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

Fix broken docstrings in bindings and minor API docs updates #920

Merged
merged 29 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6da46b0
fix RenameQubitsPass docs
CalMacCQ Jul 7, 2023
e1244c2
try to fix ZZPhaseToRz, RoutingPass and CustomRoutingPass
CalMacCQ Jul 7, 2023
cc955c5
Merge branch 'develop' into fix/round_angles
CalMacCQ Jul 7, 2023
820e72f
Merge branch 'develop' into fix/round_angles
CalMacCQ Jul 7, 2023
00ac411
Merge branch 'fix/round_angles' of github.com:CQCL/tket into fix/roun…
CalMacCQ Jul 7, 2023
d3f69a0
try to fix RoundAngles
CalMacCQ Jul 7, 2023
0976cdd
finally fix ZZPhaseToRz
CalMacCQ Jul 7, 2023
fe50e09
fix spacing
CalMacCQ Jul 7, 2023
7a00e59
Merge branch 'develop' into fix/round_angles
CalMacCQ Jul 12, 2023
c142330
fix RingArch and to_dict
CalMacCQ Jul 12, 2023
e6b9213
fix QubitPauliString
CalMacCQ Jul 12, 2023
e5fbf5f
fix spacing
CalMacCQ Jul 12, 2023
233c184
fix spacing in ZZPhaseToRz
CalMacCQ Jul 12, 2023
20eaf62
use sphinx-autodoc-typehints
CalMacCQ Jul 12, 2023
e9b478a
Merge branch 'fix/round_angles' of github.com:CQCL/tket into fix/roun…
CalMacCQ Jul 12, 2023
a5c3df4
fix broken getting_started links
CalMacCQ Jul 12, 2023
98aed47
fix mistake in ZZPhaseToRz docstring
CalMacCQ Jul 19, 2023
3d676e6
use sphinx_autodoc_annotation again
CalMacCQ Jul 21, 2023
6ff580c
update ZZPhaseToRz docstring
CalMacCQ Jul 21, 2023
9458e3c
fix conf.py
CalMacCQ Jul 21, 2023
38e4cbf
fix duplicate link warning
CalMacCQ Jul 21, 2023
02ea72c
Merge branch 'develop' into fix/round_angles
CalMacCQ Jul 21, 2023
35c5741
update pytket.qasm docs
CalMacCQ Jul 21, 2023
d227dc5
minor wording
CalMacCQ Jul 21, 2023
e1415dd
remove extra lines from pytket.qasm docs
CalMacCQ Jul 21, 2023
b354c4c
more pytket.qasm edits
CalMacCQ Jul 21, 2023
d7244b9
use half-turns instead of radians
CalMacCQ Jul 21, 2023
6d1fa51
fix Bit.to_list() docstring
CalMacCQ Jul 21, 2023
c258c77
fix minor formatting issues in pytket.placement and pytket.zx
CalMacCQ Jul 21, 2023
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
14 changes: 8 additions & 6 deletions pytket/binders/architecture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ PYBIND11_MODULE(architecture, m) {
.def(
"to_dict", [](const Architecture &arch) { return json(arch); },
"Return a JSON serializable dict representation of "
"the Architecture.\n"
":return: dict containing nodes and links.")
"the Architecture."
"\n\n:return: dict containing nodes and links.")
.def_static(
"from_dict", [](const json &j) { return j.get<Architecture>(); },
"Construct Architecture instance from JSON serializable "
Expand Down Expand Up @@ -160,8 +160,8 @@ PYBIND11_MODULE(architecture, m) {
.def(
py::init<const unsigned, const std::string>(),
"The constructor for a RingArchitecture with some undirected "
"connectivity between qubits.\n\n:param number of qubits\n:param "
"label: Name for Node in RingArch Architecture",
"connectivity between qubits.\n\n:param number of qubits:"
"\n:param label: Name for Node in RingArch Architecture",
py::arg("nodes"), py::arg("label") = "ringNode")
.def(
"__deepcopy__",
Expand All @@ -177,7 +177,8 @@ PYBIND11_MODULE(architecture, m) {
.def(
py::init<unsigned, const std::string>(),
"Construct a fully-connected architecture."
"\n\n:param n: number of qubits\n:param label: Name for Node in "
"\n\n:param n: number of qubits"
"\n:param label: Name for Node in "
"FullyConnected Architecture",
py::arg("n"), py::arg("label") = "fcNode")
.def(
Expand All @@ -196,7 +197,8 @@ PYBIND11_MODULE(architecture, m) {
.def(
"to_dict", [](const FullyConnected &arch) { return json(arch); },
"JSON-serializable dict representation of the architecture."
"\n\n:return: dict containing nodes")
"\n\n"
":return: dict containing nodes")
.def_static(
"from_dict", [](const json &j) { return j.get<FullyConnected>(); },
"Construct FullyConnected instance from dict representation.");
Expand Down
4 changes: 2 additions & 2 deletions pytket/binders/circuit/unitid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ void init_unitid(py::module &m) {
.def(
"to_list", [](const Bit &b) { return json(b); },
"Return a JSON serializable list representation of "
"the Bit.\n"
":return: list containing register name and index")
"the Bit."
"\n\n:return: list containing register name and index")
.def_static(
"from_list", [](const json &j) { return j.get<Bit>(); },
"Construct Bit instance from JSON serializable "
Expand Down
31 changes: 20 additions & 11 deletions pytket/binders/passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ PYBIND11_MODULE(passes, m) {
"Removes gate-inverse pairs, merges rotations, removes identity "
"rotations, and removes redundant gates before measurement. Does not "
"add any new gate types.\n\n"
"When merging rotations with the same op group name, the merged"
"When merging rotations with the same op group name, the merged "
"operation keeps the same name.");
m.def(
"SynthesiseHQS", &SynthesiseHQS,
Expand Down Expand Up @@ -611,8 +611,9 @@ PYBIND11_MODULE(passes, m) {
m.def(
"CustomRoutingPass", &gen_routing_pass,
"Construct a pass to route to the connectivity graph of an "
":py:class:`Architecture`. Edge direction is ignored."
"\n:return: a pass that routes to the given device architecture",
":py:class:`Architecture`. Edge direction is ignored. "
"\n\n"
":return: a pass that routes to the given device architecture ",
py::arg("arc"), py::arg("config"));

m.def(
Expand All @@ -621,7 +622,8 @@ PYBIND11_MODULE(passes, m) {
":py:class:`Architecture`. Edge direction is ignored. "
"Uses :py:class:`LexiLabellingMethod` and "
":py:class:`LexiRouteRoutingMethod`."
"\n:return: a pass that routes to the given device architecture",
"\n\n"
":return: a pass that routes to the given device architecture",
py::arg("arc"));

m.def(
Expand All @@ -647,8 +649,10 @@ PYBIND11_MODULE(passes, m) {
py::arg("label") = q_default_reg());

m.def(
"RenameQubitsPass", &gen_rename_qubits_pass, "Rename some or all qubits.",
"\n\n:param qubit_map: map from old to new qubit names",
"RenameQubitsPass", &gen_rename_qubits_pass,
"Rename some or all qubits. "
"\n\n"
":param qubit_map: map from old to new qubit names ",
py::arg("qubit_map"));

m.def(
Expand Down Expand Up @@ -855,8 +859,12 @@ PYBIND11_MODULE(passes, m) {

m.def(
"ZZPhaseToRz", &ZZPhaseToRz,
"Converts ZZPhase gates with angle pi or -pi to two Rz gates with"
"angle pi.\n:return: a pass to convert ZZPhase gates to Rz");
"Converts all ZZPhase gates in a circuit with angle 1 or -1 (half-turns) "
"into two Rz gates each with a parameter value of 1 (half-turns). "
"ZZPhase gates with parameter values other than 1 or -1 "
"(half-turns) are left "
"unchanged.\n\n"
":return: a pass to convert ZZPhase gates to Rz.");

m.def(
"CnXPairwiseDecomposition", &CnXPairwiseDecomposition,
Expand All @@ -866,9 +874,9 @@ PYBIND11_MODULE(passes, m) {

m.def(
"RoundAngles", &RoundAngles,
"Round angles to the nearest :math:`\\pi / 2^n`."
"\n\n:param n: precision parameter, must be >= 0 and < 32",
"\n\n:param only_zeros: if True, only round angles less than "
"Round angles to the nearest :math:`\\pi / 2^n`. "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't actually see what the problem was with this one.

"\n\n:param n: precision parameter, must be >= 0 and < 32 "
"\n:param only_zeros: if True, only round angles less than "
":math:`\\pi / 2^{n+1}` to zero, leave other angles alone (default "
"False)",
py::arg("n"), py::arg("only_zeros") = false);
Expand All @@ -889,6 +897,7 @@ PYBIND11_MODULE(passes, m) {
"\n\n"
":param transform: function taking a :py:class:`Circuit` as an argument "
"and returning a new transformed circuit"
"\n"
":param label: optional label for the pass"
"\n:return: a pass to perform the transformation",
py::arg("transform"), py::arg("label") = "");
Expand Down
6 changes: 3 additions & 3 deletions pytket/binders/pauli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PYBIND11_MODULE(pauli, m) {

py::class_<QubitPauliString>(
m, "QubitPauliString",
"A string of Pauli letters from the alphabet {I, X, Y, Z},"
"A string of Pauli letters from the alphabet {I, X, Y, Z}, "
"implemented as a sparse list, indexed by qubit.")
.def(py::init<>(), "Constructs an empty QubitPauliString.")
.def(
Expand Down Expand Up @@ -70,8 +70,8 @@ PYBIND11_MODULE(pauli, m) {
json j = qps;
return j;
},
"A JSON-serializable representation of the QubitPauliString. "
"\n:return: a list of :py:class:`Qubit`-to-:py:class:`Pauli` "
"A JSON-serializable representation of the QubitPauliString.\n\n"
":return: a list of :py:class:`Qubit`-to-:py:class:`Pauli` "
"entries, "
"represented as dicts.")
.def_static(
Expand Down
4 changes: 2 additions & 2 deletions pytket/binders/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ PYBIND11_MODULE(placement, m) {
.def(
"to_dict", [](const Placement::Ptr &placement) { return json(placement); },
"Return a JSON serializable dict representation of "
"the Placement.\n"
":return: dict representing the Placement.")
"the Placement."
"\n\n:return: dict representing the Placement.")
.def_static(
"from_dict", [](const json &j) { return j.get<Placement::Ptr>(); },
"Construct Placement instance from JSON serializable "
Expand Down
2 changes: 1 addition & 1 deletion pytket/binders/zx/diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void ZXDiagramPybind::init_zxdiagram(py::module& m) {
":param type: :py:class:`ZXType` to filter by, from "
"{:py:meth:`ZXType.Input`, :py:meth:`ZXType.Output`, "
":py:meth:`ZXType.Open`, None}. Defaults to None."
":param qtype: :py:class:`QuantumType` to filter by, from "
"\n\n:param qtype: :py:class:`QuantumType` to filter by, from "
"{:py:meth:`QuantumType.Quantum`, :py:meth:`QuantumType.Classical`, "
"None}. Defaults to None.",
py::arg("type") = std::nullopt, py::arg("qtype") = std::nullopt)
Expand Down
2 changes: 1 addition & 1 deletion pytket/docs/display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Example usage:
from pytket.circuit.display import get_circuit_renderer

circuit_renderer = get_circuit_renderer() # Instantiate a circuit renderer
circuit_renderer.set_render_options(zx_style=False) # Configure render options
circuit_renderer.set_render_options(zx_style=True) # Configure render options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because the renderer no longer uses ZX by default

circuit_renderer.condense_c_bits = False # You can also set the properties on the instance directly
print("Render options:")
print(circuit_renderer.get_render_options()) # View currently set render options
Expand Down
4 changes: 2 additions & 2 deletions pytket/docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ This prints out a summary of readouts (the final values of the classical bits) a

Each pytket :py:class:`Backend` comes with its own default compilation method. This is a recommended sequence of optimisation passes to meet the requirements of the specific :py:class:`Backend`.

The following code snippet will show how to compile a circuit to run on an IBM device. This requires setting up IBM credentials (see `this page <https://cqcl.github.io/pytket-qiskit/api/index.html#access-and-credentials>`).
The following code snippet will show how to compile a circuit to run on an IBM device. This requires setting up IBM credentials (see the `credentials guide <https://cqcl.github.io/pytket-qiskit/api/index.html#access-and-credentials>`_).
Copy link
Contributor Author

@CalMacCQ CalMacCQ Jul 21, 2023

Choose a reason for hiding this comment

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

changed this to avoid the duplicate link labelled "this page". Fixes a sphinx warning


::

Expand All @@ -106,7 +106,7 @@ The following code snippet will show how to compile a circuit to run on an IBM d
compiled_circ = belem_device.get_compiled_circuit(circ)
result = backend.run_circuit(compiled_circ, n_shots=100)

Here the default compilation pass is applied by :py:meth:`IBMQBackend.get_compiled_circuit`. See `this page <https://cqcl.github.io/pytket-qiskit/api/index.html>`_ for more details.
Here the default compilation pass is applied by :py:meth:`IBMQBackend.get_compiled_circuit`. See `this page <https://cqcl.github.io/pytket-qiskit/api/index.html#default-compilation>`_ for more details.

As an alternative, We can experiment with constructing our own circuit compilation routines in pytket. Passes from the :py:mod:`pytket.passes` module can be applied individually or composed in sequence.
See the section of the user manual on `circuit compilation <https://cqcl.github.io/pytket/manual/manual_compiler.html>`_ and the corresponding `notebook example <https://github.com/CQCL/pytket/blob/main/examples/compilation_example.ipynb>`_ for more.
17 changes: 11 additions & 6 deletions pytket/docs/qasm.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
pytket.qasm
==================================
:py:class:`Circuit` objects can be converted to and from OpenQASM, although we do not support all operations.
In particular, we do not currently support:

1) Importing from libraries other than "qelib1"
2) Ability to interpret gates acting on a whole register in the OpenQASM style
However, we do support symbolic parameters of gates, both on import and export.

Any pytket :py:class:`Circuit` that is exported to this format should be valid for importing again as a :py:class:`Circuit`, making this a convenient file format
Any pytket :py:class:`Circuit` that is exported to OpenQASM format with ``pytket.qasm`` should be valid for importing again as a :py:class:`Circuit`, making this a convenient file format
to save your :py:class:`Circuit` objects.

However, we do support symbolic parameters of gates, both on import and export.
In addition to the default ``qelib1`` qasm header, the ``hqslib1`` header is also supported.
We can set the ``header`` argument in the qasm conversion functions as follows.

::

from pytket.qasm import circuit_to_qasm_str

qasm_str = circuit_to_qasm_str(circ, header="hqslib1")

.. note:: Unlke pytket backends the qasm converters do not handle `implicit qubit permutations <https://cqcl.github.io/pytket/manual/manual_circuit.html#implicit-qubit-permutations>`_ . In other words if a circuit containing an implicit qubit permutation is converted to a qasm file the implicit permutation will not be accounted for and the circuit will be missing this permutation when reimported.
.. note:: Unlike pytket backends, the qasm converters do not handle `implicit qubit permutations <https://cqcl.github.io/pytket/manual/manual_circuit.html#implicit-qubit-permutations>`_. In other words if a circuit containing an implicit qubit permutation is converted to a qasm file the implicit permutation will not be accounted for and the circuit will be missing this permutation when reimported.

.. automodule:: pytket.qasm
:members: circuit_from_qasm, circuit_from_qasm_wasm, circuit_to_qasm, circuit_from_qasm_str, circuit_to_qasm_str, circuit_from_qasm_io, circuit_to_qasm_io
Loading