Skip to content

Commit

Permalink
Add test coverage for constant math emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Takishima committed Aug 14, 2019
1 parent e2305a9 commit 3bb8a2c
Show file tree
Hide file tree
Showing 13 changed files with 453 additions and 0 deletions.
197 changes: 197 additions & 0 deletions projectq.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
Metadata-Version: 1.0
Name: projectq
Version: 0.4.2
Summary: ProjectQ - An open source software framework for quantum computing
Home-page: http://www.projectq.ch
Author: ProjectQ
Author-email: info@projectq.ch
License: Apache 2
Description: ProjectQ - An open source software framework for quantum computing
==================================================================

.. image:: https://travis-ci.org/ProjectQ-Framework/ProjectQ.svg?branch=master
:target: https://travis-ci.org/ProjectQ-Framework/ProjectQ

.. image:: https://coveralls.io/repos/github/ProjectQ-Framework/ProjectQ/badge.svg
:target: https://coveralls.io/github/ProjectQ-Framework/ProjectQ

.. image:: https://readthedocs.org/projects/projectq/badge/?version=latest
:target: http://projectq.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://badge.fury.io/py/projectq.svg
:target: https://badge.fury.io/py/projectq

.. image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6-brightgreen.svg


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

Examples
--------

**First quantum program**

.. code-block:: python

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 quantum 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 result


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:

.. image:: docs/images/braket_notation.svg
:alt: Rx(theta)|qubit>
:width: 100px

The same statement in ProjectQ's syntax is:

.. code-block:: python

Rx(theta) | qubit

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).

**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 on a linear chain and the architecture supports any single-qubit gate as well as the two-qubit CNOT and Swap operations:

.. code-block:: python

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), i.e.,
# Gate class counts:
# AllocateQubitGate : 16
# CXGate : 240
# HGate : 16
# R : 120
# Rz : 240
# SwapGate : 262


**Running 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:

.. code-block:: python

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 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>`__.


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:

.. code-block:: python

from projectq import MainEngine
from projectq.ops import All, Measure, QubitOperator, TimeEvolution

eng = MainEngine()
wavefunction = eng.allocate_qureg(2)
# Specify a Hamiltonian in terms of Pauli operators:
hamiltonian = QubitOperator("X0 X1") + 0.5 * QubitOperator("Y0 Y1")
# Apply exp(-i * Hamiltonian * time) (without Trotter error)
TimeEvolution(time=1, hamiltonian=hamiltonian) | wavefunction
# Measure the expection value using the simulator shortcut:
eng.flush()
value = eng.backend.get_expectation_value(hamiltonian, wavefunction)

# Last operation in any program should be measuring all qubits
All(Measure) | qureg
eng.flush()



Getting started
---------------

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.

Also, make sure to check out the `ProjectQ
website <http://www.projectq.ch>`__ and the detailed `code documentation <http://projectq.readthedocs.io/en/latest/>`__.

How to contribute
-----------------

For information on how to contribute, please visit the `ProjectQ
website <http://www.projectq.ch>`__ or send an e-mail to
info@projectq.ch.

Please cite
-----------

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) <https://doi.org/10.22331/q-2018-01-31-49>`__
(published on `arXiv <https://arxiv.org/abs/1612.08091>`__ 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 <https://doi.org/10.1088/2058-9565/aaa5cc>`__
(published on `arXiv <http://arxiv.org/abs/1604.01401>`__ on 5 Apr 2016)

Authors
-------

The first release of ProjectQ (v0.1) was developed by `Thomas
Häner <http://www.comp.phys.ethz.ch/people/person-detail.html?persid=179208>`__
and `Damian S.
Steiger <http://www.comp.phys.ethz.ch/people/person-detail.html?persid=165677>`__
in the group of `Prof. Dr. Matthias
Troyer <http://www.comp.phys.ethz.ch/people/troyer.html>`__ at ETH
Zurich.

ProjectQ is constantly growing and `many other people <https://github.com/ProjectQ-Framework/ProjectQ/graphs/contributors>`__ have already contributed to it in the meantime.

License
-------

ProjectQ is released under the Apache 2 license.

Platform: UNKNOWN
194 changes: 194 additions & 0 deletions projectq.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
LICENSE
MANIFEST.in
NOTICE
README.rst
pytest.ini
requirements.txt
setup.py
projectq/__init__.py
projectq/_version.py
projectq.egg-info/PKG-INFO
projectq.egg-info/SOURCES.txt
projectq.egg-info/dependency_links.txt
projectq.egg-info/not-zip-safe
projectq.egg-info/requires.txt
projectq.egg-info/top_level.txt
projectq/backends/__init__.py
projectq/backends/_printer.py
projectq/backends/_printer_test.py
projectq/backends/_resource.py
projectq/backends/_resource_test.py
projectq/backends/_circuits/__init__.py
projectq/backends/_circuits/_drawer.py
projectq/backends/_circuits/_drawer_test.py
projectq/backends/_circuits/_to_latex.py
projectq/backends/_circuits/_to_latex_test.py
projectq/backends/_ibm/__init__.py
projectq/backends/_ibm/_ibm.py
projectq/backends/_ibm/_ibm_http_client.py
projectq/backends/_ibm/_ibm_http_client_test.py
projectq/backends/_ibm/_ibm_test.py
projectq/backends/_sim/__init__.py
projectq/backends/_sim/_classical_simulator.py
projectq/backends/_sim/_classical_simulator_test.py
projectq/backends/_sim/_cppsim.cpp
projectq/backends/_sim/_pysim.py
projectq/backends/_sim/_simulator.py
projectq/backends/_sim/_simulator_test.py
projectq/backends/_sim/_cppkernels/fusion.hpp
projectq/backends/_sim/_cppkernels/simulator.hpp
projectq/backends/_sim/_cppkernels/intrin/alignedallocator.hpp
projectq/backends/_sim/_cppkernels/intrin/cintrin.hpp
projectq/backends/_sim/_cppkernels/intrin/kernel1.hpp
projectq/backends/_sim/_cppkernels/intrin/kernel2.hpp
projectq/backends/_sim/_cppkernels/intrin/kernel3.hpp
projectq/backends/_sim/_cppkernels/intrin/kernel4.hpp
projectq/backends/_sim/_cppkernels/intrin/kernel5.hpp
projectq/backends/_sim/_cppkernels/intrin/kernels.hpp
projectq/backends/_sim/_cppkernels/nointrin/kernel1.hpp
projectq/backends/_sim/_cppkernels/nointrin/kernel2.hpp
projectq/backends/_sim/_cppkernels/nointrin/kernel3.hpp
projectq/backends/_sim/_cppkernels/nointrin/kernel4.hpp
projectq/backends/_sim/_cppkernels/nointrin/kernel5.hpp
projectq/backends/_sim/_cppkernels/nointrin/kernels.hpp
projectq/cengines/__init__.py
projectq/cengines/_basicmapper.py
projectq/cengines/_basicmapper_test.py
projectq/cengines/_basics.py
projectq/cengines/_basics_test.py
projectq/cengines/_cmdmodifier.py
projectq/cengines/_cmdmodifier_test.py
projectq/cengines/_ibm5qubitmapper.py
projectq/cengines/_ibm5qubitmapper_test.py
projectq/cengines/_linearmapper.py
projectq/cengines/_linearmapper_test.py
projectq/cengines/_main.py
projectq/cengines/_main_test.py
projectq/cengines/_manualmapper.py
projectq/cengines/_manualmapper_test.py
projectq/cengines/_optimize.py
projectq/cengines/_optimize_test.py
projectq/cengines/_swapandcnotflipper.py
projectq/cengines/_swapandcnotflipper_test.py
projectq/cengines/_tagremover.py
projectq/cengines/_tagremover_test.py
projectq/cengines/_testengine.py
projectq/cengines/_testengine_test.py
projectq/cengines/_twodmapper.py
projectq/cengines/_twodmapper_test.py
projectq/cengines/_replacer/__init__.py
projectq/cengines/_replacer/_decomposition_rule.py
projectq/cengines/_replacer/_decomposition_rule_set.py
projectq/cengines/_replacer/_decomposition_rule_test.py
projectq/cengines/_replacer/_replacer.py
projectq/cengines/_replacer/_replacer_test.py
projectq/libs/__init__.py
projectq/libs/math/__init__.py
projectq/libs/math/_constantmath.py
projectq/libs/math/_constantmath_test.py
projectq/libs/math/_default_rules.py
projectq/libs/math/_gates.py
projectq/libs/math/_gates_test.py
projectq/libs/revkit/__init__.py
projectq/libs/revkit/_control_function.py
projectq/libs/revkit/_control_function_test.py
projectq/libs/revkit/_permutation.py
projectq/libs/revkit/_permutation_test.py
projectq/libs/revkit/_phase.py
projectq/libs/revkit/_phase_test.py
projectq/libs/revkit/_utils.py
projectq/meta/__init__.py
projectq/meta/_compute.py
projectq/meta/_compute_test.py
projectq/meta/_control.py
projectq/meta/_control_test.py
projectq/meta/_dagger.py
projectq/meta/_dagger_test.py
projectq/meta/_dirtyqubit.py
projectq/meta/_dirtyqubit_test.py
projectq/meta/_logicalqubit.py
projectq/meta/_logicalqubit_test.py
projectq/meta/_loop.py
projectq/meta/_loop_test.py
projectq/meta/_util.py
projectq/meta/_util_test.py
projectq/ops/__init__.py
projectq/ops/_basics.py
projectq/ops/_basics_test.py
projectq/ops/_command.py
projectq/ops/_command_test.py
projectq/ops/_gates.py
projectq/ops/_gates_test.py
projectq/ops/_metagates.py
projectq/ops/_metagates_test.py
projectq/ops/_qaagate.py
projectq/ops/_qaagate_test.py
projectq/ops/_qftgate.py
projectq/ops/_qftgate_test.py
projectq/ops/_qpegate.py
projectq/ops/_qpegate_test.py
projectq/ops/_qubit_operator.py
projectq/ops/_qubit_operator_test.py
projectq/ops/_shortcuts.py
projectq/ops/_shortcuts_test.py
projectq/ops/_state_prep.py
projectq/ops/_state_prep_test.py
projectq/ops/_time_evolution.py
projectq/ops/_time_evolution_test.py
projectq/ops/_uniformly_controlled_rotation.py
projectq/ops/_uniformly_controlled_rotation_test.py
projectq/setups/__init__.py
projectq/setups/default.py
projectq/setups/grid.py
projectq/setups/grid_test.py
projectq/setups/ibm.py
projectq/setups/ibm16.py
projectq/setups/ibm16_test.py
projectq/setups/ibm_test.py
projectq/setups/linear.py
projectq/setups/linear_test.py
projectq/setups/restrictedgateset.py
projectq/setups/restrictedgateset_test.py
projectq/setups/decompositions/__init__.py
projectq/setups/decompositions/_gates_test.py
projectq/setups/decompositions/amplitudeamplification.py
projectq/setups/decompositions/amplitudeamplification_test.py
projectq/setups/decompositions/arb1qubit2rzandry.py
projectq/setups/decompositions/arb1qubit2rzandry_test.py
projectq/setups/decompositions/barrier.py
projectq/setups/decompositions/barrier_test.py
projectq/setups/decompositions/carb1qubit2cnotrzandry.py
projectq/setups/decompositions/carb1qubit2cnotrzandry_test.py
projectq/setups/decompositions/cnot2cz.py
projectq/setups/decompositions/cnot2cz_test.py
projectq/setups/decompositions/cnu2toffoliandcu.py
projectq/setups/decompositions/cnu2toffoliandcu_test.py
projectq/setups/decompositions/crz2cxandrz.py
projectq/setups/decompositions/entangle.py
projectq/setups/decompositions/globalphase.py
projectq/setups/decompositions/ph2r.py
projectq/setups/decompositions/phaseestimation.py
projectq/setups/decompositions/phaseestimation_test.py
projectq/setups/decompositions/qft2crandhadamard.py
projectq/setups/decompositions/qubitop2onequbit.py
projectq/setups/decompositions/qubitop2onequbit_test.py
projectq/setups/decompositions/r2rzandph.py
projectq/setups/decompositions/rx2rz.py
projectq/setups/decompositions/rx2rz_test.py
projectq/setups/decompositions/ry2rz.py
projectq/setups/decompositions/ry2rz_test.py
projectq/setups/decompositions/sqrtswap2cnot.py
projectq/setups/decompositions/sqrtswap2cnot_test.py
projectq/setups/decompositions/stateprep2cnot.py
projectq/setups/decompositions/stateprep2cnot_test.py
projectq/setups/decompositions/swap2cnot.py
projectq/setups/decompositions/time_evolution.py
projectq/setups/decompositions/time_evolution_test.py
projectq/setups/decompositions/toffoli2cnotandtgate.py
projectq/setups/decompositions/uniformlycontrolledr2cnot.py
projectq/setups/decompositions/uniformlycontrolledr2cnot_test.py
projectq/tests/__init__.py
projectq/tests/_factoring_test.py
projectq/types/__init__.py
projectq/types/_qubit.py
projectq/types/_qubit_test.py
1 change: 1 addition & 0 deletions projectq.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions projectq.egg-info/not-zip-safe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 3bb8a2c

Please sign in to comment.