Skip to content

Commit

Permalink
Merge pull request #958 from CQCL/release/1.18.0
Browse files Browse the repository at this point in the history
Release/1.18.0
  • Loading branch information
cqc-alec authored Aug 4, 2023
2 parents 5a80b16 + 4f75f2c commit 3caf2d2
Show file tree
Hide file tree
Showing 38 changed files with 913 additions and 106 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-without-conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ jobs:
- name: Install pybind11
run: |
cd ${TMP_DIR}
wget https://github.com/pybind/pybind11/archive/refs/tags/v2.10.4.tar.gz
tar xzvf v2.10.4.tar.gz
cd pybind11-2.10.4/
wget https://github.com/pybind/pybind11/archive/refs/tags/v2.11.1.tar.gz
tar xzvf v2.11.1.tar.gz
cd pybind11-2.11.1/
mkdir build
cd build
cmake -GNinja -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DPYBIND11_TEST=OFF ..
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
ccache -p
- name: Build tket
run: |
conan install tket --user=tket --channel=stable -s build_type=Debug -o boost/*:header_only=True -o tket/*:profile_coverage=True -o with_test=True -of build/tket
conan install tket --user=tket --channel=stable -s build_type=Debug --build=missing -o boost/*:header_only=True -o tket/*:profile_coverage=True -o with_test=True -of build/tket
conan build tket --user=tket --channel=stable -s build_type=Debug -o boost/*:header_only=True -o tket/*:profile_coverage=True -o with_test=True -o test-tket/*:with_coverage=True -of build/tket
conan export-pkg tket --user=tket --channel=stable -s build_type=Debug -o boost/*:header_only=True -o tket/*:profile_coverage=True -o with_test=True -of build/tket -tf ""
- name: Install runtime test requirements
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ For full API documentation, as well as a comprehensive user manual and a
selection of example notebooks, please follow the links from the
[pytket](https://github.com/CQCL/pytket) main page.

Note that the various pytket extensions (which allow pytket to interface with
other software packages and with quantum devices) live in the separate
[pytket-extensions](https://github.com/CQCL/pytket-extensions) repository.
In addition to the core pytket package there are pytket extension modules which allow pytket to interface with quantum devices and simulators. Some extensions also provide interoperability with other software libraries such as qiskit, cirq and pennylane.

For a list of available pytket extensions see the [extensions index page](https://cqcl.github.io/pytket-extensions/api/index.html).

These extensions are installed as separate python packages and the source code for each extension lives in its own github repository.

If you would like to build tket yourself and help to improve it, read on!

Expand Down
6 changes: 3 additions & 3 deletions build-without-conan.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ cmake --install .

```
cd ${TMP_DIR}
wget https://github.com/pybind/pybind11/archive/refs/tags/v2.10.4.tar.gz
tar xzvf v2.10.4.tar.gz
cd pybind11-2.10.4/
wget https://github.com/pybind/pybind11/archive/refs/tags/v2.11.1.tar.gz
tar xzvf v2.11.1.tar.gz
cd pybind11-2.11.1/
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DPYBIND11_TEST=OFF ..
Expand Down
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
14 changes: 14 additions & 0 deletions pytket/binders/circuit/Circuit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,20 @@ void init_circuit(py::module &m) {
"\n:return: the circuit depth with respect to operations matching an "
"element of `types`",
py::arg("types"))
.def(
"depth_2q", &Circuit::depth_2q,
"Returns the number of vertices in the longest path through the "
"sub-DAG consisting of vertices with 2 quantum wires,"
"excluding vertices representing barrier operations."
"\n\n>>> c = Circuit(3)"
"\n>>> c.CZ(0,1)"
"\n>>> c.Z(0)"
"\n>>> c.Z(1)"
"\n>>> c.ZZMax(1,2)"
"\n>>> c.CX(1,2)"
"\n>>> c.depth_2q()"
"\n3"
"\n:return: the circuit depth with respect to 2-qubit operations.")
.def(
"_to_graphviz_file", &Circuit::to_graphviz_file,
"Saves a visualisation of a circuit's DAG to a \".dot\" file",
Expand Down
22 changes: 22 additions & 0 deletions pytket/binders/circuit/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ void init_library(py::module &m) {
"Given expressions α, β and γ, return circuit equivalent to "
"TK2(α, β, γ) using up to 3 CX and single-qubit gates.\n\n"
"The decomposition minimizes the number of CX gates.");
library_m.def(
"_TK2_using_CX_and_swap", &CircPool::TK2_using_CX_and_swap,
"Given expressions α, β and γ, return circuit equivalent to "
"TK2(α, β, γ), up to a wire swap that is encoded in the implicit "
"qubit permutation of the Circuit, using up to 3 CX and single-qubit "
"gates.\n\n"
"The decomposition minimizes the number of CX gates.");
library_m.def(
"_approx_TK2_using_1xCX", &CircPool::approx_TK2_using_1xCX,
"Best approximation of TK2 using 1 CX gate and single-qubit gates, using "
Expand Down Expand Up @@ -68,6 +75,9 @@ void init_library(py::module &m) {
library_m.def(
"_CX_using_ZZMax", &CircPool::CX_using_ZZMax,
"Equivalent to CX, using only ZZMax, Rx and Rz gates");
library_m.def(
"_CX_using_ZZPhase", &CircPool::CX_using_ZZPhase,
"Equivalent to CX, using only ZZPhase, Rx and Rz gates");
library_m.def(
"_CX_using_XXPhase_0", &CircPool::CX_using_XXPhase_0,
"Equivalent to CX, using only XXPhase, Rx, Ry and Rz gates");
Expand Down Expand Up @@ -216,6 +226,14 @@ void init_library(py::module &m) {
library_m.def(
"_TK2_using_ZZPhase", &CircPool::TK2_using_ZZPhase,
"Equivalent to TK2, using 3 ZZPhase gates");
library_m.def(
"_TK2_using_ZZPhase_and_swap", &CircPool::TK2_using_ZZPhase_and_swap,
"Equivalent to TK2, up to a wire swap that is encoded in the implicit "
"qubit permutation of the Circuit, using up to 3 ZZPhase gates.");
library_m.def(
"_TK2_using_TK2_or_swap", &CircPool::TK2_using_TK2_or_swap,
"Either the exact TK2, or a wire swap encoded in the implicit qubit "
"permutation of the Circuit and single qubit gates.");
library_m.def(
"_approx_TK2_using_1xZZPhase", &CircPool::approx_TK2_using_1xZZPhase,
"Approximate equivalent to TK2, using 1 ZZPhase gate and single-qubit "
Expand All @@ -227,6 +245,10 @@ void init_library(py::module &m) {
library_m.def(
"_TK2_using_ZZMax", &CircPool::TK2_using_ZZMax,
"Equivalent to TK2, using up to 3 ZZMax gates.");
library_m.def(
"_TK2_using_ZZMax_and_swap", &CircPool::TK2_using_ZZMax_and_swap,
"Equivalent to TK2, up to a wire swap that is encoded in the implicit "
"qubit permutation of the Circuit, using up to 3 ZZMax gates.");
library_m.def(
"_XXPhase3_using_TK2", &CircPool::XXPhase3_using_TK2,
"Equivalent to XXPhase3, using three TK2 gates");
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
3 changes: 2 additions & 1 deletion pytket/binders/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ PYBIND11_MODULE(partition, m) {
.value(
"NonConflictingSets", PauliPartitionStrat::NonConflictingSets,
"Build sets of Pauli tensors in which each qubit has the "
"same Pauli or Pauli.I. Requires no additional CX gates.")
"same Pauli or Pauli.I. Requires no additional CX gates "
"for diagonalisation.")
.value(
"CommutingSets", PauliPartitionStrat::CommutingSets,
"Build sets of mutually commuting Pauli tensors. Requires "
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`. "
"\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
4 changes: 2 additions & 2 deletions pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def package(self):
cmake.install()

def requirements(self):
self.requires("tket/1.2.26@tket/stable")
self.requires("tket/1.2.31@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tkassert/0.3.3@tket/stable")
self.requires("tkwsm/0.3.4@tket/stable")
self.requires("tktokenswap/0.3.4@tket/stable")
self.requires("symengine/0.10.1")
self.requires("gmp/6.2.1")
self.requires("pybind11/2.10.4")
self.requires("pybind11/2.11.1")
self.requires("nlohmann_json/3.11.2")
self.requires("pybind11_json/0.2.13")
13 changes: 13 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Changelog
=========

1.18.0 (August 2023)
--------------------

Minor new features:

* Add circuit method ``depth_2q``.
* Add ``allow_swaps`` parameter to ``auto_rebase_pass``.

Fixes:

* Fix slow ``Circuit.get_statevector()``.


1.17.1 (July 2023)
------------------

Expand Down
4 changes: 2 additions & 2 deletions pytket/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
author = "Quantinuum"

# The short X.Y version
version = "1.17"
version = "1.18"
# The full version, including alpha/beta/rc tags
release = "1.17.1"
release = "1.18.0"


# -- General configuration ---------------------------------------------------
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
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>`_).

::

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.
7 changes: 5 additions & 2 deletions pytket/docs/opensource.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ Symengine
---------

© 2013-2017 SymEngine Development Team

Licence: https://github.com/symengine/symengine/blob/master/LICENSE
Package and documentation: https://github.com/symengine/symengine

Package and documentation: https://github.com/symengine/symengine

Eigen
-----

Licence: https://www.mozilla.org/en-US/MPL/2.0/
Package and documentation: https://bitbucket.org/eigen/eigen

Package and documentation: https://eigen.tuxfamily.org/
Loading

0 comments on commit 3caf2d2

Please sign in to comment.