From 1b724ded1cf9f581e47c7786396e07c95d35320f Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Thu, 31 Mar 2022 15:36:52 -0700 Subject: [PATCH] Add Google-specific variant for noise properties. (#5082) This PR provides an implementation of `SuperconductingQubitsNoiseProperties` for Google hardware. Now that SQNP is an abstract type, this is a prerequisite for re-enabling calibration-to-noise tools. This is part 3 of #4666; part 2 was #4964. Remaining steps include: - Reinstatement of calibration_to_noise_properties using new types - Reinstatement of compare_generated_noise_to_metrics using new types --- cirq/devices/noise_properties.py | 10 +++++++--- cirq/devices/noise_properties_test.py | 8 ++++++++ .../devices/superconducting_qubits_noise_properties.py | 7 ++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cirq/devices/noise_properties.py b/cirq/devices/noise_properties.py index a2ee49ff0fd..1c10d31bb52 100644 --- a/cirq/devices/noise_properties.py +++ b/cirq/devices/noise_properties.py @@ -22,7 +22,7 @@ import abc from typing import Iterable, Sequence, TYPE_CHECKING, List -from cirq import _import, ops, protocols, devices +from cirq import _compat, _import, ops, protocols, devices from cirq.devices.noise_utils import ( PHYSICAL_GATE_TAG, ) @@ -54,7 +54,7 @@ def __init__(self, noise_properties: NoiseProperties) -> None: self._noise_properties = noise_properties self.noise_models = self._noise_properties.build_noise_models() - def virtual_predicate(self, op: 'cirq.Operation') -> bool: + def is_virtual(self, op: 'cirq.Operation') -> bool: """Returns True if an operation is virtual. Device-specific subclasses should implement this method to mark any @@ -68,6 +68,10 @@ def virtual_predicate(self, op: 'cirq.Operation') -> bool: """ return False + @_compat.deprecated(deadline='v0.16', fix='Use is_virtual instead.') + def virtual_predicate(self, op: 'cirq.Operation') -> bool: + return self.is_virtual(op) + def noisy_moments( self, moments: Iterable['cirq.Moment'], system_qubits: Sequence['cirq.Qid'] ) -> Sequence['cirq.OP_TREE']: @@ -91,7 +95,7 @@ def noisy_moments( # using `self.virtual_predicate` to determine virtuality. new_moments = [] for moment in split_measure_moments: - virtual_ops = {op for op in moment if self.virtual_predicate(op)} + virtual_ops = {op for op in moment if self.is_virtual(op)} physical_ops = [ op.with_tags(PHYSICAL_GATE_TAG) for op in moment if op not in virtual_ops ] diff --git a/cirq/devices/noise_properties_test.py b/cirq/devices/noise_properties_test.py index c848af659b3..582e5754e89 100644 --- a/cirq/devices/noise_properties_test.py +++ b/cirq/devices/noise_properties_test.py @@ -60,3 +60,11 @@ def test_sample_model(): cirq.Moment(cirq.H(q0), cirq.H(q1)), ) assert noisy_circuit == expected_circuit + + +def test_deprecated_virtual_predicate(): + q0, q1 = cirq.LineQubit.range(2) + props = SampleNoiseProperties([q0, q1], [(q0, q1), (q1, q0)]) + model = NoiseModelFromNoiseProperties(props) + with cirq.testing.assert_deprecated("Use is_virtual", deadline="v0.16"): + _ = model.virtual_predicate(cirq.X(q0)) diff --git a/cirq/devices/superconducting_qubits_noise_properties.py b/cirq/devices/superconducting_qubits_noise_properties.py index 43a165e89f9..64e307d4623 100644 --- a/cirq/devices/superconducting_qubits_noise_properties.py +++ b/cirq/devices/superconducting_qubits_noise_properties.py @@ -35,14 +35,15 @@ class SuperconductingQubitsNoiseProperties(devices.NoiseProperties, abc.ABC): Args: gate_times_ns: Dict[type, float] of gate types to their duration on - quantum hardware. + quantum hardware. Used with t(1|phi)_ns to specify thermal noise. t1_ns: Dict[cirq.Qid, float] of qubits to their T_1 time, in ns. tphi_ns: Dict[cirq.Qid, float] of qubits to their T_phi time, in ns. readout_errors: Dict[cirq.Qid, np.ndarray] of qubits to their readout errors in matrix form: [P(read |1> from |0>), P(read |0> from |1>)]. + Used to prepend amplitude damping errors to measurements. gate_pauli_errors: dict of noise_utils.OpIdentifiers (a gate and the qubits it - targets) to the Pauli error for that operation. Keys in this dict - must have defined qubits. + targets) to the Pauli error for that operation. Used to construct + depolarizing error. Keys in this dict must have defined qubits. validate: If True, verifies that t1 and tphi qubits sets match, and that all symmetric two-qubit gates have errors which are symmetric over the qubits they affect. Defaults to True.