Ejemplo n.º 1
0
def test_insertion_noise():
    q0, q1 = cirq.LineQubit.range(2)
    op_id0 = OpIdentifier(cirq.XPowGate, q0)
    op_id1 = OpIdentifier(cirq.ZPowGate, q1)
    model = InsertionNoiseModel({
        op_id0: cirq.T(q0),
        op_id1: cirq.H(q1)
    },
                                require_physical_tag=False)
    assert not model.prepend

    moment_0 = cirq.Moment(cirq.X(q0), cirq.X(q1))
    assert model.noisy_moment(moment_0, system_qubits=[q0, q1]) == [
        moment_0,
        cirq.Moment(cirq.T(q0)),
    ]

    moment_1 = cirq.Moment(cirq.Z(q0), cirq.Z(q1))
    assert model.noisy_moment(moment_1, system_qubits=[q0, q1]) == [
        moment_1,
        cirq.Moment(cirq.H(q1)),
    ]

    moment_2 = cirq.Moment(cirq.X(q0), cirq.Z(q1))
    assert model.noisy_moment(moment_2, system_qubits=[q0, q1]) == [
        moment_2,
        cirq.Moment(cirq.T(q0), cirq.H(q1)),
    ]

    moment_3 = cirq.Moment(cirq.Z(q0), cirq.X(q1))
    assert model.noisy_moment(moment_3, system_qubits=[q0, q1]) == [moment_3]
Ejemplo n.º 2
0
def sample_noise_properties(
    system_qubits: List[cirq.Qid], qubit_pairs: List[Tuple[cirq.Qid, cirq.Qid]]
):
    # Known false positive: https://github.com/PyCQA/pylint/issues/5857
    return GoogleNoiseProperties(  # pylint: disable=unexpected-keyword-arg
        gate_times_ns=DEFAULT_GATE_NS,
        t1_ns={q: 1e5 for q in system_qubits},
        tphi_ns={q: 2e5 for q in system_qubits},
        readout_errors={q: np.array([SINGLE_QUBIT_ERROR, TWO_QUBIT_ERROR]) for q in system_qubits},
        gate_pauli_errors={
            **{
                OpIdentifier(g, q): 0.001
                for g in GoogleNoiseProperties.single_qubit_gates()
                for q in system_qubits
            },
            **{
                OpIdentifier(g, q0, q1): 0.01
                for g in GoogleNoiseProperties.symmetric_two_qubit_gates()
                for q0, q1 in qubit_pairs
            },
        },
        fsim_errors={
            OpIdentifier(g, q0, q1): cirq.PhasedFSimGate(0.01, 0.03, 0.04, 0.05, 0.02)
            for g in GoogleNoiseProperties.symmetric_two_qubit_gates()
            for q0, q1 in qubit_pairs
        },
    )
Ejemplo n.º 3
0
def test_op_id_swap():
    q0, q1 = cirq.LineQubit.range(2)
    base_id = OpIdentifier(cirq.CZPowGate, q0, q1)
    swap_id = OpIdentifier(base_id.gate_type, *base_id.qubits[::-1])
    assert cirq.CZ(q0, q1) in base_id
    assert cirq.CZ(q0, q1) not in swap_id
    assert cirq.CZ(q1, q0) not in base_id
    assert cirq.CZ(q1, q0) in swap_id
Ejemplo n.º 4
0
 def build_noise_models(self):
     add_h = InsertionNoiseModel(
         {OpIdentifier(cirq.Gate, q): cirq.H(q)
          for q in self.qubits})
     add_iswap = InsertionNoiseModel({
         OpIdentifier(cirq.Gate, *qs): cirq.ISWAP(*qs)
         for qs in self.qubit_pairs
     })
     return [add_h, add_iswap]
Ejemplo n.º 5
0
def test_require_physical_tag():
    q0, q1 = cirq.LineQubit.range(2)
    op_id0 = OpIdentifier(cirq.XPowGate, q0)
    op_id1 = OpIdentifier(cirq.ZPowGate, q1)
    model = InsertionNoiseModel({op_id0: cirq.T(q0), op_id1: cirq.H(q1)})
    assert model.require_physical_tag

    moment_0 = cirq.Moment(cirq.X(q0).with_tags(PHYSICAL_GATE_TAG), cirq.Z(q1))
    assert model.noisy_moment(moment_0, system_qubits=[q0, q1]) == [
        moment_0,
        cirq.Moment(cirq.T(q0)),
    ]
def test_prepend():
    q0, q1 = cirq.LineQubit.range(2)
    op_id0 = OpIdentifier(cirq.XPowGate, q0)
    op_id1 = OpIdentifier(cirq.ZPowGate, q1)
    model = InsertionNoiseModel(
        {op_id0: cirq.T(q0), op_id1: cirq.H(q1)}, prepend=True, require_physical_tag=False
    )

    moment_0 = cirq.Moment(cirq.X(q0), cirq.Z(q1))
    assert model.noisy_moment(moment_0, system_qubits=[q0, q1]) == [
        cirq.Moment(cirq.T(q0), cirq.H(q1)),
        moment_0,
    ]
Ejemplo n.º 7
0
def test_supertype_match():
    # Verifies that ops in gate_pauli_errors which only appear as their
    # supertypes in fsim_errors are properly accounted for.
    q0, q1 = cirq.LineQubit.range(2)
    op_id = OpIdentifier(cirq_google.SycamoreGate, q0, q1)
    test_props = sample_noise_properties([q0, q1], [(q0, q1), (q1, q0)])
    expected_err = test_props._depolarizing_error[op_id]

    props = sample_noise_properties([q0, q1], [(q0, q1), (q1, q0)])
    props.fsim_errors = {
        k: cirq.PhasedFSimGate(0.5, 0.4, 0.3, 0.2, 0.1)
        for k in [OpIdentifier(cirq.FSimGate, q0, q1), OpIdentifier(cirq.FSimGate, q1, q0)]
    }
    assert props._depolarizing_error[op_id] != expected_err
Ejemplo n.º 8
0
def test_op_identifier_subtypes():
    gate_id = OpIdentifier(cirq.Gate)
    xpow_id = OpIdentifier(cirq.XPowGate)
    x_on_q0_id = OpIdentifier(cirq.XPowGate, cirq.LineQubit(0))
    assert xpow_id.is_proper_subtype_of(gate_id)
    assert x_on_q0_id.is_proper_subtype_of(xpow_id)
    assert x_on_q0_id.is_proper_subtype_of(gate_id)
    assert not xpow_id.is_proper_subtype_of(xpow_id)
def test_supertype_matching():
    # Demonstrate that the model applies the closest matching type
    # if multiple types match a given gate.
    q0 = cirq.LineQubit(0)
    op_id0 = OpIdentifier(cirq.Gate, q0)
    op_id1 = OpIdentifier(cirq.XPowGate, q0)
    model = InsertionNoiseModel(
        {op_id0: cirq.T(q0), op_id1: cirq.S(q0)}, require_physical_tag=False
    )

    moment_0 = cirq.Moment(cirq.Rx(rads=1).on(q0))
    assert model.noisy_moment(moment_0, system_qubits=[q0]) == [moment_0, cirq.Moment(cirq.S(q0))]

    moment_1 = cirq.Moment(cirq.Y(q0))
    assert model.noisy_moment(moment_1, system_qubits=[q0]) == [moment_1, cirq.Moment(cirq.T(q0))]
Ejemplo n.º 10
0
def test_op_id_str():
    op_id = OpIdentifier(cirq.XPowGate, cirq.LineQubit(0))
    print(op_id)
    print(repr(op_id))
    assert str(
        op_id
    ) == "<class 'cirq.ops.common_gates.XPowGate'>(cirq.LineQubit(0),)"
    assert repr(op_id) == (
        "cirq.devices.noise_utils.OpIdentifier(cirq.ops.common_gates.XPowGate, cirq.LineQubit(0))"
    )
def default_props(system_qubits: List[cirq.Qid], qubit_pairs: List[Tuple[cirq.Qid, cirq.Qid]]):
    return {
        'gate_times_ns': DEFAULT_GATE_NS,
        't1_ns': {q: 1e5 for q in system_qubits},
        'tphi_ns': {q: 2e5 for q in system_qubits},
        'readout_errors': {q: [0.001, 0.01] for q in system_qubits},
        'gate_pauli_errors': {
            **{
                OpIdentifier(g, q): 0.001
                for g in TestNoiseProperties.single_qubit_gates()
                for q in system_qubits
            },
            **{
                OpIdentifier(g, q0, q1): 0.01
                for g in TestNoiseProperties.two_qubit_gates()
                for q0, q1 in qubit_pairs
            },
        },
    }
Ejemplo n.º 12
0
def test_colliding_noise_qubits():
    # Check that noise affecting other qubits doesn't cause issues.
    q0, q1, q2, q3 = cirq.LineQubit.range(4)
    op_id0 = OpIdentifier(cirq.CZPowGate)
    model = InsertionNoiseModel({op_id0: cirq.CNOT(q1, q2)}, require_physical_tag=False)

    moment_0 = cirq.Moment(cirq.CZ(q0, q1), cirq.CZ(q2, q3))
    assert model.noisy_moment(moment_0, system_qubits=[q0, q1, q2, q3]) == [
        moment_0,
        cirq.Moment(cirq.CNOT(q1, q2)),
        cirq.Moment(cirq.CNOT(q1, q2)),
    ]
def test_depol_validation():
    q0, q1, q2 = cirq.LineQubit.range(3)
    # Create unvalidated properties with too many qubits on a Z gate.
    z_2q_props = TestNoiseProperties(
        gate_times_ns=DEFAULT_GATE_NS,
        t1_ns={q0: 1},
        tphi_ns={q0: 1},
        readout_errors={q0: [0.1, 0.2]},
        gate_pauli_errors={OpIdentifier(cirq.ZPowGate, q0, q1): 0.1},
        validate=False,
    )
    with pytest.raises(ValueError, match='takes 1 qubit'):
        _ = z_2q_props._depolarizing_error

    # Create unvalidated properties with too many qubits on a CZ gate.
    cz_3q_props = TestNoiseProperties(
        gate_times_ns=DEFAULT_GATE_NS,
        t1_ns={q0: 1},
        tphi_ns={q0: 1},
        readout_errors={q0: [0.1, 0.2]},
        gate_pauli_errors={OpIdentifier(cirq.CZPowGate, q0, q1, q2): 0.1},
        validate=False,
    )
    with pytest.raises(ValueError, match='takes 2 qubit'):
        _ = cz_3q_props._depolarizing_error

    # Unsupported gates are only checked in constructor.
    toffoli_props = TestNoiseProperties(
        gate_times_ns=DEFAULT_GATE_NS,
        t1_ns={q0: 1},
        tphi_ns={q0: 1},
        readout_errors={q0: [0.1, 0.2]},
        gate_pauli_errors={OpIdentifier(cirq.CCXPowGate, q0, q1, q2): 0.1},
        validate=False,
    )
    with pytest.raises(ValueError):
        _ = toffoli_props._depolarizing_error
Ejemplo n.º 14
0
def test_op_identifier():
    op_id = OpIdentifier(cirq.XPowGate)
    assert cirq.X(cirq.LineQubit(1)) in op_id
    assert cirq.Rx(rads=1) in op_id
def test_init_validation():
    q0, q1, q2 = cirq.LineQubit.range(3)
    with pytest.raises(
            ValueError,
            match='Keys specified for T1 and Tphi are not identical.'):
        _ = TestNoiseProperties(
            gate_times_ns=DEFAULT_GATE_NS,
            t1_ns={},
            tphi_ns={q0: 1},
            readout_errors={q0: [0.1, 0.2]},
            gate_pauli_errors={},
        )

    with pytest.raises(
            ValueError,
            match='Symmetric errors can only apply to 2-qubit gates.'):
        _ = TestNoiseProperties(
            gate_times_ns=DEFAULT_GATE_NS,
            t1_ns={q0: 1},
            tphi_ns={q0: 1},
            readout_errors={q0: [0.1, 0.2]},
            gate_pauli_errors={OpIdentifier(cirq.CCNOT, q0, q1, q2): 0.1},
        )

    with pytest.raises(ValueError,
                       match='does not appear in the symmetric or asymmetric'):
        _ = TestNoiseProperties(
            gate_times_ns=DEFAULT_GATE_NS,
            t1_ns={q0: 1},
            tphi_ns={q0: 1},
            readout_errors={q0: [0.1, 0.2]},
            gate_pauli_errors={
                OpIdentifier(cirq.CNOT, q0, q1): 0.1,
                OpIdentifier(cirq.CNOT, q1, q0): 0.1,
            },
        )

    with pytest.raises(ValueError, match='has errors but its symmetric id'):
        _ = TestNoiseProperties(
            gate_times_ns=DEFAULT_GATE_NS,
            t1_ns={q0: 1},
            tphi_ns={q0: 1},
            readout_errors={q0: [0.1, 0.2]},
            gate_pauli_errors={OpIdentifier(cirq.CZPowGate, q0, q1): 0.1},
        )

    # Single-qubit gates are ignored in symmetric-gate validation.
    test_props = TestNoiseProperties(
        gate_times_ns=DEFAULT_GATE_NS,
        t1_ns={q0: 1},
        tphi_ns={q0: 1},
        readout_errors={q0: [0.1, 0.2]},
        gate_pauli_errors={
            OpIdentifier(cirq.ZPowGate, q0): 0.1,
            OpIdentifier(cirq.CZPowGate, q0, q1): 0.1,
            OpIdentifier(cirq.CZPowGate, q1, q0): 0.1,
        },
    )
    assert test_props.expected_gates() == (
        TestNoiseProperties.single_qubit_gates()
        | TestNoiseProperties.symmetric_two_qubit_gates())

    # All errors are ignored if validation is disabled.
    _ = TestNoiseProperties(
        gate_times_ns=DEFAULT_GATE_NS,
        t1_ns={},
        tphi_ns={q0: 1},
        readout_errors={q0: [0.1, 0.2]},
        gate_pauli_errors={
            OpIdentifier(cirq.CCNOT, q0, q1, q2): 0.1,
            OpIdentifier(cirq.CNOT, q0, q1): 0.1,
        },
        validate=False,
    )
def test_zphase_data():
    qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)]
    pauli_error = [0.001, 0.002, 0.003]
    incoherent_error = [0.0001, 0.0002, 0.0003]
    p00_error = [0.004, 0.005, 0.006]
    p11_error = [0.007, 0.008, 0.009]
    t1_micros = [10, 20, 30]
    syc_pauli = [0.01, 0.02]
    iswap_pauli = [0.03, 0.04]
    syc_angles = [
        cirq.PhasedFSimGate(theta=0.011, phi=-0.021, zeta=-0.031, gamma=0.043),
        cirq.PhasedFSimGate(theta=-0.012, phi=0.022, zeta=0.032, gamma=-0.044),
    ]
    iswap_angles = [
        cirq.PhasedFSimGate(theta=-0.013, phi=0.023, zeta=0.031, gamma=-0.043),
        cirq.PhasedFSimGate(theta=0.014, phi=-0.024, zeta=-0.032, gamma=0.044),
    ]

    # Create NoiseProperties object from Calibration
    calibration = get_mock_calibration(
        pauli_error,
        incoherent_error,
        p00_error,
        p11_error,
        t1_micros,
        syc_pauli,
        iswap_pauli,
        syc_angles,
        iswap_angles,
    )

    qubit_pairs = [(qubits[0], qubits[1]), (qubits[0], qubits[2])]
    zphase_data = {
        "syc": {
            "zeta": {
                qubit_pairs[0]: syc_angles[0].zeta,
                qubit_pairs[1]: syc_angles[1].zeta
            },
            "gamma": {
                qubit_pairs[0]: syc_angles[0].gamma,
                qubit_pairs[1]: syc_angles[1].gamma
            },
        },
        "sqrt_iswap": {
            "zeta": {
                qubit_pairs[0]: iswap_angles[0].zeta,
                qubit_pairs[1]: iswap_angles[1].zeta
            },
            "gamma": {
                qubit_pairs[0]: iswap_angles[0].gamma,
                qubit_pairs[1]: iswap_angles[1].gamma
            },
        },
    }

    prop = cirq_google.noise_properties_from_calibration(
        calibration, zphase_data)
    for i, qs in enumerate(qubit_pairs):
        for gate, values in [
            (cirq_google.SycamoreGate, syc_angles),
            (cirq.ISwapPowGate, iswap_angles),
        ]:
            assert prop.fsim_errors[OpIdentifier(gate, *qs)] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs)] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i]
def test_noise_properties_from_calibration():
    qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)]
    pauli_error = [0.001, 0.002, 0.003]
    incoherent_error = [0.0001, 0.0002, 0.0003]
    p00_error = [0.004, 0.005, 0.006]
    p11_error = [0.007, 0.008, 0.009]
    t1_micros = [10, 20, 30]
    syc_pauli = [0.01, 0.02]
    iswap_pauli = [0.03, 0.04]
    syc_angles = [
        cirq.PhasedFSimGate(theta=0.011, phi=-0.021),
        cirq.PhasedFSimGate(theta=-0.012, phi=0.022),
    ]
    iswap_angles = [
        cirq.PhasedFSimGate(theta=-0.013, phi=0.023),
        cirq.PhasedFSimGate(theta=0.014, phi=-0.024),
    ]

    _CALIBRATION_DATA = Merge(
        f"""
    timestamp_ms: 1579214873,
    metrics: [{{
        name: 'single_qubit_rb_pauli_error_per_gate',
        targets: ['0_0'],
        values: [{{
            double_val: {pauli_error[0]}
        }}]
    }}, {{
        name: 'single_qubit_rb_pauli_error_per_gate',
        targets: ['0_1'],
        values: [{{
            double_val:{pauli_error[1]}
        }}]
    }}, {{
        name: 'single_qubit_rb_pauli_error_per_gate',
        targets: ['1_0'],
        values: [{{
            double_val:{pauli_error[2]}
        }}]
    }}, {{
        name: 'single_qubit_rb_incoherent_error_per_gate',
        targets: ['0_0'],
        values: [{{
            double_val: {incoherent_error[0]}
        }}]
    }}, {{
        name: 'single_qubit_rb_incoherent_error_per_gate',
        targets: ['0_1'],
        values: [{{
            double_val:{incoherent_error[1]}
        }}]
    }}, {{
        name: 'single_qubit_rb_incoherent_error_per_gate',
        targets: ['1_0'],
        values: [{{
            double_val:{incoherent_error[2]}
        }}]
    }}, {{
        name: 'single_qubit_p00_error',
        targets: ['0_0'],
        values: [{{
            double_val: {p00_error[0]}
        }}]
    }}, {{
        name: 'single_qubit_p00_error',
        targets: ['0_1'],
        values: [{{
            double_val: {p00_error[1]}
        }}]
    }}, {{
        name: 'single_qubit_p00_error',
        targets: ['1_0'],
        values: [{{
            double_val: {p00_error[2]}
        }}]
    }}, {{
        name: 'single_qubit_p11_error',
        targets: ['0_0'],
        values: [{{
            double_val: {p11_error[0]}
        }}]
    }}, {{
        name: 'single_qubit_p11_error',
        targets: ['0_1'],
        values: [{{
            double_val: {p11_error[1]}
        }}]
    }}, {{
        name: 'single_qubit_p11_error',
        targets: ['1_0'],
        values: [{{
            double_val: {p11_error[2]}
        }}]
    }}, {{
        name: 'single_qubit_idle_t1_micros',
        targets: ['0_0'],
        values: [{{
            double_val: {t1_micros[0]}
        }}]
    }}, {{
        name: 'single_qubit_idle_t1_micros',
        targets: ['0_1'],
        values: [{{
            double_val: {t1_micros[1]}
        }}]
    }}, {{
        name: 'single_qubit_idle_t1_micros',
        targets: ['1_0'],
        values: [{{
            double_val: {t1_micros[2]}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sycamore_gate_xeb_pauli_error_per_cycle',
        targets: ['0_0', '0_1'],
        values: [{{
            double_val: {syc_pauli[0]}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sycamore_gate_xeb_pauli_error_per_cycle',
        targets: ['0_0', '1_0'],
        values: [{{
            double_val: {syc_pauli[1]}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sqrt_iswap_gate_xeb_pauli_error_per_cycle',
        targets: ['0_0', '0_1'],
        values: [{{
            double_val: {iswap_pauli[0]}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sqrt_iswap_gate_xeb_pauli_error_per_cycle',
        targets: ['0_0', '1_0'],
        values: [{{
            double_val: {iswap_pauli[1]}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sycamore_gate_xeb_entangler_theta_error_per_cycle',
        targets: ['0_0', '0_1'],
        values: [{{
            double_val: {syc_angles[0].theta}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sycamore_gate_xeb_entangler_theta_error_per_cycle',
        targets: ['0_0', '1_0'],
        values: [{{
            double_val: {syc_angles[1].theta}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sqrt_iswap_gate_xeb_entangler_theta_error_per_cycle',
        targets: ['0_0', '0_1'],
        values: [{{
            double_val: {iswap_angles[0].theta}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sqrt_iswap_gate_xeb_entangler_theta_error_per_cycle',
        targets: ['0_0', '1_0'],
        values: [{{
            double_val: {iswap_angles[1].theta}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sycamore_gate_xeb_entangler_phi_error_per_cycle',
        targets: ['0_0', '0_1'],
        values: [{{
            double_val: {syc_angles[0].phi}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sycamore_gate_xeb_entangler_phi_error_per_cycle',
        targets: ['0_0', '1_0'],
        values: [{{
            double_val: {syc_angles[1].phi}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sqrt_iswap_gate_xeb_entangler_phi_error_per_cycle',
        targets: ['0_0', '0_1'],
        values: [{{
            double_val: {iswap_angles[0].phi}
        }}]
    }}, {{
        name: 'two_qubit_parallel_sqrt_iswap_gate_xeb_entangler_phi_error_per_cycle',
        targets: ['0_0', '1_0'],
        values: [{{
            double_val: {iswap_angles[1].phi}
        }}]
    }}]
""",
        cirq_google.api.v2.metrics_pb2.MetricsSnapshot(),
    )

    # Create NoiseProperties object from Calibration
    calibration = cirq_google.Calibration(_CALIBRATION_DATA)
    prop = cirq_google.noise_properties_from_calibration(calibration)

    for i, q in enumerate(qubits):
        assert np.isclose(
            prop.gate_pauli_errors[OpIdentifier(cirq.PhasedXZGate, q)],
            pauli_error[i])
        assert np.allclose(prop.readout_errors[q],
                           np.array([p00_error[i], p11_error[i]]))
        assert np.isclose(prop.t1_ns[q], t1_micros[i] * 1000)
        microwave_time_ns = 25.0
        tphi_err = incoherent_error[i] - microwave_time_ns / (3 *
                                                              prop.t1_ns[q])
        if tphi_err > 0:
            tphi_ns = microwave_time_ns / (3 * tphi_err)
        else:
            tphi_ns = 1e10
        assert prop.tphi_ns[q] == tphi_ns

    qubit_pairs = [(qubits[0], qubits[1]), (qubits[0], qubits[2])]
    for i, qs in enumerate(qubit_pairs):
        for gate, values in [
            (cirq_google.SycamoreGate, syc_pauli),
            (cirq.ISwapPowGate, iswap_pauli),
        ]:
            assert np.isclose(prop.gate_pauli_errors[OpIdentifier(gate, *qs)],
                              values[i])
            assert np.isclose(
                prop.gate_pauli_errors[OpIdentifier(gate, *qs[::-1])],
                values[i])
            assert np.isclose(prop.gate_pauli_errors[OpIdentifier(gate, *qs)],
                              values[i])
            assert np.isclose(
                prop.gate_pauli_errors[OpIdentifier(gate, *qs[::-1])],
                values[i])

        for gate, values in [
            (cirq_google.SycamoreGate, syc_angles),
            (cirq.ISwapPowGate, iswap_angles),
        ]:
            assert prop.fsim_errors[OpIdentifier(gate, *qs)] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs)] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i]
def test_noise_properties_from_calibration():
    qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)]
    pauli_error = [0.001, 0.002, 0.003]
    incoherent_error = [0.0001, 0.0002, 0.0003]
    p00_error = [0.004, 0.005, 0.006]
    p11_error = [0.007, 0.008, 0.009]
    t1_micros = [10, 20, 30]
    syc_pauli = [0.01, 0.02]
    iswap_pauli = [0.03, 0.04]
    syc_angles = [
        cirq.PhasedFSimGate(theta=0.011, phi=-0.021),
        cirq.PhasedFSimGate(theta=-0.012, phi=0.022),
    ]
    iswap_angles = [
        cirq.PhasedFSimGate(theta=-0.013, phi=0.023),
        cirq.PhasedFSimGate(theta=0.014, phi=-0.024),
    ]

    # Create NoiseProperties object from Calibration
    calibration = get_mock_calibration(
        pauli_error,
        incoherent_error,
        p00_error,
        p11_error,
        t1_micros,
        syc_pauli,
        iswap_pauli,
        syc_angles,
        iswap_angles,
    )
    prop = cirq_google.noise_properties_from_calibration(calibration)

    for i, q in enumerate(qubits):
        assert np.isclose(
            prop.gate_pauli_errors[OpIdentifier(cirq.PhasedXZGate, q)],
            pauli_error[i])
        assert np.allclose(prop.readout_errors[q],
                           np.array([p00_error[i], p11_error[i]]))
        assert np.isclose(prop.t1_ns[q], t1_micros[i] * 1000)
        microwave_time_ns = 25.0
        tphi_err = incoherent_error[i] - microwave_time_ns / (3 *
                                                              prop.t1_ns[q])
        if tphi_err > 0:
            tphi_ns = microwave_time_ns / (3 * tphi_err)
        else:
            tphi_ns = 1e10
        assert prop.tphi_ns[q] == tphi_ns

    qubit_pairs = [(qubits[0], qubits[1]), (qubits[0], qubits[2])]
    for i, qs in enumerate(qubit_pairs):
        for gate, values in [
            (cirq_google.SycamoreGate, syc_pauli),
            (cirq.ISwapPowGate, iswap_pauli),
        ]:
            assert np.isclose(prop.gate_pauli_errors[OpIdentifier(gate, *qs)],
                              values[i])
            assert np.isclose(
                prop.gate_pauli_errors[OpIdentifier(gate, *qs[::-1])],
                values[i])
            assert np.isclose(prop.gate_pauli_errors[OpIdentifier(gate, *qs)],
                              values[i])
            assert np.isclose(
                prop.gate_pauli_errors[OpIdentifier(gate, *qs[::-1])],
                values[i])

        for gate, values in [
            (cirq_google.SycamoreGate, syc_angles),
            (cirq.ISwapPowGate, iswap_angles),
        ]:
            assert prop.fsim_errors[OpIdentifier(gate, *qs)] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs)] == values[i]
            assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i]