Skip to content

Commit 3bb8a2c

Browse files
committed
Add test coverage for constant math emulation
1 parent e2305a9 commit 3bb8a2c

File tree

13 files changed

+453
-0
lines changed

13 files changed

+453
-0
lines changed

projectq.egg-info/PKG-INFO

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
Metadata-Version: 1.0
2+
Name: projectq
3+
Version: 0.4.2
4+
Summary: ProjectQ - An open source software framework for quantum computing
5+
Home-page: http://www.projectq.ch
6+
Author: ProjectQ
7+
Author-email: [email protected]
8+
License: Apache 2
9+
Description: ProjectQ - An open source software framework for quantum computing
10+
==================================================================
11+
12+
.. image:: https://travis-ci.org/ProjectQ-Framework/ProjectQ.svg?branch=master
13+
:target: https://travis-ci.org/ProjectQ-Framework/ProjectQ
14+
15+
.. image:: https://coveralls.io/repos/github/ProjectQ-Framework/ProjectQ/badge.svg
16+
:target: https://coveralls.io/github/ProjectQ-Framework/ProjectQ
17+
18+
.. image:: https://readthedocs.org/projects/projectq/badge/?version=latest
19+
:target: http://projectq.readthedocs.io/en/latest/?badge=latest
20+
:alt: Documentation Status
21+
22+
.. image:: https://badge.fury.io/py/projectq.svg
23+
:target: https://badge.fury.io/py/projectq
24+
25+
.. image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6-brightgreen.svg
26+
27+
28+
ProjectQ is an open source effort for quantum computing.
29+
30+
It features a compilation framework capable of
31+
targeting various types of hardware, a high-performance quantum computer
32+
simulator with emulation capabilities, and various compiler plug-ins.
33+
This allows users to
34+
35+
- run quantum programs on the IBM Quantum Experience chip
36+
- simulate quantum programs on classical computers
37+
- emulate quantum programs at a higher level of abstraction (e.g.,
38+
mimicking the action of large oracles instead of compiling them to
39+
low-level gates)
40+
- export quantum programs as circuits (using TikZ)
41+
- get resource estimates
42+
43+
Examples
44+
--------
45+
46+
**First quantum program**
47+
48+
.. code-block:: python
49+
50+
from projectq import MainEngine # import the main compiler engine
51+
from projectq.ops import H, Measure # import the operations we want to perform (Hadamard and measurement)
52+
53+
eng = MainEngine() # create a default compiler (the back-end is a simulator)
54+
qubit = eng.allocate_qubit() # allocate a quantum register with 1 qubit
55+
56+
H | qubit # apply a Hadamard gate
57+
Measure | qubit # measure the qubit
58+
59+
eng.flush() # flush all gates (and execute measurements)
60+
print("Measured {}".format(int(qubit))) # converting a qubit to int or bool gives access to the measurement result
61+
62+
63+
ProjectQ 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:
64+
65+
.. image:: docs/images/braket_notation.svg
66+
:alt: Rx(theta)|qubit>
67+
:width: 100px
68+
69+
The same statement in ProjectQ's syntax is:
70+
71+
.. code-block:: python
72+
73+
Rx(theta) | qubit
74+
75+
The **|**-operator separates the specification of the gate operation (left-hand side) from the quantum bits to which the operation is applied (right-hand side).
76+
77+
**Changing the compiler and using a resource counter as a back-end**
78+
79+
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 on a linear chain and the architecture supports any single-qubit gate as well as the two-qubit CNOT and Swap operations:
80+
81+
.. code-block:: python
82+
83+
from projectq import MainEngine
84+
from projectq.backends import ResourceCounter
85+
from projectq.ops import QFT
86+
from projectq.setups import linear
87+
88+
compiler_engines = linear.get_engine_list(num_qubits=16,
89+
one_qubit_gates='any',
90+
two_qubit_gates=(CNOT, Swap))
91+
resource_counter = ResourceCounter()
92+
eng = MainEngine(backend=resource_counter, engine_list=compiler_engines)
93+
qureg = eng.allocate_qureg(16)
94+
QFT | qureg
95+
eng.flush()
96+
97+
print(resource_counter)
98+
99+
# This will output, among other information,
100+
# how many operations are needed to perform
101+
# this quantum fourier transform (QFT), i.e.,
102+
# Gate class counts:
103+
# AllocateQubitGate : 16
104+
# CXGate : 240
105+
# HGate : 16
106+
# R : 120
107+
# Rz : 240
108+
# SwapGate : 262
109+
110+
111+
**Running a quantum program on IBM's QE chips**
112+
113+
To run a program on the IBM Quantum Experience chips, all one has to do is choose the `IBMBackend` and the corresponding compiler:
114+
115+
.. code-block:: python
116+
117+
compiler_engines = projectq.setups.ibm16.get_engine_list()
118+
eng = MainEngine(IBMBackend(use_hardware=True, num_runs=1024,
119+
verbose=False, device='ibmqx5'),
120+
engine_list=compiler_engines)
121+
122+
123+
**Classically simulate a quantum program**
124+
125+
ProjectQ has a high-performance simulator which allows simulating up to about 30 qubits on a regular laptop. See the `simulator tutorial <https://github.com/ProjectQ-Framework/ProjectQ/blob/feature/update-readme/examples/simulator_tutorial.ipynb>`__ for more information. Using the emulation features of our simulator (fast classical shortcuts), one can easily emulate Shor's algorithm for problem sizes for which a quantum computer would require above 50 qubits, see our `example codes <http://projectq.readthedocs.io/en/latest/examples.html#shor-s-algorithm-for-factoring>`__.
126+
127+
128+
The advanced features of the simulator are also particularly useful to investigate algorithms for the simulation of quantum systems. For example, the simulator can evolve a quantum system in time (without Trotter errors) and it gives direct access to expectation values of Hamiltonians leading to extremely fast simulations of VQE type algorithms:
129+
130+
.. code-block:: python
131+
132+
from projectq import MainEngine
133+
from projectq.ops import All, Measure, QubitOperator, TimeEvolution
134+
135+
eng = MainEngine()
136+
wavefunction = eng.allocate_qureg(2)
137+
# Specify a Hamiltonian in terms of Pauli operators:
138+
hamiltonian = QubitOperator("X0 X1") + 0.5 * QubitOperator("Y0 Y1")
139+
# Apply exp(-i * Hamiltonian * time) (without Trotter error)
140+
TimeEvolution(time=1, hamiltonian=hamiltonian) | wavefunction
141+
# Measure the expection value using the simulator shortcut:
142+
eng.flush()
143+
value = eng.backend.get_expectation_value(hamiltonian, wavefunction)
144+
145+
# Last operation in any program should be measuring all qubits
146+
All(Measure) | qureg
147+
eng.flush()
148+
149+
150+
151+
Getting started
152+
---------------
153+
154+
To start using ProjectQ, simply follow the installation instructions in the `tutorials <http://projectq.readthedocs.io/en/latest/tutorials.html>`__. There, you will also find OS-specific hints, a small introduction to the ProjectQ syntax, and a few `code examples <http://projectq.readthedocs.io/en/latest/examples.html>`__. More example codes and tutorials can be found in the examples folder `here <https://github.com/ProjectQ-Framework/ProjectQ/tree/develop/examples>`__ on GitHub.
155+
156+
Also, make sure to check out the `ProjectQ
157+
website <http://www.projectq.ch>`__ and the detailed `code documentation <http://projectq.readthedocs.io/en/latest/>`__.
158+
159+
How to contribute
160+
-----------------
161+
162+
For information on how to contribute, please visit the `ProjectQ
163+
website <http://www.projectq.ch>`__ or send an e-mail to
164+
165+
166+
Please cite
167+
-----------
168+
169+
When using ProjectQ for research projects, please cite
170+
171+
- Damian S. Steiger, Thomas Häner, and Matthias Troyer "ProjectQ: An
172+
Open Source Software Framework for Quantum Computing"
173+
`Quantum 2, 49 (2018) <https://doi.org/10.22331/q-2018-01-31-49>`__
174+
(published on `arXiv <https://arxiv.org/abs/1612.08091>`__ on 23 Dec 2016)
175+
- Thomas Häner, Damian S. Steiger, Krysta M. Svore, and Matthias Troyer
176+
"A Software Methodology for Compiling Quantum Programs" `Quantum Sci. Technol. 3 (2018) 020501 <https://doi.org/10.1088/2058-9565/aaa5cc>`__
177+
(published on `arXiv <http://arxiv.org/abs/1604.01401>`__ on 5 Apr 2016)
178+
179+
Authors
180+
-------
181+
182+
The first release of ProjectQ (v0.1) was developed by `Thomas
183+
Häner <http://www.comp.phys.ethz.ch/people/person-detail.html?persid=179208>`__
184+
and `Damian S.
185+
Steiger <http://www.comp.phys.ethz.ch/people/person-detail.html?persid=165677>`__
186+
in the group of `Prof. Dr. Matthias
187+
Troyer <http://www.comp.phys.ethz.ch/people/troyer.html>`__ at ETH
188+
Zurich.
189+
190+
ProjectQ is constantly growing and `many other people <https://github.com/ProjectQ-Framework/ProjectQ/graphs/contributors>`__ have already contributed to it in the meantime.
191+
192+
License
193+
-------
194+
195+
ProjectQ is released under the Apache 2 license.
196+
197+
Platform: UNKNOWN

projectq.egg-info/SOURCES.txt

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
LICENSE
2+
MANIFEST.in
3+
NOTICE
4+
README.rst
5+
pytest.ini
6+
requirements.txt
7+
setup.py
8+
projectq/__init__.py
9+
projectq/_version.py
10+
projectq.egg-info/PKG-INFO
11+
projectq.egg-info/SOURCES.txt
12+
projectq.egg-info/dependency_links.txt
13+
projectq.egg-info/not-zip-safe
14+
projectq.egg-info/requires.txt
15+
projectq.egg-info/top_level.txt
16+
projectq/backends/__init__.py
17+
projectq/backends/_printer.py
18+
projectq/backends/_printer_test.py
19+
projectq/backends/_resource.py
20+
projectq/backends/_resource_test.py
21+
projectq/backends/_circuits/__init__.py
22+
projectq/backends/_circuits/_drawer.py
23+
projectq/backends/_circuits/_drawer_test.py
24+
projectq/backends/_circuits/_to_latex.py
25+
projectq/backends/_circuits/_to_latex_test.py
26+
projectq/backends/_ibm/__init__.py
27+
projectq/backends/_ibm/_ibm.py
28+
projectq/backends/_ibm/_ibm_http_client.py
29+
projectq/backends/_ibm/_ibm_http_client_test.py
30+
projectq/backends/_ibm/_ibm_test.py
31+
projectq/backends/_sim/__init__.py
32+
projectq/backends/_sim/_classical_simulator.py
33+
projectq/backends/_sim/_classical_simulator_test.py
34+
projectq/backends/_sim/_cppsim.cpp
35+
projectq/backends/_sim/_pysim.py
36+
projectq/backends/_sim/_simulator.py
37+
projectq/backends/_sim/_simulator_test.py
38+
projectq/backends/_sim/_cppkernels/fusion.hpp
39+
projectq/backends/_sim/_cppkernels/simulator.hpp
40+
projectq/backends/_sim/_cppkernels/intrin/alignedallocator.hpp
41+
projectq/backends/_sim/_cppkernels/intrin/cintrin.hpp
42+
projectq/backends/_sim/_cppkernels/intrin/kernel1.hpp
43+
projectq/backends/_sim/_cppkernels/intrin/kernel2.hpp
44+
projectq/backends/_sim/_cppkernels/intrin/kernel3.hpp
45+
projectq/backends/_sim/_cppkernels/intrin/kernel4.hpp
46+
projectq/backends/_sim/_cppkernels/intrin/kernel5.hpp
47+
projectq/backends/_sim/_cppkernels/intrin/kernels.hpp
48+
projectq/backends/_sim/_cppkernels/nointrin/kernel1.hpp
49+
projectq/backends/_sim/_cppkernels/nointrin/kernel2.hpp
50+
projectq/backends/_sim/_cppkernels/nointrin/kernel3.hpp
51+
projectq/backends/_sim/_cppkernels/nointrin/kernel4.hpp
52+
projectq/backends/_sim/_cppkernels/nointrin/kernel5.hpp
53+
projectq/backends/_sim/_cppkernels/nointrin/kernels.hpp
54+
projectq/cengines/__init__.py
55+
projectq/cengines/_basicmapper.py
56+
projectq/cengines/_basicmapper_test.py
57+
projectq/cengines/_basics.py
58+
projectq/cengines/_basics_test.py
59+
projectq/cengines/_cmdmodifier.py
60+
projectq/cengines/_cmdmodifier_test.py
61+
projectq/cengines/_ibm5qubitmapper.py
62+
projectq/cengines/_ibm5qubitmapper_test.py
63+
projectq/cengines/_linearmapper.py
64+
projectq/cengines/_linearmapper_test.py
65+
projectq/cengines/_main.py
66+
projectq/cengines/_main_test.py
67+
projectq/cengines/_manualmapper.py
68+
projectq/cengines/_manualmapper_test.py
69+
projectq/cengines/_optimize.py
70+
projectq/cengines/_optimize_test.py
71+
projectq/cengines/_swapandcnotflipper.py
72+
projectq/cengines/_swapandcnotflipper_test.py
73+
projectq/cengines/_tagremover.py
74+
projectq/cengines/_tagremover_test.py
75+
projectq/cengines/_testengine.py
76+
projectq/cengines/_testengine_test.py
77+
projectq/cengines/_twodmapper.py
78+
projectq/cengines/_twodmapper_test.py
79+
projectq/cengines/_replacer/__init__.py
80+
projectq/cengines/_replacer/_decomposition_rule.py
81+
projectq/cengines/_replacer/_decomposition_rule_set.py
82+
projectq/cengines/_replacer/_decomposition_rule_test.py
83+
projectq/cengines/_replacer/_replacer.py
84+
projectq/cengines/_replacer/_replacer_test.py
85+
projectq/libs/__init__.py
86+
projectq/libs/math/__init__.py
87+
projectq/libs/math/_constantmath.py
88+
projectq/libs/math/_constantmath_test.py
89+
projectq/libs/math/_default_rules.py
90+
projectq/libs/math/_gates.py
91+
projectq/libs/math/_gates_test.py
92+
projectq/libs/revkit/__init__.py
93+
projectq/libs/revkit/_control_function.py
94+
projectq/libs/revkit/_control_function_test.py
95+
projectq/libs/revkit/_permutation.py
96+
projectq/libs/revkit/_permutation_test.py
97+
projectq/libs/revkit/_phase.py
98+
projectq/libs/revkit/_phase_test.py
99+
projectq/libs/revkit/_utils.py
100+
projectq/meta/__init__.py
101+
projectq/meta/_compute.py
102+
projectq/meta/_compute_test.py
103+
projectq/meta/_control.py
104+
projectq/meta/_control_test.py
105+
projectq/meta/_dagger.py
106+
projectq/meta/_dagger_test.py
107+
projectq/meta/_dirtyqubit.py
108+
projectq/meta/_dirtyqubit_test.py
109+
projectq/meta/_logicalqubit.py
110+
projectq/meta/_logicalqubit_test.py
111+
projectq/meta/_loop.py
112+
projectq/meta/_loop_test.py
113+
projectq/meta/_util.py
114+
projectq/meta/_util_test.py
115+
projectq/ops/__init__.py
116+
projectq/ops/_basics.py
117+
projectq/ops/_basics_test.py
118+
projectq/ops/_command.py
119+
projectq/ops/_command_test.py
120+
projectq/ops/_gates.py
121+
projectq/ops/_gates_test.py
122+
projectq/ops/_metagates.py
123+
projectq/ops/_metagates_test.py
124+
projectq/ops/_qaagate.py
125+
projectq/ops/_qaagate_test.py
126+
projectq/ops/_qftgate.py
127+
projectq/ops/_qftgate_test.py
128+
projectq/ops/_qpegate.py
129+
projectq/ops/_qpegate_test.py
130+
projectq/ops/_qubit_operator.py
131+
projectq/ops/_qubit_operator_test.py
132+
projectq/ops/_shortcuts.py
133+
projectq/ops/_shortcuts_test.py
134+
projectq/ops/_state_prep.py
135+
projectq/ops/_state_prep_test.py
136+
projectq/ops/_time_evolution.py
137+
projectq/ops/_time_evolution_test.py
138+
projectq/ops/_uniformly_controlled_rotation.py
139+
projectq/ops/_uniformly_controlled_rotation_test.py
140+
projectq/setups/__init__.py
141+
projectq/setups/default.py
142+
projectq/setups/grid.py
143+
projectq/setups/grid_test.py
144+
projectq/setups/ibm.py
145+
projectq/setups/ibm16.py
146+
projectq/setups/ibm16_test.py
147+
projectq/setups/ibm_test.py
148+
projectq/setups/linear.py
149+
projectq/setups/linear_test.py
150+
projectq/setups/restrictedgateset.py
151+
projectq/setups/restrictedgateset_test.py
152+
projectq/setups/decompositions/__init__.py
153+
projectq/setups/decompositions/_gates_test.py
154+
projectq/setups/decompositions/amplitudeamplification.py
155+
projectq/setups/decompositions/amplitudeamplification_test.py
156+
projectq/setups/decompositions/arb1qubit2rzandry.py
157+
projectq/setups/decompositions/arb1qubit2rzandry_test.py
158+
projectq/setups/decompositions/barrier.py
159+
projectq/setups/decompositions/barrier_test.py
160+
projectq/setups/decompositions/carb1qubit2cnotrzandry.py
161+
projectq/setups/decompositions/carb1qubit2cnotrzandry_test.py
162+
projectq/setups/decompositions/cnot2cz.py
163+
projectq/setups/decompositions/cnot2cz_test.py
164+
projectq/setups/decompositions/cnu2toffoliandcu.py
165+
projectq/setups/decompositions/cnu2toffoliandcu_test.py
166+
projectq/setups/decompositions/crz2cxandrz.py
167+
projectq/setups/decompositions/entangle.py
168+
projectq/setups/decompositions/globalphase.py
169+
projectq/setups/decompositions/ph2r.py
170+
projectq/setups/decompositions/phaseestimation.py
171+
projectq/setups/decompositions/phaseestimation_test.py
172+
projectq/setups/decompositions/qft2crandhadamard.py
173+
projectq/setups/decompositions/qubitop2onequbit.py
174+
projectq/setups/decompositions/qubitop2onequbit_test.py
175+
projectq/setups/decompositions/r2rzandph.py
176+
projectq/setups/decompositions/rx2rz.py
177+
projectq/setups/decompositions/rx2rz_test.py
178+
projectq/setups/decompositions/ry2rz.py
179+
projectq/setups/decompositions/ry2rz_test.py
180+
projectq/setups/decompositions/sqrtswap2cnot.py
181+
projectq/setups/decompositions/sqrtswap2cnot_test.py
182+
projectq/setups/decompositions/stateprep2cnot.py
183+
projectq/setups/decompositions/stateprep2cnot_test.py
184+
projectq/setups/decompositions/swap2cnot.py
185+
projectq/setups/decompositions/time_evolution.py
186+
projectq/setups/decompositions/time_evolution_test.py
187+
projectq/setups/decompositions/toffoli2cnotandtgate.py
188+
projectq/setups/decompositions/uniformlycontrolledr2cnot.py
189+
projectq/setups/decompositions/uniformlycontrolledr2cnot_test.py
190+
projectq/tests/__init__.py
191+
projectq/tests/_factoring_test.py
192+
projectq/types/__init__.py
193+
projectq/types/_qubit.py
194+
projectq/types/_qubit_test.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

projectq.egg-info/not-zip-safe

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)