ProjectQ is an open source effort for quantum computing.
It features a compilation framework capable of targeting various types of hardware, a high-performance quantum computer simulator with emulation capabilities, and various compiler plug-ins. This allows users to
- run quantum programs on the IBM Quantum Experience chip
- simulate quantum programs on classical computers
- emulate quantum programs at a higher level of abstraction (e.g., mimicking the action of large oracles instead of compiling them to low-level gates)
- export quantum programs as circuits (using TikZ)
- get resource estimates
First quantum program
from projectq import MainEngine # import the main compiler engine
from projectq.ops import H, Measure # import the operations we want to perform (Hadamard and measurement)
eng = MainEngine() # create a default compiler (the back-end is a simulator)
qubit = eng.allocate_qubit() # allocate a qunatum register with 1 qubit
H | qubit # apply a Hadamard gate
Measure | qubit # measure the qubit
eng.flush() # flush all gates (and execute measurements)
print("Measured {}".format(int(qubit))) # converting a qubit to int or bool gives access to the measurement resultProjectQ features a lean syntax which is close to the mathematical notation used in quantum physics. For example a rotation of a qubit around the x-axis is usually specified as:
The same statement in ProjectQ's syntax is:
Rx(theta) | qubitEverything to the left of |-operator specifies the gate operation and on the right-hand side are the quantum bits to which the operation is applied to.
Changing the compiler and using a resource counter as a back-end
Instead of simulating a quantum program, one can use our resource counter (as a back-end) to determine how many operations it would take on a future quantum computer with a given architecture. Suppose the qubits are arranged in linear chain and the architecture supports any single-qubit gate as well as the two-qubit CNOT and Swap operation:
from projectq import MainEngine
from projectq.backends import ResourceCounter
from projectq.ops import QFT
from projectq.setups import linear
compiler_engines = linear.get_engine_list(num_qubits=16,
one_qubit_gates='any',
two_qubit_gates=(CNOT, Swap))
resource_counter = ResourceCounter()
eng = MainEngine(backend=resource_counter, engine_list=compiler_engines)
qureg = eng.allocate_qureg(16)
QFT | qureg
eng.flush()
print(resource_counter)
# This will output, among other information,
# how many operations are needed to perform
# this quantum fourier transform (QFT), e.g.:
# Gate class counts:
# AllocateQubitGate : 16
# CXGate : 240
# HGate : 16
# R : 120
# Rz : 240
# SwapGate : 262Running a quantum program on IBM's QE chips
To run a program on the IBM Quantum Experience chips, all one has to do is choose the IBMBackend and the corresponding compiler:
compiler_engines = projectq.setups.ibm16.get_engine_list()
eng = MainEngine(IBMBackend(use_hardware=True, num_runs=1024,
verbose=False, device='ibmqx5'),
engine_list=compiler_engines)Classically simulate a quantum program
ProjectQ has a high-performance simulator. This allows to easily simulate 30-qubit circuit if the computer has 16GB of RAM. See the simulator tutorial for more information.
To start using ProjectQ, simply follow the installation instructions in the tutorials. There, you will also find OS-specific hints, a small introduction to the ProjectQ syntax, and a few code examples. More example codes and tutorials can be found in the examples folder here on GitHub.
Also, make sure to check out the ProjectQ website and the detailed code documentation.
For information on how to contribute, please visit the ProjectQ website or send an e-mail to info@projectq.ch.
When using ProjectQ for research projects, please cite
- Damian S. Steiger, Thomas Häner, and Matthias Troyer "ProjectQ: An Open Source Software Framework for Quantum Computing" Quantum 2, 49 (2018) (published on arXiv on 23 Dec 2016)
- Thomas Häner, Damian S. Steiger, Krysta M. Svore, and Matthias Troyer "A Software Methodology for Compiling Quantum Programs" Quantum Sci. Technol. 3 (2018) 020501 (published on arXiv on 5 Apr 2016)
The first release of ProjectQ (v0.1) was developed by Thomas Häner and Damian S. Steiger in the group of Prof. Dr. Matthias Troyer at ETH Zurich.
ProjectQ is constantly growing and many other people have already contributed to it in the meantime.
ProjectQ is released under the Apache 2 license.