Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyQVM #552

Merged
merged 48 commits into from Jan 24, 2019
Merged

PyQVM #552

Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2bc7dfa
PyQVM
Oct 4, 2018
5816d41
Merge branch 'master' into pyqvm
Oct 10, 2018
7a1210e
Latest attempt at figuring out the best semantics for run_and_measure
Oct 11, 2018
cb99448
no print
Oct 11, 2018
3d4b8f3
Update QAM.run()
Oct 11, 2018
fde6481
Fix some tests
Oct 15, 2018
3c92f9f
Merge branch 'master' into pyqvm
Oct 15, 2018
7e64246
Merge branch 'fix-some-tests' into pyqvm
Oct 15, 2018
d06b4fb
Sample from density simulator
Oct 15, 2018
96a59a6
wip random kraus sampling
Oct 15, 2018
bcf4ba2
Merge branch 'qam-run-classical-addresses' into pyqvm
Oct 16, 2018
1142d6c
Merge branch 'run-and-measure' into pyqvm
Oct 16, 2018
1c73ab8
fixup new r_a_m
Oct 16, 2018
a1f4a93
Merge remote-tracking branch 'origin/master' into pyqvm
Oct 16, 2018
2eb7e38
reduce diff and make _all_bitstrings public
Oct 16, 2018
af5ff71
sample_bitstrings
Oct 16, 2018
6b483a4
remove noise stuff
Oct 16, 2018
cb307e6
Fix test
Oct 16, 2018
ddf7220
Merge remote-tracking branch 'origin/master' into pyqvm
Oct 19, 2018
f4fa266
Merge branch 'master' into pyqvm
Oct 29, 2018
e85caeb
Simpler, seperate run-and-measure
Oct 29, 2018
088036b
No SHARING
Oct 29, 2018
47dc68b
Merge remote-tracking branch 'origin/master' into pyqvm
Oct 31, 2018
ea88d5f
Merge remote-tracking branch 'origin/master' into pyqvm
Nov 19, 2018
4cddd7b
Merge remote-tracking branch 'origin/master' into pyqvm
Nov 28, 2018
e1a18d0
Spruce up docstrings
Nov 28, 2018
e0b1ea4
the -> an
Nov 28, 2018
c71f93a
Merge branch 'spruce-up-api-docs' into pyqvm
Nov 28, 2018
db50a04
doc params
Nov 28, 2018
5d96883
pyqvm
Nov 28, 2018
7a98162
Docs
Nov 28, 2018
8d90910
Make numpy_simulator usable standalone
Nov 28, 2018
218ea09
Update migration.ipynb to use pyqvm
Nov 28, 2018
624ceaa
Reference expectation
Nov 28, 2018
b632e5a
Tests and fix expectation
Nov 28, 2018
fddd178
Fix tests; fix noise apply to qubits
Nov 28, 2018
e98bd40
Style "fixes"
Nov 28, 2018
ebdf128
Merge remote-tracking branch 'origin/master' into pyqvm
Jan 2, 2019
18af6dc
Note about tensordot
Jan 3, 2019
7a39a3f
simplify sum
Jan 3, 2019
9708f47
return self for method chaining in accordance with interface
Jan 3, 2019
6cf2f26
simplify sum
Jan 3, 2019
5ad6b89
PyQVM to handle executables
Jan 9, 2019
92c9528
lifted_pauli lets you pick out qubits
Jan 10, 2019
161c0b9
Merge remote-tracking branch 'origin/master' into pyqvm
Jan 11, 2019
589aef8
Revert porting of migration guide
Jan 11, 2019
1924116
PyQVM supports defgate
Jan 21, 2019
561fd07
Fix test for change to lifted_pauli api
Jan 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/source/apidocs/qam.rst
Expand Up @@ -9,10 +9,11 @@ quantum/classical quil programs on either a Quantum Virtual Machine (QVM, a clas
or a Quantum Processor Unit (QPU, a real quantum device).


.. currentmodule:: pyquil.api
.. autosummary::
:toctree: autogen
:template: autosumm.rst

_qam.QAM
QPU
QVM
~pyquil.api._qam.QAM
~pyquil.api.QPU
~pyquil.api.QVM
~pyquil.pyqvm.PyQVM
43 changes: 43 additions & 0 deletions docs/source/apidocs/simulators.rst
@@ -0,0 +1,43 @@
Simulators
==========

QVMs promise to behave like a real QPU. However, under-the-hood there is usually a simulation
that has fewer constraints than a physical device. For example, in a wavefunction (or statevector)
simulation, you can directly inspect amplitudes and probabilities.


.. currentmodule:: pyquil
.. autosummary::
:toctree: autogen
:template: autosumm.rst

~pyquil.api.WavefunctionSimulator
~pyquil.reference_simulator.ReferenceWavefunctionSimulator
~pyquil.reference_simulator.ReferenceDensitySimulator
~pyquil.numpy_simulator.NumpyWavefunctionSimulator


Reference Utilities
-------------------

.. currentmodule:: pyquil.unitary_tools
.. autosummary::
:toctree: autogen
:template: autosumm.rst

lifted_pauli
lifted_gate
program_unitary
all_bitstrings


Numpy Utilities
---------------

.. currentmodule:: pyquil.numpy_simulator
.. autosummary::
:toctree: autogen
:template: autosumm.rst

targeted_einsum
targeted_tensordot
2 changes: 1 addition & 1 deletion docs/source/index.rst
Expand Up @@ -94,7 +94,7 @@ Contents
apidocs/compilers
apidocs/qam
apidocs/devices
apidocs/wavefunction
apidocs/simulators
apidocs/noise

.. toctree::
Expand Down
71 changes: 57 additions & 14 deletions docs/source/migration.ipynb
Expand Up @@ -91,7 +91,7 @@
"source": [
"#### The new way\n",
"\n",
"`WavefunctionSimulator` encapsulates all functionality that requires peering into a wavefunction. This also opens the door for different types of simulators other than those backed by a wavefunction. For example, you can simulate a quantum circuit with a density matrix simulation or a path integral simulation."
"PyQuil has a built-in numpy-based wavefunction simulator that is reasonably performant and easy to interact with."
]
},
{
Expand All @@ -103,14 +103,56 @@
"name": "stdout",
"output_type": "stream",
"text": [
"(0.7071067812+0j)|00> + (0.7071067812+0j)|11>\n"
"as a n_qubit-index tensor:\n",
" [[0.70710678+0.j 0. +0.j]\n",
" [0. +0.j 0.70710678+0.j]]\n",
"flattened:\n",
" [0.70710678+0.j 0. +0.j 0. +0.j 0.70710678+0.j]\n"
]
}
],
"source": [
"from pyquil.numpy_simulator import NumpyWavefunctionSimulator\n",
"sim = NumpyWavefunctionSimulator(n_qubits=2)\n",
"sim = sim.do_program(program)\n",
"print(\"as a n_qubit-index tensor:\\n\", sim.wf)\n",
"print(\"flattened:\\n\", sim.wf.reshape(-1))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The wavefunction is persisted across multiple calls to `do_program`. Consider calling `reset`"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Without resetting\n",
"[[0.70710678+0.j 0. +0.j]\n",
" [0. +0.j 0.70710678+0.j]]\n",
"With resetting\n",
"[[1.+0.j 0.+0.j]\n",
" [0.+0.j 0.+0.j]]\n"
]
}
],
"source": [
"from pyquil.api import WavefunctionSimulator\n",
"wfn = WavefunctionSimulator().wavefunction(program)\n",
"print(wfn)"
"sim.do_gate(I(0))\n",
"print(\"Without resetting\")\n",
"print(sim.wf)\n",
"\n",
"print(\"With resetting\")\n",
"sim.reset()\n",
"sim.do_gate(I(0))\n",
"print(sim.wf)"
]
},
{
Expand All @@ -126,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -157,7 +199,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -186,7 +228,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -210,14 +252,14 @@
"metadata": {},
"source": [
"#### The new way\n",
"If you want analytical expectation values, the solution is to use `WavefunctionSimulator.expectation`\n",
"If you want analytical expectation values, the solution is to use the `expectation` method on `NumpyWavefunctionSimulator`. In lieu of a `prep_program` argument, call `do_program` beforehand and your wavefunction will persist.\n",
"\n",
"Note that the method is not named `pauli_expectation` as we do not support the pyQuil<1.9 way of using `Program`s to represent `PauliSum`s"
"This should allow you to prepare a wavefunction once and measure multiple expectation values or measure expectation values in the middle of programs."
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -231,8 +273,9 @@
}
],
"source": [
"sim = NumpyWavefunctionSimulator(n_qubits=2).do_program(program)\n",
"for observable in [z0, z1, xor]:\n",
" expectation = WavefunctionSimulator().expectation(prep_prog=program, pauli_terms=observable)\n",
" expectation = sim.expectation(observable)\n",
" print(observable, '\\t', expectation)"
]
},
Expand Down Expand Up @@ -288,7 +331,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -308,7 +351,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand Down