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 12, 2021
1 parent f9ad970 commit 8f160bb
Show file tree
Hide file tree
Showing 44 changed files with 249 additions and 292 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Test (Python ${{ matrix.python-version }})
run: |
docker run --rm -itd -p 5555:5555 rigetti/quilc -S
docker run --rm -itd -p 5000:5000 rigetti/qvm -S
apt update -y && apt install -y libblas-dev liblapack-dev
pip install -r requirements.txt && pip install -e .
MPLBACKEND=Agg pytest
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ venv.bak/
.mypy_cache/

.idea/

docs/examples/graph-state.json
20 changes: 0 additions & 20 deletions .gitlab-ci.yml

This file was deleted.

6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Changelog
=========

[v0.7.2](https://github.com/rigetti/forest-benchmarking/compare/v0.7.1...master) (in development)
[v0.8.0](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
}
}
12 changes: 6 additions & 6 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 @@ -173,12 +173,12 @@
"outputs": [],
"source": [
"# noiseless QVM\n",
"qvm = get_qc(\"9q-generic-qvm\", as_qvm=True, noisy=False)\n",
"qvm = get_qc(\"9q-square-qvm\", noisy=False)\n",
"\n",
"# noisy QVM\n",
"noisy_qvm = get_qc(\"9q-generic-qvm\", as_qvm=True, noisy=True)\n",
"noisy_qvm = get_qc(\"9q-square-qvm\", 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
}
}
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
19 changes: 15 additions & 4 deletions docs/examples/quantum_volume.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,17 @@
"outputs": [],
"source": [
"from pyquil.api._quantum_computer import _get_qvm_with_topology\n",
"path_qc = _get_qvm_with_topology(name='path', topology=path_graph, noisy=True)"
"from pyquil.api import QCSClientConfiguration\n",
"\n",
"path_qc = _get_qvm_with_topology(\n",
" name='path',\n",
" topology=path_graph,\n",
" noisy=True,\n",
" client_configuration=QCSClientConfiguration.load(),\n",
" qvm_type=\"qvm\",\n",
" compiler_timeout=10.0,\n",
" execution_timeout=10.0,\n",
")"
]
},
{
Expand Down Expand Up @@ -433,8 +443,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 @@ -464,7 +475,7 @@
" program.wrap_in_numshots_loop(num_shots)\n",
" executable = qc.compiler.native_quil_to_executable(program)\n",
"\n",
" results = qc.run(executable)\n",
" results = qc.run(executable).readout_data.get('ro')\n",
"\n",
" runtime = time.time() - start\n",
" yield results\n",
Expand Down Expand Up @@ -739,4 +750,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
}
}
8 changes: 4 additions & 4 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,8 +80,8 @@
"metadata": {},
"outputs": [],
"source": [
"bm = get_benchmarker()\n",
"qc = get_qc(\"9q-square-noisy-qvm\", noisy=True)"
"bm = BenchmarkConnection()\n",
"qc = get_qc(\"9q-square-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
}
}
4 changes: 2 additions & 2 deletions docs/examples/ripple_adder_benchmark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"outputs": [],
"source": [
"# noiseless QVM\n",
"qc = get_qc(\"9q-generic\", as_qvm=True, noisy=False)\n",
"qc = get_qc(\"9q-square-qvm\", noisy=False)\n",
"\n",
"# noisy QVM\n",
"noisy_qc = get_qc(\"9q-generic-noisy-qvm\", as_qvm=True, noisy=True)"
"noisy_qc = get_qc(\"9q-square-qvm\", noisy=True)"
]
},
{
Expand Down
Loading

0 comments on commit 8f160bb

Please sign in to comment.