Skip to content

Commit

Permalink
Update for pyQuil v3
Browse files Browse the repository at this point in the history
  • Loading branch information
ameyer-rigetti committed Aug 9, 2021
1 parent f9ad970 commit 7aaa3f5
Show file tree
Hide file tree
Showing 39 changed files with 199 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: python:3.6
image: python:3.7

services:
- name: rigetti/qvm
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
[v0.7.2](https://github.com/rigetti/forest-benchmarking/compare/v0.7.1...master) (in development)
------------------------------------------------------------------------------------

### Announcements

- Upgraded pyQuil to v3 (gh-215). As a result, the minimum supported Python version is now 3.7.

### Bugfixes

- Fix compiler timeout during test (@jlapeyre) (gh-208)
Expand Down
22 changes: 9 additions & 13 deletions docs/examples/chip_scan.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"import numpy as np\n",
"from numpy import pi\n",
"from pyquil.api import get_qc\n",
"from pyquil.api._devices import get_lattice\n",
"from pyquil import Program\n",
"from pyquil.gates import *\n",
"\n",
Expand All @@ -38,11 +37,8 @@
"metadata": {},
"outputs": [],
"source": [
"# lattice_name = 'Aspen-1-5Q-B'\n",
"lattice_name = '9q-square-noisy-qvm'\n",
"# lattice = get_lattice(lattice_name)\n",
"# stored_specs = lattice.get_specs()\n",
"# print(stored_specs)"
"# quantum_processor_id = 'Aspen-1-5Q-B'\n",
"quantum_processor_id = '9q-square-noisy-qvm'"
]
},
{
Expand Down Expand Up @@ -97,7 +93,7 @@
"source": [
"import networkx as nx\n",
"\n",
"qc = get_qc(lattice_name, as_qvm=True, noisy=True)\n",
"qc = get_qc(quantum_processor_id, as_qvm=True, noisy=True)\n",
"qubits = qc.qubits()\n",
"print(qubits)\n",
"graph = qc.qubit_topology()\n",
Expand Down Expand Up @@ -228,7 +224,7 @@
"source": [
"print('Single qubit confusion matrices: \\n', single_qubit_cms)\n",
"print('Avg. fidelity per qubit: ', [np.round(np.trace(cm)/2, 3) for cm in single_qubit_cms.values()])\n",
"from pyquil.gate_matrices import Z as Z_mat\n",
"from pyquil.simulation.matrices import Z as Z_mat\n",
"print('Asymmetry magnitude: ', [np.round(np.trace(Z_mat @ cm)/2, 3) for cm in single_qubit_cms.values()])"
]
},
Expand Down Expand Up @@ -391,9 +387,9 @@
"metadata": {},
"outputs": [],
"source": [
"from pyquil.api import get_benchmarker\n",
"from pyquil.api import BenchmarkConnection\n",
"from forest.benchmarking.randomized_benchmarking import do_rb\n",
"bm = get_benchmarker()"
"bm = BenchmarkConnection()"
]
},
{
Expand Down Expand Up @@ -842,8 +838,8 @@
"source": [
"from forest.benchmarking.direct_fidelity_estimation import do_dfe\n",
"\n",
"from pyquil.api import get_benchmarker\n",
"bm = get_benchmarker()\n",
"from pyquil.api import BenchmarkConnection\n",
"bm = BenchmarkConnection()\n",
"\n",
"cz_fidelities = {}\n",
"for edge in graph.edges():\n",
Expand Down Expand Up @@ -1032,4 +1028,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
8 changes: 4 additions & 4 deletions docs/examples/direct_fidelity_estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"from pyquil.paulis import ID\n",
"from pyquil.gates import I, X, MEASURE, H, CNOT, RY, CZ\n",
"from pyquil import Program, get_qc\n",
"from pyquil.api import get_benchmarker\n",
"from pyquil.api import BenchmarkConnection\n",
"from forest.benchmarking.direct_fidelity_estimation import ( generate_exhaustive_state_dfe_experiment, \n",
" generate_exhaustive_process_dfe_experiment,\n",
" generate_monte_carlo_state_dfe_experiment, \n",
Expand All @@ -178,7 +178,7 @@
"# noisy QVM\n",
"noisy_qvm = get_qc(\"9q-generic-qvm\", as_qvm=True, noisy=True)\n",
"\n",
"bm = get_benchmarker()"
"bm = BenchmarkConnection()"
]
},
{
Expand Down Expand Up @@ -275,7 +275,7 @@
}
],
"source": [
"from pyquil.gate_matrices import I as Imatrix, H as Hmatrix, CNOT as CNOTmatrix\n",
"from pyquil.simulation.matrices import I as Imatrix, H as Hmatrix, CNOT as CNOTmatrix\n",
"\n",
"U_ideal = CNOTmatrix @ np.kron(Hmatrix, Imatrix)\n",
"print(U_ideal)\n",
Expand Down Expand Up @@ -1491,4 +1491,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
11 changes: 5 additions & 6 deletions docs/examples/entangled_states.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@
" program.wrap_in_numshots_loop(n_shots)\n",
" executable = qc.compile(program)\n",
"\n",
" qc.qam.load(executable)\n",
" for theta in np.linspace(-np.pi, np.pi, 21):\n",
" qc.qam.write_memory(region_name='theta', value=theta)\n",
" bitstrings = qc.qam.run().wait().read_from_memory_region(region_name='ro')\n",
" executable.write_memory(region_name='theta', value=theta)\n",
" bitstrings = qc.qam.run(executable).readout_data.get('ro')\n",
" parities = np.sum(bitstrings, axis=1) % 2\n",
" avg_parity = np.mean(parities)\n",
" results.append({\n",
Expand Down Expand Up @@ -438,7 +437,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pyquil.api import get_benchmarker\n",
"from pyquil.api import BenchmarkConnection\n",
"from forest.benchmarking.direct_fidelity_estimation import ( generate_exhaustive_state_dfe_experiment, \n",
" acquire_dfe_data,\n",
" estimate_dfe )"
Expand All @@ -450,7 +449,7 @@
"metadata": {},
"outputs": [],
"source": [
"bm = get_benchmarker()"
"bm = BenchmarkConnection()"
]
},
{
Expand Down Expand Up @@ -530,4 +529,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
1 change: 1 addition & 0 deletions docs/examples/graph-state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"focal_node":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":1,"12":1,"13":1,"14":1,"15":1,"16":1,"17":1,"18":1,"19":1,"20":1,"21":2,"22":2,"23":2,"24":2,"25":2,"26":2,"27":2,"28":2,"29":2,"30":2,"31":2,"32":2,"33":2,"34":2,"35":2,"36":2,"37":2,"38":2,"39":2,"40":2,"41":2,"42":3,"43":3,"44":3,"45":3,"46":3,"47":3,"48":3,"49":3,"50":3,"51":3,"52":3,"53":3,"54":3,"55":3,"56":3,"57":3,"58":3,"59":3,"60":3,"61":3,"62":3},"theta":{"0":-3.1415926536,"1":-2.8274333882,"2":-2.5132741229,"3":-2.1991148575,"4":-1.8849555922,"5":-1.5707963268,"6":-1.2566370614,"7":-0.9424777961,"8":-0.6283185307,"9":-0.3141592654,"10":0.0,"11":0.3141592654,"12":0.6283185307,"13":0.9424777961,"14":1.2566370614,"15":1.5707963268,"16":1.8849555922,"17":2.1991148575,"18":2.5132741229,"19":2.8274333882,"20":3.1415926536,"21":-3.1415926536,"22":-2.8274333882,"23":-2.5132741229,"24":-2.1991148575,"25":-1.8849555922,"26":-1.5707963268,"27":-1.2566370614,"28":-0.9424777961,"29":-0.6283185307,"30":-0.3141592654,"31":0.0,"32":0.3141592654,"33":0.6283185307,"34":0.9424777961,"35":1.2566370614,"36":1.5707963268,"37":1.8849555922,"38":2.1991148575,"39":2.5132741229,"40":2.8274333882,"41":3.1415926536,"42":-3.1415926536,"43":-2.8274333882,"44":-2.5132741229,"45":-2.1991148575,"46":-1.8849555922,"47":-1.5707963268,"48":-1.2566370614,"49":-0.9424777961,"50":-0.6283185307,"51":-0.3141592654,"52":0.0,"53":0.3141592654,"54":0.6283185307,"55":0.9424777961,"56":1.2566370614,"57":1.5707963268,"58":1.8849555922,"59":2.1991148575,"60":2.5132741229,"61":2.8274333882,"62":3.1415926536},"n_bitstrings":{"0":1000,"1":1000,"2":1000,"3":1000,"4":1000,"5":1000,"6":1000,"7":1000,"8":1000,"9":1000,"10":1000,"11":1000,"12":1000,"13":1000,"14":1000,"15":1000,"16":1000,"17":1000,"18":1000,"19":1000,"20":1000,"21":1000,"22":1000,"23":1000,"24":1000,"25":1000,"26":1000,"27":1000,"28":1000,"29":1000,"30":1000,"31":1000,"32":1000,"33":1000,"34":1000,"35":1000,"36":1000,"37":1000,"38":1000,"39":1000,"40":1000,"41":1000,"42":1000,"43":1000,"44":1000,"45":1000,"46":1000,"47":1000,"48":1000,"49":1000,"50":1000,"51":1000,"52":1000,"53":1000,"54":1000,"55":1000,"56":1000,"57":1000,"58":1000,"59":1000,"60":1000,"61":1000,"62":1000},"avg_parity":{"0":0.531,"1":0.34,"2":0.212,"3":0.097,"4":0.032,"5":0.0,"6":0.015,"7":0.098,"8":0.217,"9":0.352,"10":0.523,"11":0.644,"12":0.795,"13":0.904,"14":0.976,"15":1.0,"16":0.973,"17":0.896,"18":0.809,"19":0.655,"20":0.48,"21":0.469,"22":0.314,"23":0.185,"24":0.097,"25":0.032,"26":0.0,"27":0.035,"28":0.106,"29":0.22,"30":0.354,"31":0.492,"32":0.658,"33":0.796,"34":0.893,"35":0.976,"36":1.0,"37":0.969,"38":0.889,"39":0.784,"40":0.679,"41":0.491,"42":0.507,"43":0.336,"44":0.203,"45":0.082,"46":0.036,"47":0.0,"48":0.024,"49":0.105,"50":0.204,"51":0.341,"52":0.479,"53":0.634,"54":0.78,"55":0.906,"56":0.969,"57":1.0,"58":0.973,"59":0.904,"60":0.797,"61":0.653,"62":0.491}}
2 changes: 1 addition & 1 deletion docs/examples/hinton_plots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"from pyquil.gate_matrices import X, Y, Z\n",
"from pyquil.simulation.matrices import X, Y, Z\n",
"PROJ_ZERO = np.array([[1, 0], [0, 0]])\n",
"PROJ_ONE = np.array([[0, 0], [0, 1]])\n",
"ID = PROJ_ZERO + PROJ_ONE\n",
Expand Down
5 changes: 3 additions & 2 deletions docs/examples/quantum_volume.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,9 @@
"metadata": {},
"outputs": [],
"source": [
"from pyquil import Program\n",
"from forest.benchmarking.quantum_volume import generate_abstract_qv_circuit, _naive_program_generator, collect_heavy_outputs\n",
"from pyquil.numpy_simulator import NumpyWavefunctionSimulator\n",
"from pyquil.simulation import NumpyWavefunctionSimulator\n",
"from pyquil.gates import RESET\n",
"import time\n",
"\n",
Expand Down Expand Up @@ -739,4 +740,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
6 changes: 3 additions & 3 deletions docs/examples/qubit_spectroscopy_cz_ramsey.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
"metadata": {},
"outputs": [],
"source": [
"# if you are on the QPU you can look at `qc.device.specs`\n",
"# qc.device.specs"
"# if you are on the QPU you can look at the ISA\n",
"# qc.quantum_processor.to_compiler_isa()"
]
},
{
Expand Down Expand Up @@ -202,4 +202,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
7 changes: 3 additions & 4 deletions docs/examples/randomized_benchmarking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
"\n",
"import numpy as np\n",
"\n",
"from pyquil.api import get_benchmarker\n",
"from forest.benchmarking.randomized_benchmarking import (generate_rb_sequence,\n",
" generate_rb_experiments, acquire_rb_data,\n",
" get_stats_by_qubit_group, fit_rb_results)\n",
Expand All @@ -156,9 +155,9 @@
"metadata": {},
"outputs": [],
"source": [
"from pyquil.api import get_qc, get_benchmarker\n",
"from pyquil.api import get_qc, BenchmarkConnection\n",
"qc = get_qc(\"9q-square-noisy-qvm\")\n",
"bm = get_benchmarker()"
"bm = BenchmarkConnection()"
]
},
{
Expand Down Expand Up @@ -671,4 +670,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
6 changes: 3 additions & 3 deletions docs/examples/randomized_benchmarking_interleaved.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"\n",
"import numpy as np\n",
"\n",
"from pyquil.api import get_benchmarker, get_qc\n",
"from pyquil.api import BenchmarkConnection, get_qc\n",
"from forest.benchmarking.randomized_benchmarking import *\n",
"from forest.benchmarking.plotting import plot_figure_for_fit\n",
"\n",
Expand All @@ -80,7 +80,7 @@
"metadata": {},
"outputs": [],
"source": [
"bm = get_benchmarker()\n",
"bm = BenchmarkConnection()\n",
"qc = get_qc(\"9q-square-noisy-qvm\", noisy=True)"
]
},
Expand Down Expand Up @@ -422,4 +422,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
6 changes: 3 additions & 3 deletions docs/examples/randomized_benchmarking_unitarity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@
"from forest.benchmarking.plotting import plot_figure_for_fit\n",
"from forest.benchmarking.randomized_benchmarking import *\n",
"\n",
"from pyquil.api import get_benchmarker\n",
"from pyquil.api import BenchmarkConnection\n",
"from pyquil import Program, get_qc\n",
"\n",
"noisy_qc = get_qc('2q-qvm', noisy=True)\n",
"bm = get_benchmarker()"
"bm = BenchmarkConnection()"
]
},
{
Expand Down Expand Up @@ -357,4 +357,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
12 changes: 6 additions & 6 deletions docs/examples/robust_phase_estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@
"source": [
"from pyquil import Program\n",
"from pyquil.quil import DefGate, Gate\n",
"from pyquil.gate_matrices import X as x_mat, Y as y_mat, Z as z_mat\n",
"from pyquil.simulation.matrices import X as x_mat, Y as y_mat, Z as z_mat\n",
"\"\"\"\n",
"Procedure and notation follows Sections III A, B, and C in \n",
"[RPE] Robust Calibration of a Universal Single-Qubit Gate-Set via Robust Phase Estimation\n",
Expand Down Expand Up @@ -661,12 +661,12 @@
}
],
"source": [
"from pyquil.device import gates_in_isa\n",
"from pyquil.noise import decoherence_noise_with_asymmetric_ro, _decoherence_noise_model\n",
"# noise_model = decoherence_noise_with_asymmetric_ro(gates=gates_in_isa(qc.device.get_isa()), p00=0.92, p11=.87)\n",
"from pyquil.noise import decoherence_noise_with_asymmetric_ro, _decoherence_noise_model, _get_qvm_noise_supported_gates\n",
"# noise_model = decoherence_noise_with_asymmetric_ro(qc.device.get_isa(), p00=0.92, p11=.87)\n",
"T1=20e-6\n",
"T2=10e-6\n",
"noise_model = _decoherence_noise_model(gates=gates_in_isa(qc.device.get_isa()), T1=T1, T2=T2, ro_fidelity=1.)\n",
"gates = _get_qvm_noise_supported_gates(qc.device.to_compiler_isa())\n",
"noise_model = _decoherence_noise_model(gates=gates, T1=T1, T2=T2, ro_fidelity=1.)\n",
"\n",
"qc = get_qc(\"9q-square\", as_qvm=True, noisy=False)\n",
"qc.qam.noise_model = noise_model\n",
Expand Down Expand Up @@ -705,4 +705,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
2 changes: 1 addition & 1 deletion docs/examples/state_and_process_plots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"from matplotlib import pyplot as plt\n",
"\n",
"# quantum related things\n",
"from pyquil.gate_matrices import X, Y, Z, H, CNOT, CZ\n",
"from pyquil.simulation.matrices import X, Y, Z, H, CNOT, CZ\n",
"from forest.benchmarking.operator_tools.superoperator_transformations import *\n",
"from forest.benchmarking.utils import n_qubit_pauli_basis\n"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/superoperator_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"from pyquil.gate_matrices import I, X, Y, Z, H, CNOT"
"from pyquil.simulation.matrices import I, X, Y, Z, H, CNOT"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/tomography_process.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
"source": [
"# numerical representation of the true process\n",
"\n",
"from pyquil.gate_matrices import RX as RX_matrix\n",
"from pyquil.simulation.matrices import RX as RX_matrix\n",
"from forest.benchmarking.operator_tools import kraus2choi\n",
"\n",
"kraus_true = RX_matrix(np.pi)\n",
Expand All @@ -264,7 +264,7 @@
"choi_true = kraus2choi(kraus_true)\n",
"print('The Choi representation is:\\n', np.real_if_close(np.round(choi_true, 2)))\n",
"\n",
"from pyquil.gate_matrices import X as X_matrix\n",
"from pyquil.simulation.matrices import X as X_matrix\n",
"choi_x_gate = kraus2choi(X_matrix)\n",
"print('\\n The X gate choi matrix is:\\n', np.real_if_close(np.round(choi_x_gate)))"
]
Expand Down Expand Up @@ -761,7 +761,7 @@
}
],
"source": [
"from pyquil.gate_matrices import CNOT as CNOT_matrix\n",
"from pyquil.simulation.matrices import CNOT as CNOT_matrix\n",
"process_choi_ideal = kraus2choi(CNOT_matrix)\n",
"_print_big_matrix(process_choi_ideal)"
]
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/tomography_state.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@
"outputs": [],
"source": [
"from pyquil.pyqvm import PyQVM\n",
"from pyquil.reference_simulator import ReferenceDensitySimulator\n",
"from pyquil.simulation import ReferenceDensitySimulator\n",
"mixed_qvm = get_qc('1q-pyqvm')\n",
"# replace the simulator with a ReferenceDensitySimulator for mixed states\n",
"mixed_qvm.qam.wf_simulator = ReferenceDensitySimulator(n_qubits=1, rs=mixed_qvm.qam.rs)"
Expand Down Expand Up @@ -1209,4 +1209,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Loading

0 comments on commit 7aaa3f5

Please sign in to comment.