Package: qsearch
qsearchAn implementation of a quantum gate synthesis algorithm based on A* and numerical optimization.  It relies onNumPyandSciPy.  It can export code forQiskitandOpenQASM.This is an implementation of the algorithm described in the paperTowards Optimal Topology Aware Quantum Circuit Synthesis.These are some results showing how qsearch can provide optimal or near optimal results. We compare results to theUniversalQ Compiler.Circuit# of QubitsRef #CNOT LinearCNOT RingUQ (CNOT Ring)CNOT Linear Unitary DistanceCNOT Ring Unitary DistanceQFT367*6*151.33 * 10-142.22 * 10-16Fredkin388791.76 * 10-140.0Toffoli368691.14 * 10-140.0Peres3576191.13 * 10-140.0HHL3N/A3*3*161.25 * 10-140.0Or3686101.72 * 10-140.0EntangledX342,3,42,3,491.26 * 10-140.0TFIM_3_33444170.00.0TFIM_6_33866174.44 * 10-160.0TFIM_42_335666178.88 * 10-160.0TFIM_60_338066176.66 * 10-160.0QFT4N/A13*896.66 * 10-16TFIM_30_446011879.08 * 10-11IBM Challenge4N/A4DNR0.0* Some gates occasionally resulted in circuits with different CNOT counts due to the optimizers getting stuck in local minima. The best run out of 10 is listed in these cases. The CNOT count for these circuits was occasionally 1 more than listed. The gate "EntangledX" is a parameterized gate, and for certain combinations of parameters we were able to produce solutions with fewer CNOTs than the hand-optimized general solution.InstallationThis is a python package which can be installed using pip.  You will need a Python version of at least 3.6. The qsearch compiler currently runs on macOS, Linux (includingthe Windows Subsystem for Linux) and Windows (performance is much worse on Windows). You can install it fromPyPiusing:pip3 install qsearchYou can also install from the git repository:pip3 install https://github.com/BQSKit/qsearch/archive/dev.zipor download and install it:git clone https://github.com/BQSKit/qsearch
pip3 install --upgrade ./qsearchIf you make changes to your local copy, you can reinstall the package:pip3 install --upgrade ./qsearchOnce installed, you can import the library like any other python package:import qsearchGetting Started: qsearch ProjectsThe simplest way to use the qsearch 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 qsearch
myproject = qsearch.Project("desired/path/to/project/directory")You can then add unitaries to compile, and set compiler properties. Unitary matrices should be provided asnumpyndarrays usingdtype="complex128".myproject.add_compilation("gate_name", gate_unitary)
myproject["compiler_option"] = valueOnce your project is configured, you can start your project by callingrun(). The compiler uses an automatic checkpointing system, so if it is killed while in-progress, it can be resumed by callingrun()again.myproject.run()Once your project is finished, you can get OpenQASM output:myproject.assemble("gate_name") # This will return a string of OpenQASM
myproject.assemble("gate_name", write_location="path/to/output/file") # This will write the qasm to the specified path.Compiling Without ProjectsIf you would like to avoid working with Projects, you can use theSearchCompilerclass directly.import qsearch
compiler = qsearch.SearchCompiler()
result = compiler.compile(target=target_unitary)TheSearchCompilerclass and thecompilefunction can take extra arguments to further configure the compiler.  The returned value is a dictionary that contains the unitary that represents the implemented circuit, theqsearch.gates.Gaterepresentation of the circuit structure, and the vector of parameters for the circuit structure.A Note On EndiannessWe 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 = qsearch.utils.endian_reverse(big_endian) # you can use the same function to convert in the other direction as wellDocumentation and ExamplesThe documentation and API reference can be foundon readthedocs.Also check out theexamples!Legal/Copyright informationPlease read ourLICENSE