-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QuantumComputer method to run TomographyExperiments (#1100)
- Loading branch information
Showing
22 changed files
with
1,254 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Experiment | ||
========== | ||
|
||
The ``experiment`` module offers a schema and utilities for succinctly expressing commonly | ||
used applications and algorithms in near-term quantum programming. A ``TomographyExperiment`` | ||
is intended to be consumed by the ``QuantumComputer.experiment`` method. | ||
|
||
**NOTE**: When working with the `experiment` method, the following declared memory labels are | ||
reserved: | ||
|
||
- "preparation_alpha", "preparation_beta", and "preparation_gamma" | ||
- "measurement_alpha", "measurement_beta", and "measurement_gamma" | ||
- "symmetrization" | ||
- "ro" | ||
|
||
.. currentmodule:: pyquil.experiment | ||
|
||
Schema | ||
------ | ||
|
||
.. autoclass:: pyquil.experiment.TomographyExperiment | ||
|
||
.. rubric:: Methods | ||
|
||
.. autosummary:: | ||
:toctree: autogen | ||
:template: autosumm.rst | ||
|
||
~TomographyExperiment.get_meas_qubits | ||
~TomographyExperiment.get_meas_registers | ||
~TomographyExperiment.generate_experiment_program | ||
~TomographyExperiment.build_setting_memory_map | ||
~TomographyExperiment.build_symmetrization_memory_maps | ||
|
||
.. autoclass:: SymmetrizationLevel | ||
|
||
.. autoclass:: pyquil.experiment.ExperimentSetting | ||
|
||
.. autoclass:: pyquil.experiment.ExperimentResult | ||
|
||
Utilities | ||
--------- | ||
|
||
.. autofunction:: pyquil.experiment.bitstrings_to_expectations | ||
.. autofunction:: pyquil.experiment.merge_memory_map_lists | ||
.. autofunction:: pyquil.experiment.read_json | ||
.. autofunction:: pyquil.experiment.to_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import networkx as nx | ||
import numpy as np | ||
|
||
from pyquil import Program | ||
from pyquil.api import QVM, QuantumComputer | ||
from pyquil.device import NxDevice | ||
from pyquil.experiment import ExperimentSetting, TomographyExperiment | ||
from pyquil.gates import CNOT, H, RESET | ||
from pyquil.paulis import sX, sY, sZ | ||
from pyquil.tests.utils import DummyCompiler | ||
|
||
|
||
def test_qc_expectation(forest): | ||
device = NxDevice(nx.complete_graph(2)) | ||
qc = QuantumComputer( | ||
name='testy!', | ||
qam=QVM(connection=forest), | ||
device=device, | ||
compiler=DummyCompiler() | ||
) | ||
|
||
# bell state program | ||
p = Program() | ||
p += RESET() | ||
p += H(0) | ||
p += CNOT(0, 1) | ||
p.wrap_in_numshots_loop(10) | ||
|
||
# XX, YY, ZZ experiment | ||
sx = ExperimentSetting(in_state=sZ(0) * sZ(1), out_operator=sX(0) * sX(1)) | ||
sy = ExperimentSetting(in_state=sZ(0) * sZ(1), out_operator=sY(0) * sY(1)) | ||
sz = ExperimentSetting(in_state=sZ(0) * sZ(1), out_operator=sZ(0) * sZ(1)) | ||
|
||
e = TomographyExperiment(settings=[sx, sy, sz], program=p) | ||
|
||
results = qc.experiment(e) | ||
|
||
# XX expectation value for bell state |00> + |11> is 1 | ||
assert np.isclose(results[0].expectation, 1) | ||
assert np.isclose(results[0].std_err, 0) | ||
assert results[0].total_counts == 40 | ||
|
||
# YY expectation value for bell state |00> + |11> is -1 | ||
assert np.isclose(results[1].expectation, -1) | ||
assert np.isclose(results[1].std_err, 0) | ||
assert results[1].total_counts == 40 | ||
|
||
# ZZ expectation value for bell state |00> + |11> is 1 | ||
assert np.isclose(results[2].expectation, 1) | ||
assert np.isclose(results[2].std_err, 0) | ||
assert results[2].total_counts == 40 | ||
|
||
|
||
def test_qc_expectation_larger_lattice(forest): | ||
device = NxDevice(nx.complete_graph(4)) | ||
qc = QuantumComputer( | ||
name='testy!', | ||
qam=QVM(connection=forest), | ||
device=device, | ||
compiler=DummyCompiler() | ||
) | ||
|
||
q0 = 2 | ||
q1 = 3 | ||
|
||
# bell state program | ||
p = Program() | ||
p += RESET() | ||
p += H(q0) | ||
p += CNOT(q0, q1) | ||
p.wrap_in_numshots_loop(10) | ||
|
||
# XX, YY, ZZ experiment | ||
sx = ExperimentSetting(in_state=sZ(q0) * sZ(q1), out_operator=sX(q0) * sX(q1)) | ||
sy = ExperimentSetting(in_state=sZ(q0) * sZ(q1), out_operator=sY(q0) * sY(q1)) | ||
sz = ExperimentSetting(in_state=sZ(q0) * sZ(q1), out_operator=sZ(q0) * sZ(q1)) | ||
|
||
e = TomographyExperiment(settings=[sx, sy, sz], program=p) | ||
|
||
results = qc.experiment(e) | ||
|
||
# XX expectation value for bell state |00> + |11> is 1 | ||
assert np.isclose(results[0].expectation, 1) | ||
assert np.isclose(results[0].std_err, 0) | ||
assert results[0].total_counts == 40 | ||
|
||
# YY expectation value for bell state |00> + |11> is -1 | ||
assert np.isclose(results[1].expectation, -1) | ||
assert np.isclose(results[1].std_err, 0) | ||
assert results[1].total_counts == 40 | ||
|
||
# ZZ expectation value for bell state |00> + |11> is 1 | ||
assert np.isclose(results[2].expectation, 1) | ||
assert np.isclose(results[2].std_err, 0) | ||
assert results[2].total_counts == 40 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from pyquil.experiment._main import (OperatorEncoder, SymmetrizationLevel, TomographyExperiment, | ||
read_json, to_json) | ||
from pyquil.experiment._result import ExperimentResult | ||
from pyquil.experiment._main import OperatorEncoder, TomographyExperiment, read_json, to_json | ||
from pyquil.experiment._memory import merge_memory_map_lists | ||
from pyquil.experiment._result import ExperimentResult, bitstrings_to_expectations | ||
from pyquil.experiment._setting import (_OneQState, _pauli_to_product_state, ExperimentSetting, | ||
SIC0, SIC1, SIC2, SIC3, TensorProductState, minusX, minusY, | ||
minusZ, plusX, plusY, plusZ, zeros_state) | ||
from pyquil.experiment._symmetrization import SymmetrizationLevel |
Oops, something went wrong.