https://github.com/cqcl/pytket-dqc
https://github.com/cqcl/pytket-dqc
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cqcl/pytket-dqc
- Owner: CQCL
- License: apache-2.0
- Created: 2021-12-20T18:54:45.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-07-28T09:01:04.000Z (11 months ago)
- Last Synced: 2025-07-28T11:17:39.487Z (11 months ago)
- Language: Python
- Size: 2.51 MB
- Stars: 12
- Watchers: 8
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pytket-dqc
Automated entanglement-efficient distribution of quantum circuits.
## Table of Contents
- [About](#about)
- [Requirements](#requirements)
- [Installing pytket-dqc](#installing-pytket-dqc)
- [Contributing](#contributing)
## About
This package takes a quantum circuit and network description and produces a circuit distributed across the given network,
using entanglement-assisted local operations and classical communication to implement non-local gates in the circuit,
with the aim of reducing the amount of entanglement required for the circuit implementation.
A more in-depth presentation of the methods implemented here can be found in the
corresponding paper ["Distributing circuits over heterogeneous, modular quantum computing network architectures"](https://arxiv.org/abs/2305.14148).
Here we detail the steps required to install `pytket-dqc`. More thorough documentation of it use can be found [here](https://cqcl.github.io/pytket-dqc/)
You may also find the example Jupyter notebooks in `examples/` instructive.
## Requirements
In addition to specified Python packages that will automatically be installed when you install pytket-dqc,
the following packages are also required.
We provide installation steps for MacOS,
but they should apply just the same for Linux systems by replacing `brew` with your package manager
(e.g. `apt` for Debian/Ubuntu users).
### [CMake](https://cmake.org/)
This is required for building KaHyPar.
Please refer to [Building KaHyPar](https://github.com/kahypar/kahypar?tab=readme-ov-file#building-kahypar)
for more details.
Installation Steps
1. `brew install cmake`
### [KaHyPar (with Python interface)](https://github.com/kahypar/kahypar)
This is required for the hypergraph partitioning methods used in `pytket-dqc`.
Note that continuous integration tests are run with v1.3.2, released with [this commit](https://github.com/kahypar/kahypar/releases/tag/1.3.2) and we recommend you use that version.
We use an experimental feature from KaHyPar that let us select a different maximum weight for each block of the partition
(i.e. a different qubit capacity for each server).
The python interface for this feature was added in [this commit](https://github.com/kahypar/kahypar/commit/ff8fdf06c4e50af2faecddb9c5b6f7553e232df2).
It looks like KaHyPar >1.2.1 is the least requirement for this feature.
If KaHyPar is built from their repository (following the instructions given below), this feature is automatically available.
Boost
[KaHyPar requires Boost.Program_options](https://github.com/kahypar/kahypar#requirements).
If you do not have Boost installed then you can:
- Install it (see [here](https://www.boost.org/doc/libs/1_78_0/tools/build/doc/html/index.html#bbv2.installation))
- Add the flag `-DKAHYPAR_USE_MINIMAL_BOOST=ON` to the command given in Step 4 below.
Installation Steps
1. Navigate to the directory where you wish to download and build KaHyPar.
For instance, `cd ~` will do so in your home directory, which is probably fine for most people.
The location of this directory is up to you and it will not affect installation.
2. Clone the repository (using HTTPS, since the SSH link to the repository seems to be broken):
```
git clone --depth=1 --recursive https://github.com/kahypar/kahypar.git
```
3. Create and move to the build directory:
```
mkdir kahypar/build && cd kahypar/build
```
4. Build KaHyPar
```
cmake ../ -DCMAKE_BUILD_TYPE=RELEASE -DKAHYPAR_PYTHON_INTERFACE=1
```
5. Build KaHyPar's Python interface:
```
cd python
make
```
6. Copy the dynamic library to the appropriate path so that Python can import the kahypar module and use its contents:
```
cp kahypar*.so
```
You must replace `` with the path to the directory `site-packages` listed by the command `python -m site`. For instance:
```
cp kahypar*.so /home/myuser/anaconda3/lib/python3.9/site-packages
```
Test KaHyPar
You should now be able to use KaHyPar in Python.
To test this, in your terminal open a Python 3 shell with command `python3` and then do `import kahypar`.
If this fails then Python cannot access the dynamic library (the `.so` file).
If you get such an error it is likely something went wrong in step 6 from the instructions above,
i.e. the `.so` file was not copied to the right directory, or the wrong `.so` file was copied.
Troubleshooting
I got an error when building KaHyPar! (Step 4)
If an error occurs it might be that you do not have the Boost library installed in your computer.
You may choose to install it yourself
(your package manager is likely able to do it for you, e.g. `brew install boost`)
or ask CMake to fetch the minimal requirements and install them using the following command instead of the one given in Step 4
```
cmake ../ -DCMAKE_BUILD_TYPE=RELEASE -DKAHYPAR_PYTHON_INTERFACE=1 -DKAHYPAR_USE_MINIMAL_BOOST=ON
```
Note that the `-DKAHYPAR_USE_MINIMAL_BOOST=ON` flag is used.
It may not be possible to get it to play nicely with an already present installation of boost.
See for relevant discussion.
My terminal is telling me `kahypar.so` doesn't exist when I try to copy it! (Step 6)
Try to find a file in the directory `kahypar/build/python` with the extension `.so` and copy that instead.
You do not need to rename the file.
### [Graphviz](https://graphviz.org/download/)
This package is used for graph visualisation.
Installation Steps
1. `brew install graphviz`
1. `pip install --global-option=build_ext --global-option="-I/opt/homebrew/include/" --global-option="-L/opt/homebrew/lib/graphviz" pygraphviz`
## Installing pytket-dqc
1. Ensure that CMake, KaHyPar, and Graphviz are installed. See above for guidance on this.
1. In your terminal, navigate to the directory you wish to download `pytket-dqc`'s source files to.
(If unsure, then `cd ~` is probably fine.)
1. Clone this repository with `git clone git@github.com:CQCL/pytket-dqc.git`.
1. Navigate to the cloned repository `cd pytket-dqc`.
1. Run `pip install .`
#### Testing pytket-dqc
You may wish to test your installation has succeeded.
You can do this by running `pip install pytest` to install `pytest`.
Then running `pytest tests -m "not high_compute` from the directory that these source files were `git clone`d to.
(The additional flag skips tests that will take a long time.)
Assuming that all the tests pass then you have succeeded in installing `pytket-dqc`!
## Contributing
If you wish to contribute to the development of `pytket-dqc` (which would be extremely welcome!),
you can do so by creating a branch and submitting a PR.
For code consistency, we'd ask you to include type annotations on your code,
and ensure that your code conforms to standards set by `flake8` (with a line length of 79 characters).
This will be checked automatically on any PRs submitted to this project, by `mypy` and `flake8` respectively.