Julia backend for Qiskit
Project description
qiskit_alt
qiskit_alt
This Python package uses a backend written in Julia to implement high performance features for standard Qiskit. This package is a proof of concept with little high-level code.
Installing and managing Julia and its packages is automated. So you don't need to learn anything about Julia to get started.
Table of contents
-
Installation and configuration notes
-
Compilation Compiling a system image to eliminate compilation at run time.
-
Using qiskit_alt First steps.
-
Manual Steps Details of automatic installation.
-
-
- Zapata demo of Jordan-Wigner transformation in Julia; The same thing as the main demonstration in qiskit_alt.
-
Julia Packages Julia packages that qiskit_alt depends on.
-
Development. Instructions for developing qiskit_alt.
Installation and Configuration Notes
Basic
qiskit_alt
is available on pypi
shell> pip install qiskit_alt
- Complete installation by running
import qiskit_alt
qiskit_alt.project.ensure_init()
See julia_project
for more options.
-
If no Julia executable is found,
jill.py
will be used to download and install it. It is not necessary to add the installation path or symlink path to your search PATH to use julia from qiskit_alt. Before offering to install Julia,qiskit_alt
will search for julia as described here. -
The Julia packages are installed the first time you run
qiskit_alt.project.ensure_init()
from Python. If this fails, see the log file qiskit_alt.log. You can open a bug report in theqiskit_alt
repo -
Check that the installation is not completely broken by running benchmark scripts, with the string "alt" in the name:
python ./bench/run_all_bench.py
Note that the folder bench
is not included when you install via pip install qiskit_alt
.
But it can be downloaded here.
More installation details
-
qiskit_alt
depends onpyjulia
and/orjuliacall
for communication between Julia and Python. -
pyjulia
andjuliacall
are two packages for communication between Python and Julia. You only need to import one of them. But, you won't import them directly. -
When you initialize with
qiskit_alt.project.ensure_init()
the default communication package is chosen. You can also choose explicitly withqiskit_alt.project.ensure_init(calljula="pyjulia")
orqiskit_alt.project.ensure_init(calljula="juliacall")
-
The installation is interactive. How to do a non-interactive installation with environment variables is described below.
-
You may allow
qiskit_alt
to download and install Julia for you, usingjill.py
. Otherwise you can follow instructions for installing Julia with an installation tool. -
We recommend using a virtual Python environment with
venv
orconda
. For examplepython -m venv ./env
, which creates a virtual environment for python packages needed to runqiskit_alt
. You can use whatever name you like in place of the directory./env
. -
Activate the environment using the file required for your shell. For example
source ./env/bin/activate
forvenv
and bash. -
Install
qiskit_alt
withpip install qiskit_alt
. -
Install whatever other packages you want. For example
pip install ipython
. -
Configuring installation with environment variables. If you set these environment variables, you will not be prompted during installation.
- Set
QISKIT_ALT_JULIA_PATH
to the path to a Julia executable (in a Julia installation). This variable takes precedence over other methods of specifying the path to the executable. - Set
QISKIT_ALT_INSTALL_JULIA
toy
orn
to confirm or disallow installing julia viajill.py
. - Set
QISKIT_ALT_COMPILE
toy
orn
to confirm or disallow compiling a system image after installing Julia packages - Set
QISKIT_ALT_DEPOT
toy
orn
to force using or not using a Julia "depot" specific to this project.
- Set
-
qiskit_alt.project.update()
will deleteManifest.toml
files; upgrade packages; rebuild the manifest; delete compiled system images. If you callupdate()
while running a compiled system image, you should exit Python and start again before compiling -
qiskit_alt.project
is an instance ofJuliaProject
from the packagejulia_project
. for managing Julia dependencies in Python projects. See more options atjulia_project
.
Compilation
- We highly recommend compiling a system image for
qiskit_alt
to speed up loading and reduce delays due to just-in-time compilation. You will be prompted to install when installing or upgrading. Compilation may also be done at any time as follows.
[1]: import qiskit_alt
In [2]: qiskit_alt.project.ensure_init(use_sys_image=False)
In [3]: qiskit_alt.project.compile()
Compilation takes about four minutes. The new Julia system image will be found the next time you import qiskit_alt
.
Note that we disabled possibly loading a previously-compiled system image before compiling a new one.
This avoids some possible stability issues.
Using qiskit_alt
This is a very brief introduction.
-
The
pyjulia
interface is exposed via thejulia
module. Thejuliacall
module is calledjuliacall
. However you should not doimport julia
orimport juliacall
beforeimport qiskit_alt
, andqiskit_alt.project.ensure_init()
(orqiskit_alt.project.ensure_init(calljulia="pyjulia")
orjuliacall
withqiskit_alt.project.ensure_init(calljulia="juliacall")
) This is becauseimport julia
will circumvent the facilities described above for choosing the julia executable and the compiled system image. -
Julia modules are loaded like this. Note that
qiskit_alt.project.julia
points to eitherjulia
orjuliacall
depending on which was chosen.
import qiskit_alt
qiskit_alt.project.ensure_init(calljulia=interface_choice)
Main = qiskit_alt.project.julia.Main
import qiskit_alt
; import julia
; from julia import PkgName
.
After this, all functions and symbols in PkgName
are available.
You can do, for example
In [1]: import qiskit_alt
In [2]: qiskit_alt.project.ensure_init()
In [3]: julia = qiskit_alt.project.julia
In [4]: julia.Main.cosd(90)
Out[4]: 0.0
In [5]: QuantumOps = qiskit_alt.project.simple_import("QuantumOps")
In [6]: pauli_sum = QuantumOps.rand_op_sum(QuantumOps.Pauli, 3, 4); pauli_sum
Out[6]:
<PyCall.jlwrap 4x3 QuantumOps.PauliSum{Vector{Vector{QuantumOps.Paulis.Pauli}}, Vector{Complex{Int64}}}:
IIZ * (1 + 0im)
XYI * (1 + 0im)
YIX * (1 + 0im)
ZIZ * (1 + 0im)>
In the last example above, PauliSum
is a Julia object. The PauliSum
can be converted to
a Qiskit SparsePauliOp
like this.
In [7]: from qiskit_alt.pauli_operators import PauliSum_to_SparsePauliOp
In [8]: PauliSum_to_SparsePauliOp(pauli_sum)
Out[8]:
SparsePauliOp(['ZII', 'IYX', 'XIY', 'ZIZ'],
coeffs=[1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])
Introduction
The highlights thus far are in benchmark code, which is
presented in the demonstration notebooks.
There is one demonstration notebook using pyjulia
and another demonstration notebook using juliacall
.
The main application-level demonstration is computing a qubit Hamiltonian as a qiskit.quantum_info.SparsePauliOp
from a Python list specifiying the molecule geometry in the same format as that used by qiskit_nature
.
- The Jordan-Wigner transform in qiskit_alt is 30 or so times faster than in qiskit-nature.
- Computing a Fermionic Hamiltonian from pyscf integrals is several times faster, with the factor increasing with the problem size.
- Converting an operator from the computational basis, as a numpy matrix, to the Pauli basis, as a
qiskit.quantum_info.SparsePauliOp
, is many times faster with the factor increasing rapidly in the number of qubits.
You might want to skip to installation instructions
Demonstration
-
There are a few demos in this demonstration benchmark notebook
-
The benchmark code is a good place to get an idea of what qiskit_alt can do.
-
Here are some demonstration notebooks of the Julia packages behind
qiskit_alt
. -
Zapata demo of Jordan-Wigner transformation in Julia; The same thing as the main demonstration in qiskit_alt. This is from JuliaCon 2020.
Managing Julia packages
- Available Julia modules are those in the standard library and those listed in Project.toml.
You can add more packages (and record them in
Project.toml
) by doingqiskit_alt.project.julia.Pkg.add("PackageName")
. You can also do the same by avoiding Python and using the julia cli.
Julia Packages
- The Julia repos
QuantumOps.jl
andElectronicStructure.jl
andQiskitQuantumInfo.jl
are not registered in the General Registry, but rather inQuantumRegistry
which contains just a handful of packages for this project.
Testing
The test folder is mostly out of date.
Testing installation with docker
See the readme.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file qiskit_alt-0.1.13.tar.gz
.
File metadata
- Download URL: qiskit_alt-0.1.13.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 914f8a35155ef52704cfa4131ce6df95aa31a8cc42890feb74df9d6343a5ef0a |
|
MD5 | c5af97ce95248a92ead91bbf1756da02 |
|
BLAKE2b-256 | ad5dc94f10e9b547ad946e31dcc5a9abdcce4a247c3e1a3b46e0f41cb2d323e2 |
File details
Details for the file qiskit_alt-0.1.13-py3-none-any.whl
.
File metadata
- Download URL: qiskit_alt-0.1.13-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 842bfee47e1edb64c6938867002adaeb0fd0660e69dc6fc4c000f113f4cca704 |
|
MD5 | a2ed1c536acf04dd3d1e977721f44a18 |
|
BLAKE2b-256 | 0f61275094174e2fac6c9525d8247aadea06117b73d3163bf60ed3f6cbb3d06e |