Package: search-compiler
search_compilerAn 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 paperHeuristics for Quantum Compiling with a Continuous Gate Set.InstallationThis 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, andthe Windows Subsystem for Linux. You can install it fromPyPiusing:pip3 install search_compilerYou can also install from a downloaded copy of the repository:git clone git@github.com:WolfLink/search_compiler.git
pip3 install ./search_compilerIf you make changes to your local copy, you can reinstall the package:pip3 install --upgrade ./search_compilerOnce installed, you can import the library like any other python package:import search_compiler as scNative GatesetThere is a gateset that is implemented in native code to be faster.See the wiki for installation instructions.Getting Started: search_compiler ProjectsThe 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 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 checkpoint 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 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 ProjectsIf you would like to avoid working with Projects, you can use theSearchCompilerclass directly.import search_compiler as sc
compiler = sc.SearchCompiler()
circuit, vector = compiler.compile(target_unitary)TheSearchCompilerclass and thecompilefunction can take extra arguments to further configure the compiler.  The return values are, in order, the unitary that represents the implemented circuit, thesc.QuantumSteprepresentation of the circuit structure, and the vector of parameters for the circuit structure.To export openqasm code, use theassemblefunction fromassembler.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 fileSee the wiki for details on compiler properties.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 = sc.utils.endian_reverse(big_endian) # you can use the same function to convert in the other direction as wellFind information on customizing the compiler in thewiki.