QMAP - A JKQ tool for Quantum Circuit Mapping
Project description
QMAP - A JKQ tool for Quantum Circuit Mapping written in C++
A JKQ tool for quantum circuit mapping by the Institute for Integrated Circuits at the Johannes Kepler University Linz based on methods proposed in [1], [2].
[1] A. Zulehner, A. Paler, and R. Wille. "An Efficient Methodology for Mapping Quantum Circuits to the IBM QX Architectures". IEEE Transactions on Computer Aided Design of Integrated Circuits and Systems (TCAD), 2018.
[2] R. Wille, L. Burgholzer, and A. Zulehner. "Mapping Quantum Circuits to IBM QX Architectures Using the Minimal Number of SWAP and H Operations". In Design Automation Conference (DAC), 2019.
The tool can be used for mapping quantum circuits in any of the following formats:
QuantumCircuit
object from IBM's Qiskit (only through the JKQ QMAP Python bindings)OpenQASM
(e.g. used by IBM's Qiskit),Real
(e.g. from RevLib),TFC
(e.g. from Reversible Logic Synthesis Benchmarks Page)QC
(e.g. from Feynman)
to any given architecture, e.g., the IBM Q London architecture, which is specified by the coupling map
5
0 1
1 0
1 2
2 1
1 3
3 1
3 4
4 3
with the following available methods:
- Heuristic Mapper: Heuristic solution based on A* search. For details see [1].
- Exact Mapper: Exact solution utilizing the SMT Solver Z3. For details see [2].
Note that, at the moment, circuits to be mapped are assumed to be already decomposed into elementary gates supported by the targeted device. More specifically, circuits must not contain gates acting on more than two qubits.
For more information, please visit iic.jku.at/eda/research/ibm_qx_mapping/.
If you have any questions, feel free to contact us via iic-quantum@jku.at or by creating an issue on GitHub.
Usage
JKQ QMAP is mainly developed as a C++ library with a commandline interface. However, using it in Python is as easy as
pip install jkq.qmap
and then in Python
from jkq import qmap
qmap.compile(...)
where the compile
function is defined as follows:
"""
Interface to the JKQ QMAP tool for mapping quantum circuits
Params:
circ – Path to first circuit file, path to Qiskit QuantumCircuit pickle, or Qiskit QuantumCircuit object
arch – Path to architecture file or one of the available architectures (Arch)
calibration – Path to file containing calibration information
method – Mapping technique to use (*heuristic* | exact)
initial_layout – Strategy to use for determining initial layout (only relevant for heuristic mapper)
layering – Circuit layering strategy to use (*individual_gates* | disjoint_qubits | odd_qubits | qubit_triangle)
save_mapped_circuit – Include .qasm string of the mapped circuit in result
csv – Create CSV string for result
statistics – Print statistics
verbose – Print more detailed information during the mapping process
Returns:
JSON object containing results
"""
def compile(circ, arch: Union[str, Arch],
calibration = "",
method: Method = Method.heuristic,
initial_layout: InitialLayoutStrategy = InitialLayoutStrategy.dynamic,
layering: LayeringStrategy = LayeringStrategy.individual_gates,
save_mapped_circuit: bool = False,
csv: bool = False,
statistics: bool = False,
verbose: bool = False
) -> object
Note that in order for the bindings to work the SMT Solver Z3 >= 4.8.3 has to be installed on the system and the dynamic linker has to be able to find the library. This can be accomplished in a multitude of ways:
- Under Ubuntu 20.04 and newer:
sudo apt-get install z3
- Under macOS:
brew install z3
- Alternatively:
pip install z3-solver
and then append the corresponding path to the library path (LD_LIBRARY_PATH
under Linux,DYLD_LIBRARY_PATH
under macOS), e.g. viaexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(python -c "import z3; print(z3.__path__[0]+'/lib')")
- Download pre-built binaries from https://github.com/Z3Prover/z3/releases and copy the files to the respective system directories
- Build Z3 from source and install it to the system
Command-line Executable
JKQ QMAP also provides two standalone executables with command-line interface called qmap_heuristic
and qmap_exact
.
They provide the same options as the Python module as flags (e.g., --ps
for printing statistics). Per default, this produces JSON formatted output.
$ ./qmap_heuristic --in grover_2.qasm --out grover_2m.qasm --arch ibmq_london.arch --ps
{
"circuit": {
"name": "grover_2",
"qubits": 3,
"gates": 30,
},
"mapped_circuit": {
"name": "grover_2m",
"qubits": 5,
"gates": 33,
},
"statistics": {
"mapping_time": 0.001638,
"additional_gates": 3,
"method": "heuristic",
"arch": "ibmq_london"
}
}
The heuristic mapping tool qmap_heuristic
also offers the --initiallayout
option, which allows to choose one of the following strategies for choosing an initial layout:
identity
: map logical qubit q_i to physical qubit Q_i,static
: determine fixed initial layout statically at the start of mapping,dynamic
(default): determine initial layout on demand during the mapping.
Both, the exact and the heuristic mapping tool also offer the --layering
option, which allows to choose one of the following strategies for partitioning the circuit:
individual
(default): consider each gate separately,disjoint
: consider gates acting on disjoint qubits as a layer,odd
: group pairs of gates. (Note that this strategy was only tested for IBM QX4 with the exact mapping tool and may not work on different architectures)triangle
: add gates to a layer, as long as no more than three qubits are involved. (Note that this strategy only works if the architecture's coupling map contains a triangle, e.g. IBM QX4, and was only tested using the exact mapping tool)
System Requirements
Building (and running) is continuously tested under Linux, MacOS, and Windows using the latest available system versions for GitHub Actions. However, the implementation should be compatible with any current C++ compiler supporting C++14 and a minimum CMake version of 3.10.
boost/program_options >= 1.50
is required for building the the commandline applications of the mapping tool.
In order to build the exact mapping tool, the SMT Solver Z3 >= 4.8.3 has to be installed and on the path.
Library Organisation
Internally the JKQ QMAP library works in the following way
- Import input file into a
qc::QuantumComputation
objectqc::QuantumComputation qc{}; std::string circ = "<PATH_TO_CIRCUIT_FILE>"; qc.import(circ);
- Import architecture file into a
Architecture
objectArchitecture arch{}; std::string cm = "<PATH_TO_ARCH_FILE>"; arch.loadCouplingMap(cm);
- (Optional) Import calibration file into
arch
objectstd::string cal = "<PATH_TO_CAL_FILE>"; arch.loadCalibrationData(cal);
- Depending on
Method
, instantiate aHeuristicMapper
orExactMapper
object with the circuit and the architectureHeuristicMapper mapper(qc, arch);
orExactMapper mapper(qc, arch);
- Set configuration options, e.g.,
MappingSettings ms{}; ms.layeringStrategy = LayeringStrategy::DisjointQubits;
- Perform the actual mapping
mapper.map(ms);
- Dump the mapped circuit
mapper.dumpResult("<PATH_TO_OUTPUT_FILE>");
- Print the results (include statistics by setting
printStatistics=true
)mapper.printResult(std::cout, printStatistics);
Configure, Build, and Install
In order to build the library execute the following in the project's main directory
-
Configure CMake
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
Windows users using Visual Studio and the MSVC compiler may try
cmake -S . -B build -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release
Older CMake versions not supporting the above syntax (< 3.13) may be used with
mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release
-
Build the respective target.
cmake --build ./build --config Release --target <target>
The following CMake targets are available
qmap_heuristic
: The heuristic mapper commandline executable (only available if Boost is found)qmap_exact
: The exact mapper commandline executable (only available if Boost and Z3 is found)qmap_heuristic_lib
: The standalone heuristic mapper libraryqmap_exact_lib
: The standalone exact mapper library (only available if Z3 is found)qmap_heuristic_test
: Unit tests for heuristic maper using GoogleTestqmap_exact_test
: Unit tests for exact maper using GoogleTest (only available if Z3 is found)
-
Optional: The QMAP library and tool may be installed on the system by executing
cmake --build ./build --config Release --target install
It can then also be included in other projects using the following CMake snippet
find_package(qmap) target_link_libraries(${TARGET_NAME} PRIVATE JKQ::qmap)
Reference
If you use our tool for your research, we will be thankful if you refer to it by citing one or both of the following publications.
If you used the heuristic mapping, please cite
@article{zulehner2019efficient,
title={An efficient methodology for mapping quantum circuits to the {IBM} {QX} architectures},
author={Zulehner, Alwin and Paler, Alexandru and Wille, Robert},
journal={{IEEE} Transactions on Computer-Aided Design of Integrated Circuits and Systems},
volume={38},
number={7},
pages={1226--1236},
year={2019}
}
If you used the exact mapping, please cite
@inproceedings{wille2019mapping,
title={Mapping Quantum Circuits to {IBM QX} Architectures Using the Minimal Number of {SWAP} and {H} Operations},
author={Wille, Robert and Burgholzer, Lukas and Zulehner, Alwin},
booktitle={Design Automation Conference},
year={2019}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file jkq.qmap-1.2.0.tar.gz
.
File metadata
- Download URL: jkq.qmap-1.2.0.tar.gz
- Upload date:
- Size: 7.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 508563e9b7ae1f9e6ecb485d8057903e86c3c68e3b7a866a6fd9f5c798e88e8d |
|
MD5 | df2ee42286e9e39b20e6b9000eab8fc9 |
|
BLAKE2b-256 | 07a6519b8aefee06d01652c09a6f79233650eb67660b14c6346d02c185127ac7 |
File details
Details for the file jkq.qmap-1.2.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 11.2 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e0f09580312cc55e1c0bde36241df5f4ec7bbd4516141915dcf4cd911e6e443 |
|
MD5 | 3be13618f557cbe49fededab1ec9bd3d |
|
BLAKE2b-256 | 4f21bdaa0bebc8a74a05c6eede292a2594af8f45e9a43dd4bd53698993784d96 |
File details
Details for the file jkq.qmap-1.2.0-cp39-cp39-manylinux2014_x86_64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp39-cp39-manylinux2014_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138b693a4204f78019df055e98abc364dd8af768de22faea1672c62dfdc1c77d |
|
MD5 | 97a8669110ea8eaf885949976333e0a3 |
|
BLAKE2b-256 | a770b24d5fc74beebb0bfb2a34952b0d4d08d7750b9ccd224981760ef452c1d2 |
File details
Details for the file jkq.qmap-1.2.0-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 424.3 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbcaee27ef9b7e9d87220032dc9100c6e16b8e415ac1b8651f08fb46fa248622 |
|
MD5 | bf7c658a3b11adfb1a8257b6182c9bac |
|
BLAKE2b-256 | 752c73e97b55103c324287c922ef2fcc71d86f48b2fc4d8871d31945499c2cfc |
File details
Details for the file jkq.qmap-1.2.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 11.2 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e8a8d9f0d5ddf2adf6add821500a7a161ddf0ecc5ab551cb7db704cd1194be |
|
MD5 | f15684d9e5b43aa7e6068a98ddb8523f |
|
BLAKE2b-256 | c6c56cc1468446656a2fcf8550e3a0ce2356a1007e6b862805d0177ee695cb3c |
File details
Details for the file jkq.qmap-1.2.0-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 214dbd638741c90c6156a8a8d65ada2d6db9e1fd390845e97fa8d5f9a16ea741 |
|
MD5 | 35efb0fd9aa1f7304ab1816a3ad1ae8d |
|
BLAKE2b-256 | 2b9da920a193abb2202ab43a88b360daf1d2431fbb4b6fdeeda33d80bed028d7 |
File details
Details for the file jkq.qmap-1.2.0-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 424.2 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f637746c25d42670f9c6a3e31a7732d729b1262dc661aaff21c5f4e17bec8f5 |
|
MD5 | efb2292109e04c0aaa77e443cb77f0c6 |
|
BLAKE2b-256 | 87ce726f386843ebf40dc7ef0d9929049898812fd202d8d2eed5cc1397979449 |
File details
Details for the file jkq.qmap-1.2.0-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 11.3 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d298c57e0249b7022a11e06942065f6384e74f11919faec47dd855947c16fdd |
|
MD5 | dd45bc8fc66c28b322e31cccb4ae7d1d |
|
BLAKE2b-256 | 9f4834e50623823a564cde6fc9914aa2f1526e2e97f59fff8c84a96196d4d663 |
File details
Details for the file jkq.qmap-1.2.0-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ce21bdf3b06afe416569bfcf1f21fcbeb7a36332f7441f0187dbda04ea5cf74 |
|
MD5 | 1a6e344f7a91ef233103e3ec7942aee1 |
|
BLAKE2b-256 | afc17aacd9784f91eb61734fa8b80bd4d78d9e49e4d5ab92bcbdcfab88ef1857 |
File details
Details for the file jkq.qmap-1.2.0-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 421.0 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c3a23cd5893e5ad35b2ad09e8c587559b171925de83638c6fd688aa6992fa5c |
|
MD5 | f1d354992360b6e099d52b4d005d89c1 |
|
BLAKE2b-256 | 9ba3bc5bc8553a1672562eace913e40addbadbae17adec3a138122fc05b7b00e |
File details
Details for the file jkq.qmap-1.2.0-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 11.3 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66e1f738fcfc07d8d7c2c9ee86ee0b7a4b4033f14d43f3c4850445b5ea989ec1 |
|
MD5 | 929b103dab17dc9b38e9155121001c4c |
|
BLAKE2b-256 | 1e7d48244582f177039faee791bfa96f2c0e1385dc230acab122ff491d50dafd |
File details
Details for the file jkq.qmap-1.2.0-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0017c65423752d51e25b9d2c5ede8d98442831014aab3200c27b8c37c4e094f8 |
|
MD5 | 81dd763f57478fcf65023a6206ee29b2 |
|
BLAKE2b-256 | c4c69209f4ff6991b01835d12f620956a4c3810581cb5a9430cb5e631e8813be |
File details
Details for the file jkq.qmap-1.2.0-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jkq.qmap-1.2.0-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 420.9 kB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79120e9dc724bf24071aaf6f8935b4be4bda207ccdf01aaa1a6c163eeca7db0b |
|
MD5 | 2f0114b1208bd32ea3e05f29803592c8 |
|
BLAKE2b-256 | 4d7468d0cbd62cddec7ae47fd2331201557dafa7ab7d092a35a34ec2b4bab178 |