Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Lightning API documentation #131

Merged
merged 23 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9375927
V17.0 increment version (#127)
albi3ro Aug 11, 2021
25c6321
Update documentation for Python bindings
mlxd Aug 12, 2021
73da0a1
Add docstrings to gate matrix definitions
mlxd Aug 12, 2021
914683a
Add docstrings for all publically facing statevector methods
mlxd Aug 13, 2021
ef86d85
Fix incorrectly labelled gatecalls
mlxd Aug 13, 2021
f00efe0
Update doxygen comments to ignore anon namespaces
mlxd Aug 13, 2021
4bf2050
Move exc into namespace
mlxd Aug 13, 2021
989c005
Update missing gates
mlxd Aug 13, 2021
54e249b
Enable build of C++ API with docs
mlxd Aug 13, 2021
9facb8a
Add C++ API to docs
mlxd Aug 13, 2021
a45c9bd
Merge branch 'master' into 7077-update-docstrings
mlxd Aug 13, 2021
5a19738
Add C4 arch diagrams for lightning
mlxd Aug 13, 2021
1e9d898
Add sample C4 architecture for lightning using current design
mlxd Aug 13, 2021
619d99a
Merge branch '7077-update-docstrings' of https://github.com/PennyLane…
mlxd Aug 13, 2021
87b7f2d
Merge branch 'master' into 7077-update-docstrings
trbromley Aug 13, 2021
ca0be68
Fix missing packages
mlxd Aug 13, 2021
2dea5d3
Merge branch '7077-update-docstrings' of https://github.com/PennyLane…
mlxd Aug 13, 2021
0c42811
Update documentation architecture
mlxd Aug 16, 2021
50f7cd9
Prevent bindings from generating API docs
mlxd Aug 16, 2021
90a767e
Merge branch 'v0.17.0-rc0' into 7077-update-docstrings
mlxd Aug 16, 2021
32651c2
Update changelog
mlxd Aug 16, 2021
c052cf3
Merge branch 'master' into 7077-update-docstrings
mlxd Aug 17, 2021
42a9ab7
Merge branch 'master' into 7077-update-docstrings
trbromley Aug 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

### Documentation

* Added preliminary architecture diagram for package.
[(#131)](https://github.com/PennyLaneAI/pennylane-lightning/pull/131)

* C++ API built as part of docs generation.
[(#131)](https://github.com/PennyLaneAI/pennylane-lightning/pull/131)

### Bug fixes

* Column-major data in numpy is now correctly converted to row-major upon pass to the C++ layer.
Expand Down Expand Up @@ -104,7 +110,7 @@ Thomas Bromley, Lee James O'Riordan

This release contains contributions from (in alphabetical order):

Ali Asadi, Thomas Bromley, Lee James O'Riordan
Ali Asadi, Christina Lee, Thomas Bromley, Lee James O'Riordan

---

Expand Down
1,629 changes: 1,629 additions & 0 deletions doc/_static/arch/system_containers_components.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,004 changes: 1,004 additions & 0 deletions doc/_static/arch/system_context.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions doc/arch/arch_overview.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Architecture overview
=====================

.. |br| raw:: html

<br />

Lightning's purpose is to provide direct C++ kernels to manipulate the statevector data as created with PennyLane. Our design extends that of the "default.qubit" device in PennyLane, allowing direct access to the complex C-backed Numpy array data. This ensures we maintain all existing compatibility with PennyLane plugins, as only the gate-application is offloaded to C++.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Lightning's purpose is to provide direct C++ kernels to manipulate the statevector data as created with PennyLane. Our design extends that of the "default.qubit" device in PennyLane, allowing direct access to the complex C-backed Numpy array data. This ensures we maintain all existing compatibility with PennyLane plugins, as only the gate-application is offloaded to C++.
Lightning Qubit's purpose is to provide direct C++ kernels to manipulate the statevector data as created with PennyLane. Our design extends that of the ``default.qubit`` device in PennyLane, allowing direct access to the complex C-backed Numpy array data. This ensures we maintain all existing compatibility with the PennyLane device API, as only the gate-application is offloaded to C++.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Though going forward will we still be following the philosophy of just offloading gate application to C++? E.g., if we override the whole execute method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is something to update as the architecture settles in. Maybe "our current design" to signify the existing implementation?


The following diagram represents the current architecture of Lightning using an adaption of the C4 container model.

|br|

.. image:: ../_static/arch/system_context.svg
:width: 600
:alt: Example of a tensor network.
:align: center

|br|


To understand the relationships between PennyLane, Lightning, and its components, we also present a component-level diagram.

|br|


.. image:: ../_static/arch/system_containers_components.svg
:width: 600
:alt: Example of a tensor network.
:align: center

|br|

The interactions provided allow us to develop and extend functionality from PennyLane to Lightning, whilst providing a clear boundary between different parts of the system.
50 changes: 50 additions & 0 deletions doc/arch/system_containers_components.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml
' uncomment the following line and comment the first to use locally
' !include C4_Context.puml

LAYOUT_TOP_DOWN()

title Component-level diagram for PennyLane Lightning

Person(developer, "Quantum software developer")
System(python, "Python", "Python 3.7+")

System(pennylane, "PennyLane", "PennyLane quantum simulation library")

System_Boundary(pennylane, "PennyLane") {
Container(other, "Other", "Catch-all for rest of PennyLane library and tooling")
Container(default_qubit, "default.qubit", "PennyLane Python-only simulation device")

Container_Boundary(lightning, "lightning-qubit") {
Component(lightning_qubit, "lightning_qubit", "C++/Python", "Python module front-end for C++ operations")

Component(statevector, "StateVector", "C++", "C++ class for directly manipulating statevector data")
Component(utils, "Utils", "C++", "Helper utilities for C++ operations")
Component(gates, "Gates", "C++", "const/constexpr numerical representations of gates")
Component(bindings, "Bindings", "C++, Pybind11", "Binds C++ classes, methods and functions to Python layer.")
}
}

Rel(lightning_qubit, bindings, "Uses", "Bound methods wrapped to interface with PennyLane library")
Rel_Neighbor(bindings, statevector, "Uses", "Wraps statevector to manipulate data using C++")
Rel(statevector, utils, "Uses")

System_Ext(tests, "Tests", "C++, CMake, Catch2")
Rel(tests, statevector, "Uses")
Rel(tests, gates, "Uses")

Rel_Neighbor(other, default_qubit, "Uses", "Quantum circuit \n backends")
Lay_L(other, default_qubit)

Lay_D(python, other)

Rel_Neighbor(developer, python, "Uses", "Win/MacOS/Lnx")

Rel(python, other, "Uses")

Rel(default_qubit, lightning_qubit, "Ops and data pointer", "Provides default \n Python plugin methods")

@enduml
33 changes: 33 additions & 0 deletions doc/arch/system_context.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
' uncomment the following line and comment the first to use locally
' !include C4_Context.puml

LAYOUT_TOP_DOWN()

title System-level component diagram for PennyLane using Lightning Qubit device

Person(developer, "Quantum software developer")
System(python, "Python", "Python 3.7+")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I know that these are autogenerated from an easily-searcheable script, maybe putting Python 3.7 isn't so bad here!

System(pennylane, "PennyLane", "PennyLane quantum simulation library")

System_Boundary(pennylane, "PennyLane") {
Container(other, "Other", "Catch-all for rest of PennyLane library and tooling")
Container(default_qubit, "default.qubit", "PennyLane Python-only simulation device")

Container(lightning, "lightning.qubit", "PennyLane Lightning C++ simulation library ⚡")
}

System_Ext(tests, "Tests", "C++, CMake, Catch2")

Rel_Neighbor(developer, python, "Uses", "Win/MacOS/Lnx")

Rel_D(python, other, "Uses")

Rel_Neighbor(default_qubit, other, "Catch-all for rest of PennyLane library and tools")
Rel_D(default_qubit, lightning, "Ops and data pointer", "Provides default \n Python plugin methods")
Rel(tests, lightning, "Uses", "Tests for C++ gate kernels")


@enduml
36 changes: 35 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os, re
import sys, os, re, inspect
from unittest.mock import MagicMock

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -45,6 +45,8 @@ def __getattr__(cls, name):
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"breathe",
"exhale",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.todo",
Expand All @@ -65,6 +67,38 @@ def __getattr__(cls, name):
automodapi_toctreedirnm = "code/api"
automodsumm_inherited_members = True

# Breathe extension
breathe_projects = {"Lightning-Qubit": "./doxyoutput/xml"}
breathe_default_project = "Lightning-Qubit"

# Exhale extension
# Setup the exhale extension
exhale_args = {
# These arguments are required
"containmentFolder": "./api",
"rootFileName": "library_root.rst",
"rootFileTitle": "Overview",
"doxygenStripFromPath": "..",
# Suggested optional arguments
"createTreeView": True,
# TIP: if using the sphinx-bootstrap-theme, you need
# "treeViewIsBootstrap": True,
"exhaleExecutesDoxygen": True,
"exhaleDoxygenStdin": (
"INPUT = "
"../pennylane_lightning/src/Bindings.cpp "
"../pennylane_lightning/src/Gates.hpp "
"../pennylane_lightning/src/StateVector.hpp "
"../pennylane_lightning/src/Util.hpp"
"EXCLUDE_SYMBOLS = std::* "
),
"afterTitleDescription": inspect.cleandoc(
"""
The Pennylane Lightning C++ API is intended to be called from Python through Pybind11. Direct use of the C++ API is currently unsupported and is provided for reference only.
"""
),
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates', 'xanadu_theme']

Expand Down
6 changes: 6 additions & 0 deletions doc/devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ Supported operations and observables

~pennylane.BasisState
~pennylane.CNOT
~pennylane.CRot
~pennylane.CRX
~pennylane.CRY
~pennylane.CRZ
Comment on lines +29 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long run, maybe we shouldn't even have this list of supported ops! Every op should be supported ⚡ (and saves us having to maintain this)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure --- do you think this entire list can be pulled? Or should we opt for that later?

~pennylane.Hadamard
~pennylane.PauliX
~pennylane.PauliY
~pennylane.PauliZ
~pennylane.PhaseShift
~pennylane.ControlledPhaseShift
~pennylane.QubitStateVector
~pennylane.Rot
~pennylane.RX
Expand Down
2 changes: 2 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PennyLane-Lightning provides the following device:

installation
support
Architecture <arch/arch_overview>

.. toctree::
:maxdepth: 2
Expand All @@ -43,3 +44,4 @@ PennyLane-Lightning provides the following device:
:hidden:

code/__init__
C++ API <api/library_root>
3 changes: 3 additions & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
docutils==0.16
sphinx
sphinx-automodapi
breathe
exhale
pybind11
Loading