A quantum computing simulator.
Project description
Links
What Is PyQCS?
PyQCS is a Quantum Computing Simulator built for physics. It currently features two simulator backends for different purposes, and a way to construct circuits in a relatively readable manner.
By default PyQCS employs a relatively slow simulator backend using dense state vectors. Note that any implementation using dense state vectors shows exponential growth in the number of qbits. Therefore this simulator backend is limited to qbit numbers below 30 for reasonable performance. For simulations requiring more qbits we recommend using a high performance framework, such as GPT’s QIS module.
The second backend uses a graphical state representation (see for instance arXiv:quant-ph/0504117) which allows for the simulation of stabilizer states and -circuits. The graphical simulator is considerably faster, in particular it does not exhibit exponential growth in the number of qbits. The graphical states are available as pyqcs.graph.state.GraphState.
Unlike other simulators PyQCS focuses on the state: Users start from a state, modify the state (using circuits) and then either look at the state or sample from the state. This direct access to the state is useful when debugging circuits or when considering physical problems. However, it can slow down compuations.
Using PyQCS
To do some computation one has to build a quantum circuit and apply it to a state. States are created using pyqcs.State.new_zero_state(<number of qbits>).
Circuits are built from the fundamental gates (see Built-in Gates) by joining them together using the | operator:
from pyqcs import H, CX, X circuit = H(0) | CX(1, 0) | X(1)
The usage of the | is in analogy to the UNIX pipe: gates are applied from left to right. This is in agreement with the Feynman quantum circuit diagrams.
Note: the circuit above would have the following matrix representation:
Applying a circuit to a state is done using multiplication:
from pyqcs import State state = State.new_zero_state(2) resulting_state = circuit * state
New in v2.2.0 is the circuitpng function that allows displaying circuits as PNGs (using a pdflatex implementation and imagemagick):
from pyqcs import H, CX, circuitpng circuit = (H(1) | H(2)) | CX(2, 1) | (H(1) | H(2)) circuitpng(circuit)
Built-in Gates
PyQCS currently has the following gates built-in:
- X
Pauli-X or NOT gate. Flips the respective qbit.
- H
Hadamard gate.
- CX
CNOT (controlled NOT) gate. Flips the act-qbit, if the control-qbit is set.
- R
R, Rz or R_phi, the rotation gate. Rotates the respective qbit around a given angle.
- M
Measurement gate: this gate measures the respective gate, collapsing the wave function and storing the result in the classical part of the state.
- Z
Pauli-Z gate.
- S
Clifford-S gate.
- CZ
Controlled Z gate.
Using the C++ Backend
Starting from version 3.0.0 PyQCS has a pure C++ backend omitting the previously used numpy arrays. The python package uses handwritten adapters to this backend.
The backend can be used as a stand-alone library. It can be built and installed using the src/backend/meson.build file. Its usage is a bit different from what one would usually expect from a simulator: Operations like measurement are not implemented explicitly but should be implemented by the user using a random number generator and the provided compute_amplitude methods.
Besides that the code should be pretty much self-explaining. See the adapter code for some ideas how to use the backend.
TODOs
Add pretty printers for states.
Write lot’s of documentation.
Add more tests.
Add a noise model.
Add a way to export circuits to GPT’s QIS module.
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
File details
Details for the file pyqcs-3.0.0.tar.gz
.
File metadata
- Download URL: pyqcs-3.0.0.tar.gz
- Upload date:
- Size: 704.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72b3986f6adb41294df75f3850a20157f0ec54bbad1230c6ebcd497d9fb66425 |
|
MD5 | 896221b8393dda47beb72ebd5fb4872e |
|
BLAKE2b-256 | d1eb693f8cfc5a0e49e4e919c7f9879ea4b94904f85086c75257d7ac69550729 |