Skip to main content

Search-Based Quantum Synthesis/Compilation

Project description

search_compiler

An implementation of a quantum gate synthesis algorithm based on A* and numerical optimization. It relies on NumPy and SciPy. It can export code for Qiskit and OpenQASM.

This is an implementation of the algorithm described in the paper Heuristics for Quantum Compiling with a Continuous Gate Set.

Installation

This is a python package which can be installed using pip. You will need a Python version of at least 3.6. The search compiler currently only runs on macOS, Linux, and the Windows Subsystem for Linux. You can install it from PyPi using:

pip3 install search_compiler 

You can also install from a downloaded copy of the repository:

git clone git@github.com:WolfLink/search_compiler.git
pip3 install ./search_compiler

If you make changes to your local copy, you can reinstall the package:

pip3 install --upgrade ./search_compiler

Once installed, you can import the library like any other python package:

import search_compiler as sc

Native Gateset

There is a gateset that is implemented in native code to be faster. See the wiki for installation instructions.

Getting Started: search_compiler Projects

The simplest way to use the search_compiler library is by using a Project. When you create a project, you provide a path where a directory will be created to contain the project's files.

import search_compiler as sc
myproject = sc.Project("desired/path/to/project/directory")

You can then add unitaries to compile, and set compiler properties. Unitary matrices should be provided as numpy ndarrays using dtype="complex128".

myproject.add_compilation("gate_name", gate_unitary)
myproject["compiler_option"] = value

Once your project is configured, you can start your project by calling run(). The compiler uses an automatic checkpoint system, so if it is killed while in-progress, it can be resumed by calling run() again.

myproject.run()

Once your project is finished, you can get openqasm output:

myproject.assemble("gate_name") # This will write the qasm to stdout
myproject.assemble("gate_name", write_location="path/to/output/file") # This will write the qasm to the specified path.

See the wiki for details on compiler properties and other Project features.

Compiling Without Projects

If you would like to avoid working with Projects, you can use the SearchCompiler class directly.

import search_compiler as sc
compiler = sc.SearchCompiler()
circuit, vector = compiler.compile(target_unitary)

The SearchCompiler class and the compile function can take extra arguments to further configure the compiler. The return values are, in order, the unitary that represents the implemented circuit, the sc.QuantumStep representation of the circuit structure, and the vector of parameters for the circuit structure.

To export openqasm code, use the assemble function from assembler.py.

myqasm = sc.assembler.assemble(circuit, vector, sc.assembler.ASSEMBLY_IBMOPENQASM) # to get output as a string
sc.assembler.assemble(circuit, vector, sc.assembler.ASSEMBLY_IBMOPENQASM, write_location="myqasm.txt") # to write the output to a file

See the wiki for details on compiler properties.

A Note On Endianness

We use the physics convention of using big endian when naming our qubits. Some quantum programs, including IBM's Qiskit, use little endian. This means you will need to reverse the endianness of a unitary designed for Qiskit in order to work with our code, or visa versa. We provide a function that performs endian reversal on numpy matrices:

little_endian = sc.utils.endian_reverse(big_endian) # you can use the same function to convert in the other direction as well

Find information on customizing the compiler in the wiki.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

search_compiler-1.2.1.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

search_compiler-1.2.1-py2.py3-none-any.whl (30.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file search_compiler-1.2.1.tar.gz.

File metadata

  • Download URL: search_compiler-1.2.1.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.7

File hashes

Hashes for search_compiler-1.2.1.tar.gz
Algorithm Hash digest
SHA256 bb8b96b3520a5b689d70d9e7204a5f61c82452604a48b8a923ed008b33cf87af
MD5 df30b8c21e14baed9bc9e6f9dae624d8
BLAKE2b-256 546ec55542951923eb0a3c1677dc660966d05378090c0272bf5ab70aaaa88989

See more details on using hashes here.

File details

Details for the file search_compiler-1.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: search_compiler-1.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.7

File hashes

Hashes for search_compiler-1.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e396b7744c5f1998a58ffa3f3b7d0f6ffc5d7c8938d3c65aa359b45e562d9f33
MD5 b837184e83cd5dc4135ebc5342c52b5a
BLAKE2b-256 c6882a5bd647e163a1893844b8257764aa5103f97a9d85c75e5ff27cebea0613

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page