From b99940b2b6a5e0231d7fde19c7bf136f51a3c056 Mon Sep 17 00:00:00 2001 From: nivedha1 Date: Sun, 18 Aug 2024 15:30:57 -0500 Subject: [PATCH 1/4] Validations added for noise props gates and qubits #6607 --- .../engine/calibration_to_noise_properties.py | 37 ++++++++- .../calibration_to_noise_properties_test.py | 31 +++++++- docs/hardware/qubit_picking.ipynb | 34 ++++++--- docs/simulate/noisy_simulation.ipynb | 41 ++++++---- docs/simulate/quantum_virtual_machine.ipynb | 61 +++++++++++---- docs/simulate/qvm_basic_example.ipynb | 76 ++++++++++++++++--- 6 files changed, 222 insertions(+), 58 deletions(-) diff --git a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py index 316fa2070a8..8ea1364f329 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py @@ -20,7 +20,10 @@ >>> cal = cirq_google.engine.load_median_device_calibration("rainbow") >>> noise_props = cirq_google.engine.noise_properties_from_calibration(cal) - >>> noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props) + >>> q0, q1 = cirq.q(4, 1), cirq.q(4, 2) + >>> circuit = cirq.Circuit(cirq.CX.on(q0, q1)) + >>> compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) + >>> noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props, compiled_circuit) >>> simulator = cirq.Simulator(noise=noise_model) >>> circuit = cirq.Circuit(cirq.X(cirq.GridQubit(5, 2))) >>> result = simulator.simulate(circuit) @@ -34,6 +37,7 @@ from cirq_google import ops as cg_ops from cirq_google.devices import google_noise_properties from cirq_google.engine import util +from cirq.circuits import circuit if TYPE_CHECKING: import cirq @@ -88,6 +92,7 @@ def _unpack_2q_from_calibration( def noise_properties_from_calibration( calibration: engine.Calibration, + cir: circuit.Circuit = None, zphase_data: Optional[util.ZPhaseDataType] = None, gate_times_ns: Optional[Dict[Type['cirq.Gate'], float]] = None, ) -> google_noise_properties.GoogleNoiseProperties: @@ -100,8 +105,10 @@ def noise_properties_from_calibration( To manually override noise properties, call `with_params` on the output: >>> cal = cirq_google.engine.load_median_device_calibration("rainbow") - >>> # noise_props with all gate durations set to 37ns. - >>> noise_props = cirq_google.engine.noise_properties_from_calibration(cal).with_params( + >>> q0, q1 = cirq.q(4, 1), cirq.q(4, 2) + >>> circuit = cirq.Circuit(cirq.CX.on(q0, q1)) + >>> compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) + >>> noise_props = cirq_google.engine.noise_properties_from_calibration(cal, compiled_circuit).with_params( ... gate_times_ns=37) See `cirq_google.GoogleNoiseProperties` for details. @@ -203,7 +210,7 @@ def noise_properties_from_calibration( fsim_errors[op_id_reverse] = error_gate # Known false positive: https://github.com/PyCQA/pylint/issues/5857 - return google_noise_properties.GoogleNoiseProperties( # pylint: disable=unexpected-keyword-arg + noise_props = google_noise_properties.GoogleNoiseProperties( # pylint: disable=unexpected-keyword-arg gate_times_ns=gate_times_ns, t1_ns=t1_ns, tphi_ns=tphi_ns, @@ -211,3 +218,25 @@ def noise_properties_from_calibration( gate_pauli_errors=gate_pauli_errors, fsim_errors=fsim_errors, ) + if cir is not None: + for qubit in cir.all_qubits(): + if qubit not in noise_props.qubits: + raise ValueError(f"Qubit {qubit} is not part of the system qubits.") + known_gates = [] + unknown_gates = [] + for gates in cir.all_operations(): + if not isinstance(gates.gate, ops.PhasedXZGate): + known_gates.append(gates.gate) + for gates in known_gates: + found = False + for ex_gate in noise_props.expected_gates(): + if isinstance(gates, ex_gate): + found = True + break + if not found: + unknown_gates.append(gates) + + if len(unknown_gates) != 0: + raise ValueError(f"these {unknown_gates} does not correspond to compiled target gateset." + f"Please compile circuit with corresponding target gateset") + return noise_props; \ No newline at end of file diff --git a/cirq-google/cirq_google/engine/calibration_to_noise_properties_test.py b/cirq-google/cirq_google/engine/calibration_to_noise_properties_test.py index 3d7eb1ed73d..efb46e4ba49 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties_test.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties_test.py @@ -234,7 +234,13 @@ def test_noise_properties_from_calibration(): syc_angles, iswap_angles, ) - prop = cirq_google.noise_properties_from_calibration(calibration) + circuit = cirq.Circuit( + cirq.H(qubits[0]), + cirq.H(qubits[1]), + cirq.H(qubits[2]), + ) + compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) + prop = cirq_google.noise_properties_from_calibration(calibration, compiled_circuit) for i, q in enumerate(qubits): assert np.isclose( @@ -313,8 +319,14 @@ def test_zphase_data(): "gamma": {qubit_pairs[0]: iswap_angles[0].gamma, qubit_pairs[1]: iswap_angles[1].gamma}, }, } + circuit = cirq.Circuit( + cirq.H(qubits[0]), + cirq.H(qubits[1]), + cirq.H(qubits[2]), + ) + compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) - prop = cirq_google.noise_properties_from_calibration(calibration, zphase_data) + prop = cirq_google.noise_properties_from_calibration(calibration, compiled_circuit, zphase_data) for i, qs in enumerate(qubit_pairs): for gate, values in [ (cirq_google.SycamoreGate, syc_angles), @@ -411,8 +423,21 @@ def test_incomplete_calibration(): """, cirq_google.api.v2.metrics_pb2.MetricsSnapshot(), ) + q0, q1 = cirq.q(4, 1), cirq.q(4, 2) + circuit = cirq.Circuit(cirq.CX.on(q0, q1)) + compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) # Create NoiseProperties object from Calibration calibration = cirq_google.Calibration(_CALIBRATION_DATA) with pytest.raises(ValueError, match='Keys specified for T1 and Tphi are not identical.'): - _ = cirq_google.noise_properties_from_calibration(calibration) + _ = cirq_google.noise_properties_from_calibration(calibration,compiled_circuit) + +def test_validate_gateset(): + + # Add various gates to the circuit + processor_id = "rainbow" + q0, q1 = cirq.q(4, 1), cirq.q(4, 2) + cal = cirq_google.engine.load_median_device_calibration(processor_id) + circuit = cirq.Circuit(cirq.CX.on(q0, q1)) + compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) + cirq_google.noise_properties_from_calibration(cal, compiled_circuit) \ No newline at end of file diff --git a/docs/hardware/qubit_picking.ipynb b/docs/hardware/qubit_picking.ipynb index fb356dadfb2..a6fb834b510 100644 --- a/docs/hardware/qubit_picking.ipynb +++ b/docs/hardware/qubit_picking.ipynb @@ -73,12 +73,14 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { "cellView": "form", - "id": "pBl-1eHNHXS8" + "id": "pBl-1eHNHXS8", + "ExecuteTime": { + "end_time": "2024-08-18T20:02:10.158772Z", + "start_time": "2024-08-18T20:02:10.151880Z" + } }, - "outputs": [], "source": [ "# @title Setup\n", "try:\n", @@ -92,7 +94,9 @@ "import cirq_google\n", "import numpy as np\n", "from matplotlib import pyplot as plt" - ] + ], + "outputs": [], + "execution_count": 3 }, { "cell_type": "markdown", @@ -113,16 +117,23 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { - "id": "hKfu5yVi2Ebs" + "id": "hKfu5yVi2Ebs", + "ExecuteTime": { + "end_time": "2024-08-18T20:07:33.480846Z", + "start_time": "2024-08-18T20:07:33.356894Z" + } }, - "outputs": [], "source": [ + "q0, q1 = cirq.q(4, 1), cirq.q(4, 2)\n", + "circuit = cirq.Circuit(cirq.CX.on(q0, q1))\n", + "compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset())\n", "processor_id = \"rainbow\"\n", "cal = cirq_google.engine.load_median_device_calibration(processor_id)\n", - "noise_props = cirq_google.noise_properties_from_calibration(cal)" - ] + "noise_props = cirq_google.noise_properties_from_calibration(cal, compiled_circuit)" + ], + "outputs": [], + "execution_count": 5 }, { "cell_type": "markdown", @@ -346,8 +357,9 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3", - "name": "python3" + "display_name": "Python 3 (ipykernel)", + "name": "python3", + "language": "python" } }, "nbformat": 4, diff --git a/docs/simulate/noisy_simulation.ipynb b/docs/simulate/noisy_simulation.ipynb index ba27b94c9b2..936aeee1ee3 100644 --- a/docs/simulate/noisy_simulation.ipynb +++ b/docs/simulate/noisy_simulation.ipynb @@ -64,11 +64,13 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { - "id": "846b32703c5c" + "id": "846b32703c5c", + "ExecuteTime": { + "end_time": "2024-08-18T20:07:12.950299Z", + "start_time": "2024-08-18T20:07:12.941938Z" + } }, - "outputs": [], "source": [ "try:\n", " import cirq\n", @@ -76,7 +78,9 @@ " print(\"installing cirq...\")\n", " !pip install --quiet cirq\n", " print(\"installed cirq.\")" - ] + ], + "outputs": [], + "execution_count": 2 }, { "cell_type": "markdown", @@ -962,31 +966,39 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { - "id": "2d83326239b3" + "id": "2d83326239b3", + "ExecuteTime": { + "end_time": "2024-08-18T20:07:19.182939Z", + "start_time": "2024-08-18T20:07:18.906936Z" + } }, - "outputs": [], "source": [ "import cirq_google\n", "\n", "processor_id = \"rainbow\" # or \"weber\"\n", "# Load the calibration data\n", "cal = cirq_google.engine.load_median_device_calibration(processor_id)\n", + "#create qubits\n", + "q0, q1 = cirq.q(4, 1), cirq.q(4, 2)\n", + "#create a circuit\n", + "circuit = cirq.Circuit(cirq.CX.on(q0, q1))\n", + "#compile circuit against target gateset\n", + "compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset())\n", "# Turn calibration data into a noise properties object\n", - "noise_props = cirq_google.noise_properties_from_calibration(cal)\n", + "noise_props = cirq_google.noise_properties_from_calibration(cal, compiled_circuit)\n", "# Build a noise model from the noise properties\n", "noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)" - ] + ], + "outputs": [], + "execution_count": 3 }, { "cell_type": "markdown", "metadata": { "id": "640b41a79b49" }, - "source": [ - "While this `NoiseModel` can be used anywhere other noise models could be used, it is particularly useful in a [Quantum Virtual Machine](./quantum_virtual_machine.ipynb). A QVM combines a realistic noise model and a [Device](../hardware/devices.ipynb) object together and places them behind a `cirq.Engine`-style interface so that you can run circuits almost identically to how you would with a hardware device, and get results that approximate those a hardware device would produce. " - ] + "source": "While this `NoiseModel` can be used anywhere other noise models could be used, it is particularly useful in a [Quantum Virtual Machine](./quantum_virtual_machine.ipynb). A QVM combines a realistic noise model and a [Device](../hardware/devices.ipynb) object together and places them behind a `cirq.Engine`-style interface so that you can run circuits almost identically to how you would with a hardware device, and get results that approximate those a hardware device would produce." } ], "metadata": { @@ -995,8 +1007,9 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3", - "name": "python3" + "display_name": "Python 3 (ipykernel)", + "name": "python3", + "language": "python" } }, "nbformat": 4, diff --git a/docs/simulate/quantum_virtual_machine.ipynb b/docs/simulate/quantum_virtual_machine.ipynb index f8142898fe3..d59962c7ecc 100644 --- a/docs/simulate/quantum_virtual_machine.ipynb +++ b/docs/simulate/quantum_virtual_machine.ipynb @@ -84,12 +84,14 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { "cellView": "form", - "id": "43IpRYMY1Ynr" + "id": "43IpRYMY1Ynr", + "ExecuteTime": { + "end_time": "2024-08-18T20:05:03.157808Z", + "start_time": "2024-08-18T20:04:46.438685Z" + } }, - "outputs": [], "source": [ "# @title Install `cirq_google` and `qsimcirq`\n", "\n", @@ -110,7 +112,21 @@ " !pip install --quiet qsimcirq\n", " print(f\"installed qsimcirq.\")\n", " import qsimcirq" - ] + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "installing qsimcirq...\n", + "\r\n", + "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m23.2.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m24.2\u001B[0m\r\n", + "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\r\n", + "installed qsimcirq.\n" + ] + } + ], + "execution_count": 2 }, { "cell_type": "markdown", @@ -127,15 +143,19 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { - "id": "YaLtjwcFy4AC" + "id": "YaLtjwcFy4AC", + "ExecuteTime": { + "end_time": "2024-08-18T20:05:29.425711Z", + "start_time": "2024-08-18T20:05:29.420538Z" + } }, - "outputs": [], "source": [ "# Choose a processor (\"rainbow\" or \"weber\")\n", "processor_id = \"weber\"" - ] + ], + "outputs": [], + "execution_count": 4 }, { "cell_type": "markdown", @@ -153,21 +173,31 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { - "id": "ygV7yCoBy6I9" + "id": "ygV7yCoBy6I9", + "ExecuteTime": { + "end_time": "2024-08-18T20:07:48.347275Z", + "start_time": "2024-08-18T20:07:47.281501Z" + } }, - "outputs": [], "source": [ "# Load the median device noise calibration for your selected processor.\n", "cal = cirq_google.engine.load_median_device_calibration(processor_id)\n", "# Create the noise properties object.\n", - "noise_props = cirq_google.noise_properties_from_calibration(cal)\n", + "q0, q1 = cirq.q(4, 1), cirq.q(4, 2)\n", + "#create qubits\n", + "circuit = cirq.Circuit(cirq.CX.on(q0, q1))\n", + "#compile circuit against target gateset\n", + "compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset())\n", + "#create noise_props from calibration\n", + "noise_props = cirq_google.noise_properties_from_calibration(cal, compiled_circuit)\n", "# Create a noise model from the noise properties.\n", "noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)\n", "# Prepare a qsim simulator using the noise model.\n", "sim = qsimcirq.QSimSimulator(noise=noise_model)" - ] + ], + "outputs": [], + "execution_count": 6 }, { "cell_type": "markdown", @@ -267,8 +297,9 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3", - "name": "python3" + "display_name": "Python 3 (ipykernel)", + "name": "python3", + "language": "python" } }, "nbformat": 4, diff --git a/docs/simulate/qvm_basic_example.ipynb b/docs/simulate/qvm_basic_example.ipynb index dcd8c548638..b2e4fca575d 100644 --- a/docs/simulate/qvm_basic_example.ipynb +++ b/docs/simulate/qvm_basic_example.ipynb @@ -82,12 +82,14 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { "cellView": "form", - "id": "zs5J6wAXqvtW" + "id": "zs5J6wAXqvtW", + "ExecuteTime": { + "end_time": "2024-08-18T20:10:36.403481Z", + "start_time": "2024-08-18T20:10:28.006479Z" + } }, - "outputs": [], "source": [ "# @title Install `cirq_google` and `qsimcirq`\n", "\n", @@ -112,7 +114,9 @@ "# Other modules used in this colab\n", "import matplotlib.pyplot as plt\n", "import time" - ] + ], + "outputs": [], + "execution_count": 2 }, { "cell_type": "markdown", @@ -133,19 +137,28 @@ }, { "cell_type": "code", - "execution_count": null, "metadata": { "cellView": "form", - "id": "pbHCUPLpq5WE" + "id": "pbHCUPLpq5WE", + "ExecuteTime": { + "end_time": "2024-08-18T20:10:40.538116Z", + "start_time": "2024-08-18T20:10:40.239421Z" + } }, - "outputs": [], "source": [ "# @title Choose a processor (\"rainbow\" or \"weber\")\n", "processor_id = \"weber\" # @param {type:\"string\"}\n", "\n", "# Construct a simulator with a noise model based on the specified processor.\n", "cal = cirq_google.engine.load_median_device_calibration(processor_id)\n", - "noise_props = cirq_google.noise_properties_from_calibration(cal)\n", + "# Create the noise properties object.\n", + "q0, q1 = cirq.q(4, 1), cirq.q(4, 2)\n", + "#create qubits\n", + "circuit = cirq.Circuit(cirq.CX.on(q0, q1))\n", + "#compile circuit against target gateset\n", + "compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset())\n", + "#create noise_props from calibration\n", + "noise_props = cirq_google.noise_properties_from_calibration(cal, compiled_circuit)\n", "noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)\n", "sim = qsimcirq.QSimSimulator(noise=noise_model)\n", "\n", @@ -164,7 +177,47 @@ " \"\\n========================\\n\",\n", ")\n", "print(sim_engine.get_processor(processor_id).get_device())" - ] + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your quantum virtual machine weber is ready, here is the qubit grid: \n", + "========================\n", + "\n", + " (0, 5)───(0, 6)\n", + " │ │\n", + " │ │\n", + " (1, 4)───(1, 5)───(1, 6)───(1, 7)\n", + " │ │ │ │\n", + " │ │ │ │\n", + " (2, 4)───(2, 5)───(2, 6)───(2, 7)───(2, 8)\n", + " │ │ │ │ │\n", + " │ │ │ │ │\n", + " (3, 2)───(3, 3)───(3, 4)───(3, 5)───(3, 6)───(3, 7)───(3, 8)───(3, 9)\n", + " │ │ │ │ │ │ │ │\n", + " │ │ │ │ │ │ │ │\n", + " (4, 1)───(4, 2)───(4, 3)───(4, 4)───(4, 5)───(4, 6)───(4, 7)───(4, 8)───(4, 9)\n", + " │ │ │ │ │ │ │ │\n", + " │ │ │ │ │ │ │ │\n", + "(5, 0)───(5, 1)───(5, 2)───(5, 3)───(5, 4)───(5, 5)───(5, 6)───(5, 7)───(5, 8)\n", + " │ │ │ │ │ │ │\n", + " │ │ │ │ │ │ │\n", + " (6, 1)───(6, 2)───(6, 3)───(6, 4)───(6, 5)───(6, 6)───(6, 7)\n", + " │ │ │ │ │\n", + " │ │ │ │ │\n", + " (7, 2)───(7, 3)───(7, 4)───(7, 5)───(7, 6)\n", + " │ │ │\n", + " │ │ │\n", + " (8, 3)───(8, 4)───(8, 5)\n", + " │\n", + " │\n", + " (9, 4)\n" + ] + } + ], + "execution_count": 3 }, { "cell_type": "markdown", @@ -423,8 +476,9 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3", - "name": "python3" + "display_name": "Python 3 (ipykernel)", + "name": "python3", + "language": "python" } }, "nbformat": 4, From 6c582a8a1bb1d3407010e320ecd3a38f08f8c97b Mon Sep 17 00:00:00 2001 From: nivedha rajaram Date: Sun, 18 Aug 2024 16:27:01 -0500 Subject: [PATCH 2/4] removed docs update --- docs/hardware/qubit_picking.ipynb | 34 +++------ docs/simulate/noisy_simulation.ipynb | 43 ++++-------- docs/simulate/quantum_virtual_machine.ipynb | 63 +++++------------ docs/simulate/qvm_basic_example.ipynb | 76 +++------------------ 4 files changed, 53 insertions(+), 163 deletions(-) diff --git a/docs/hardware/qubit_picking.ipynb b/docs/hardware/qubit_picking.ipynb index a6fb834b510..fb356dadfb2 100644 --- a/docs/hardware/qubit_picking.ipynb +++ b/docs/hardware/qubit_picking.ipynb @@ -73,14 +73,12 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "cellView": "form", - "id": "pBl-1eHNHXS8", - "ExecuteTime": { - "end_time": "2024-08-18T20:02:10.158772Z", - "start_time": "2024-08-18T20:02:10.151880Z" - } + "id": "pBl-1eHNHXS8" }, + "outputs": [], "source": [ "# @title Setup\n", "try:\n", @@ -94,9 +92,7 @@ "import cirq_google\n", "import numpy as np\n", "from matplotlib import pyplot as plt" - ], - "outputs": [], - "execution_count": 3 + ] }, { "cell_type": "markdown", @@ -117,23 +113,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "hKfu5yVi2Ebs", - "ExecuteTime": { - "end_time": "2024-08-18T20:07:33.480846Z", - "start_time": "2024-08-18T20:07:33.356894Z" - } + "id": "hKfu5yVi2Ebs" }, + "outputs": [], "source": [ - "q0, q1 = cirq.q(4, 1), cirq.q(4, 2)\n", - "circuit = cirq.Circuit(cirq.CX.on(q0, q1))\n", - "compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset())\n", "processor_id = \"rainbow\"\n", "cal = cirq_google.engine.load_median_device_calibration(processor_id)\n", - "noise_props = cirq_google.noise_properties_from_calibration(cal, compiled_circuit)" - ], - "outputs": [], - "execution_count": 5 + "noise_props = cirq_google.noise_properties_from_calibration(cal)" + ] }, { "cell_type": "markdown", @@ -357,9 +346,8 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "name": "python3", - "language": "python" + "display_name": "Python 3", + "name": "python3" } }, "nbformat": 4, diff --git a/docs/simulate/noisy_simulation.ipynb b/docs/simulate/noisy_simulation.ipynb index 936aeee1ee3..d1d2a2b57f3 100644 --- a/docs/simulate/noisy_simulation.ipynb +++ b/docs/simulate/noisy_simulation.ipynb @@ -64,13 +64,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "846b32703c5c", - "ExecuteTime": { - "end_time": "2024-08-18T20:07:12.950299Z", - "start_time": "2024-08-18T20:07:12.941938Z" - } + "id": "846b32703c5c" }, + "outputs": [], "source": [ "try:\n", " import cirq\n", @@ -78,9 +76,7 @@ " print(\"installing cirq...\")\n", " !pip install --quiet cirq\n", " print(\"installed cirq.\")" - ], - "outputs": [], - "execution_count": 2 + ] }, { "cell_type": "markdown", @@ -966,39 +962,31 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "2d83326239b3", - "ExecuteTime": { - "end_time": "2024-08-18T20:07:19.182939Z", - "start_time": "2024-08-18T20:07:18.906936Z" - } + "id": "2d83326239b3" }, + "outputs": [], "source": [ "import cirq_google\n", "\n", "processor_id = \"rainbow\" # or \"weber\"\n", "# Load the calibration data\n", "cal = cirq_google.engine.load_median_device_calibration(processor_id)\n", - "#create qubits\n", - "q0, q1 = cirq.q(4, 1), cirq.q(4, 2)\n", - "#create a circuit\n", - "circuit = cirq.Circuit(cirq.CX.on(q0, q1))\n", - "#compile circuit against target gateset\n", - "compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset())\n", "# Turn calibration data into a noise properties object\n", - "noise_props = cirq_google.noise_properties_from_calibration(cal, compiled_circuit)\n", + "noise_props = cirq_google.noise_properties_from_calibration(cal)\n", "# Build a noise model from the noise properties\n", "noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)" - ], - "outputs": [], - "execution_count": 3 + ] }, { "cell_type": "markdown", "metadata": { "id": "640b41a79b49" }, - "source": "While this `NoiseModel` can be used anywhere other noise models could be used, it is particularly useful in a [Quantum Virtual Machine](./quantum_virtual_machine.ipynb). A QVM combines a realistic noise model and a [Device](../hardware/devices.ipynb) object together and places them behind a `cirq.Engine`-style interface so that you can run circuits almost identically to how you would with a hardware device, and get results that approximate those a hardware device would produce." + "source": [ + "While this `NoiseModel` can be used anywhere other noise models could be used, it is particularly useful in a [Quantum Virtual Machine](./quantum_virtual_machine.ipynb). A QVM combines a realistic noise model and a [Device](../hardware/devices.ipynb) object together and places them behind a `cirq.Engine`-style interface so that you can run circuits almost identically to how you would with a hardware device, and get results that approximate those a hardware device would produce. " + ] } ], "metadata": { @@ -1007,11 +995,10 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "name": "python3", - "language": "python" + "display_name": "Python 3", + "name": "python3" } }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file diff --git a/docs/simulate/quantum_virtual_machine.ipynb b/docs/simulate/quantum_virtual_machine.ipynb index d59962c7ecc..e4673b86f9e 100644 --- a/docs/simulate/quantum_virtual_machine.ipynb +++ b/docs/simulate/quantum_virtual_machine.ipynb @@ -84,14 +84,12 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "cellView": "form", - "id": "43IpRYMY1Ynr", - "ExecuteTime": { - "end_time": "2024-08-18T20:05:03.157808Z", - "start_time": "2024-08-18T20:04:46.438685Z" - } + "id": "43IpRYMY1Ynr" }, + "outputs": [], "source": [ "# @title Install `cirq_google` and `qsimcirq`\n", "\n", @@ -112,21 +110,7 @@ " !pip install --quiet qsimcirq\n", " print(f\"installed qsimcirq.\")\n", " import qsimcirq" - ], - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "installing qsimcirq...\n", - "\r\n", - "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m23.2.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m24.2\u001B[0m\r\n", - "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\r\n", - "installed qsimcirq.\n" - ] - } - ], - "execution_count": 2 + ] }, { "cell_type": "markdown", @@ -143,19 +127,15 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "YaLtjwcFy4AC", - "ExecuteTime": { - "end_time": "2024-08-18T20:05:29.425711Z", - "start_time": "2024-08-18T20:05:29.420538Z" - } + "id": "YaLtjwcFy4AC" }, + "outputs": [], "source": [ "# Choose a processor (\"rainbow\" or \"weber\")\n", "processor_id = \"weber\"" - ], - "outputs": [], - "execution_count": 4 + ] }, { "cell_type": "markdown", @@ -173,31 +153,21 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "ygV7yCoBy6I9", - "ExecuteTime": { - "end_time": "2024-08-18T20:07:48.347275Z", - "start_time": "2024-08-18T20:07:47.281501Z" - } + "id": "ygV7yCoBy6I9" }, + "outputs": [], "source": [ "# Load the median device noise calibration for your selected processor.\n", "cal = cirq_google.engine.load_median_device_calibration(processor_id)\n", "# Create the noise properties object.\n", - "q0, q1 = cirq.q(4, 1), cirq.q(4, 2)\n", - "#create qubits\n", - "circuit = cirq.Circuit(cirq.CX.on(q0, q1))\n", - "#compile circuit against target gateset\n", - "compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset())\n", - "#create noise_props from calibration\n", - "noise_props = cirq_google.noise_properties_from_calibration(cal, compiled_circuit)\n", + "noise_props = cirq_google.noise_properties_from_calibration(cal)\n", "# Create a noise model from the noise properties.\n", "noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)\n", "# Prepare a qsim simulator using the noise model.\n", "sim = qsimcirq.QSimSimulator(noise=noise_model)" - ], - "outputs": [], - "execution_count": 6 + ] }, { "cell_type": "markdown", @@ -297,11 +267,10 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "name": "python3", - "language": "python" + "display_name": "Python 3", + "name": "python3" } }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file diff --git a/docs/simulate/qvm_basic_example.ipynb b/docs/simulate/qvm_basic_example.ipynb index b2e4fca575d..dcd8c548638 100644 --- a/docs/simulate/qvm_basic_example.ipynb +++ b/docs/simulate/qvm_basic_example.ipynb @@ -82,14 +82,12 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "cellView": "form", - "id": "zs5J6wAXqvtW", - "ExecuteTime": { - "end_time": "2024-08-18T20:10:36.403481Z", - "start_time": "2024-08-18T20:10:28.006479Z" - } + "id": "zs5J6wAXqvtW" }, + "outputs": [], "source": [ "# @title Install `cirq_google` and `qsimcirq`\n", "\n", @@ -114,9 +112,7 @@ "# Other modules used in this colab\n", "import matplotlib.pyplot as plt\n", "import time" - ], - "outputs": [], - "execution_count": 2 + ] }, { "cell_type": "markdown", @@ -137,28 +133,19 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "cellView": "form", - "id": "pbHCUPLpq5WE", - "ExecuteTime": { - "end_time": "2024-08-18T20:10:40.538116Z", - "start_time": "2024-08-18T20:10:40.239421Z" - } + "id": "pbHCUPLpq5WE" }, + "outputs": [], "source": [ "# @title Choose a processor (\"rainbow\" or \"weber\")\n", "processor_id = \"weber\" # @param {type:\"string\"}\n", "\n", "# Construct a simulator with a noise model based on the specified processor.\n", "cal = cirq_google.engine.load_median_device_calibration(processor_id)\n", - "# Create the noise properties object.\n", - "q0, q1 = cirq.q(4, 1), cirq.q(4, 2)\n", - "#create qubits\n", - "circuit = cirq.Circuit(cirq.CX.on(q0, q1))\n", - "#compile circuit against target gateset\n", - "compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset())\n", - "#create noise_props from calibration\n", - "noise_props = cirq_google.noise_properties_from_calibration(cal, compiled_circuit)\n", + "noise_props = cirq_google.noise_properties_from_calibration(cal)\n", "noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)\n", "sim = qsimcirq.QSimSimulator(noise=noise_model)\n", "\n", @@ -177,47 +164,7 @@ " \"\\n========================\\n\",\n", ")\n", "print(sim_engine.get_processor(processor_id).get_device())" - ], - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Your quantum virtual machine weber is ready, here is the qubit grid: \n", - "========================\n", - "\n", - " (0, 5)───(0, 6)\n", - " │ │\n", - " │ │\n", - " (1, 4)───(1, 5)───(1, 6)───(1, 7)\n", - " │ │ │ │\n", - " │ │ │ │\n", - " (2, 4)───(2, 5)───(2, 6)───(2, 7)───(2, 8)\n", - " │ │ │ │ │\n", - " │ │ │ │ │\n", - " (3, 2)───(3, 3)───(3, 4)───(3, 5)───(3, 6)───(3, 7)───(3, 8)───(3, 9)\n", - " │ │ │ │ │ │ │ │\n", - " │ │ │ │ │ │ │ │\n", - " (4, 1)───(4, 2)───(4, 3)───(4, 4)───(4, 5)───(4, 6)───(4, 7)───(4, 8)───(4, 9)\n", - " │ │ │ │ │ │ │ │\n", - " │ │ │ │ │ │ │ │\n", - "(5, 0)───(5, 1)───(5, 2)───(5, 3)───(5, 4)───(5, 5)───(5, 6)───(5, 7)───(5, 8)\n", - " │ │ │ │ │ │ │\n", - " │ │ │ │ │ │ │\n", - " (6, 1)───(6, 2)───(6, 3)───(6, 4)───(6, 5)───(6, 6)───(6, 7)\n", - " │ │ │ │ │\n", - " │ │ │ │ │\n", - " (7, 2)───(7, 3)───(7, 4)───(7, 5)───(7, 6)\n", - " │ │ │\n", - " │ │ │\n", - " (8, 3)───(8, 4)───(8, 5)\n", - " │\n", - " │\n", - " (9, 4)\n" - ] - } - ], - "execution_count": 3 + ] }, { "cell_type": "markdown", @@ -476,9 +423,8 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "name": "python3", - "language": "python" + "display_name": "Python 3", + "name": "python3" } }, "nbformat": 4, From f32febd5dbe245d87e7c1e79a5f84e436e5e33fb Mon Sep 17 00:00:00 2001 From: nivedha rajaram Date: Sun, 18 Aug 2024 16:29:33 -0500 Subject: [PATCH 3/4] removed docs --- .../engine/calibration_to_noise_properties.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py index 8ea1364f329..986c7b5565c 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py @@ -20,10 +20,7 @@ >>> cal = cirq_google.engine.load_median_device_calibration("rainbow") >>> noise_props = cirq_google.engine.noise_properties_from_calibration(cal) - >>> q0, q1 = cirq.q(4, 1), cirq.q(4, 2) - >>> circuit = cirq.Circuit(cirq.CX.on(q0, q1)) - >>> compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) - >>> noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props, compiled_circuit) + >>> noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props) >>> simulator = cirq.Simulator(noise=noise_model) >>> circuit = cirq.Circuit(cirq.X(cirq.GridQubit(5, 2))) >>> result = simulator.simulate(circuit) @@ -105,10 +102,7 @@ def noise_properties_from_calibration( To manually override noise properties, call `with_params` on the output: >>> cal = cirq_google.engine.load_median_device_calibration("rainbow") - >>> q0, q1 = cirq.q(4, 1), cirq.q(4, 2) - >>> circuit = cirq.Circuit(cirq.CX.on(q0, q1)) - >>> compiled_circuit = cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) - >>> noise_props = cirq_google.engine.noise_properties_from_calibration(cal, compiled_circuit).with_params( + >>> noise_props = cirq_google.engine.noise_properties_from_calibration(cal).with_params( ... gate_times_ns=37) See `cirq_google.GoogleNoiseProperties` for details. From cd4f7813bf507e7ca4bf3fc742d163bd043c9639 Mon Sep 17 00:00:00 2001 From: nivedha rajaram Date: Sun, 18 Aug 2024 16:30:53 -0500 Subject: [PATCH 4/4] readded docs --- .../cirq_google/engine/calibration_to_noise_properties.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py index 986c7b5565c..a55655711ac 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py @@ -102,6 +102,7 @@ def noise_properties_from_calibration( To manually override noise properties, call `with_params` on the output: >>> cal = cirq_google.engine.load_median_device_calibration("rainbow") + >>> # noise_props with all gate durations set to 37ns. >>> noise_props = cirq_google.engine.noise_properties_from_calibration(cal).with_params( ... gate_times_ns=37)