Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Native Gateset

Marc Davis edited this page Apr 30, 2020 · 6 revisions

Building and Installing

If you are on a 64 bit macOS or Linux, you can install via pip3 install search_compiler[native]. As of version 1.2.0, the Rust code should be installed automatically when you install search_compiler.

On Linux or MacOS, you can also build and install scrs from source using a system installation of openblas.

  1. Install the blas library if needed. If you want to use Apple Accelerate, it should come with macOS. For openblas, on Debian based Linux distros you will need to install libopenblas-dev. You will also need the libgfortran-<version>-dev package (for whatever version your distro supplies). For openblas on macOS, you can install these via Homebrew as brew install openblas gcc.
  2. Install rustup via https://rustup.rs. The defaults for platform should be fine.
  3. Switch to the nightly toolchain using rustup default nightly. You may need to do source ~/.cargo/env first.
  4. If you are not using openblas, uncomment the corresponding line in the pyproject.toml file for Accelerate or MKL. In the native/ directory run pip install . Make sure the version of pip you have is at least 20.0.2. You can check via pip -V.
  5. Done! You should now be able to use the any of the *_SolverNative solvers from search_compiler.solver. Verify your install is working by running python3 -c 'import search_compiler_rs'

On Linux, you can also build wheels with Docker, staticly linking a custom built openblas. Incidently, this is how the packages on PyPi are built.

  1. Install docker https://docs.docker.com/install/
  2. Run the container to build wheels: docker run --rm -v $(pwd):/io ethanhs/maturin-manylinux-2010:0.1 build --cargo-extra-args="--no-default-features --features static" --release --manylinux 2010
  3. Install the correct wheel for your Python version in native/target/wheels (e.g. scrs-0.6.0-cp37-cp37m-manylinux2010_x86_64.whl for Python 3.7)

Usage

You can use the native gateset in order to achieve significantly faster synthesis speeds. A "supported gateset" is one that uses only some combination of constant gates, QiskitU3QubitStep, XZXZPartialQubitStep, and ZXZXZQubitStep. Currently if you use any of the following solvers with a supported gateset, you should get the speed advantage. These solvers will be chosen automatically when available if the default solver setting has not been overridden:

  • COBYLA_SolverNative
  • BFGS_Jac_SolverNative
  • LeastSquares_Jac_SolverNative
import search_compiler as sc
# Use with a project (remember to use the default sc.QubitCNOTLinear() gateset or one that uses only supported gates)
p = sc.Project("myproject")
p["solver"] = sc.solver.LeastSquares_Jac_SolverNative()

# Use with SearchCompiler directly
compiler = sc.SearchCompiler(solver=sc.solver.LeastSquares_Jac_SolverNative())
Clone this wiki locally