Package: qsrs
qsrs: qsearch Rust implementationThis is a (partial) implementation of the algorithm described in the paperHeuristics for Quantum Compiling with a Continuous Gate Set.
However, re-writing in Rust has provided up to a 20x speedup in compilation time.
At some future point, this project will be usable as a stand-alone Rust program that will be able
to compile quantum circuits.There are Python bindings to the Rust code that are used in the qsearch package. These
should automatically be installed from PyPi when you install qsearch.Installingqsrsis available on PyPi:pip3 install qsrsIf you would like to build from source see "Building and Installing" below.Supported gatesThe current list of "gates" supported is:IdentityX90ZX90Z (combined for performance reasons)IBM U3KroneckerProductX, Y, ZAny constant, unparameterized gate such as CNOTThis list will likely grow as needed.Building and InstallingIf you are on a 64 bit macOS, Windows, or Linux, you can install viapip3 install qsrs.You can also install from source.LinuxMake sure the version of pip you have is at least 20.0.2.
You can check viapip -Vand upgrade viapython3 -m pip install -U pip.First, install the dependencies. On modern Debian based machines you should be able to install the dependencies like the following,
note that the version of libgfortran-10-dev may be different.sudo apt install libopenblas-dev libceres-dev libgfortran-10-devOnce that is complete you should then install Rust like as follows:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shAccept all of the default prompts. You probably want tosource ~/.cargo/env, then switch to the nightly toolchain:rustup default nightlyThen you can enter theqsrsdirectory and runpip install .This will take a while. Once it is done, verify that the installation succeeded by runningpython3 -c 'import qsrs'It should not print anything out nor give any error.On Linux, you can also build wheels with Docker, staticly linking a custom builtopenblas.
Incidently, this is how the packages on PyPi are built.Install dockerhttps://docs.docker.com/install/Run the container to build wheels:docker run --rm -v $(pwd):/io ethanhs/maturin-manylinux-2010:0.6 build --cargo-extra-args="--no-default-features --features python,static,rustopt" --release --manylinux 2010 --no-sdistInstall the correct wheel for your Python version intarget/wheels(e.g.qsrs-0.13.0-cp37-cp37m-manylinux2010_x86_64.whlfor Python 3.7)MacOSMake sure the version of pip you have is at least 20.0.2.
You can check viapip -Vand upgrade viapython3 -m pip install -U pip.First, install the dependencies. We use homebrew here, which is what we build the official package against.brew install gcc ceres-solverOnce that is complete you should then install Rust like as follows:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shAccept all of the default prompts. You probably want tosource ~/.cargo/env, then switch to the nightly toolchain:rustup default nightlyThen you can enter theqsrsdirectory and run the following to build a wheel linking to Apple's Acceleratematurin build -i python --cargo-extra-args="--no-default-features --features=accelerate,python,rustopt,ceres/system" --release --no-sdistThis will take a while. Once it is done, install the wheel likepip3 install target/wheels/qsrs-0.15.1-cp38-cp38-macosx_10_7_x86_64.whlNote the name of the wheel may be slightly different depending on your Python version, but it should be the only wheel in thetarget/wheels/folder.Verify that the installation succeeded by runningpython3 -c 'import qsrs'It should not print anything out nor give any error.WindowsMake sure the version of pip you have is at least 20.0.2.
You can check viapip -Vand upgrade viapython3 -m pip install -U pip.Download and install rust via the installer found athttps://rustup.rs/. Accept all of the defaults.Close your shell and open a new one (this updates the enviroment). Then runrustup default nightlyThen installcargo-vcpkg, which will help install dependencies for us. You can install it viacargo install cargo-vcpkgcargois installed with Rust so this should work.Then in the qsrs folder, runcargo vcpkg buildThis will likely take a while.Once it is done, build a wheel viamaturin build -i python --cargo-extra-args="--no-default-features --features python,static,rustopt" --release --no-sdistThen you should be able to install the generated wheel package likepip install -U target\wheels\qsrs-0.15.1-cp37-none-win_amd64.whlNote the name of the wheel may be slightly different depending on your Python version, but it should be the only wheel in thetarget/wheels/folder.Verify that the installation succeeded by runningpython3 -c 'import qsrs'It should not print anything out nor give any error.UsagePlease see theqsearchwikifor how to use this with qsearch.
`Testing and ContributingTo run the tests, clone the repo then run:$ pip install .
$ pip install -r ../test-requirements.txt
$ cd .. && pytestLicenseSince NLOpt's L-BFGS implementation is LGPL licensed, if therustoptfeature is enabled
(it is enabled by default), qsrs is LGPL licensed as it statically links to NLOpt.
If you disable therustoptfeature, then the combined work is BSD 3 clause licensed.In addition, if you disablerustopt, you can still enable theceresfeature for a BSD-3
licensed product, but since this crate is usually dynamically linked in the end, it doesn't
really matter.
Please see LICENSE for more information.