示例#1
0
 def noisy_moment(self, moment: cirq.Moment,
                  system_qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
     if self.is_virtual_moment(moment):
         return moment
     moments = []
     if validate_all_measurements(moment):
         if self.decay_probs:
             moments.append(
                 cirq.Moment(
                     cirq.AmplitudeDampingChannel(self.decay_probs[q])(q)
                     for q in system_qubits))
         if self.bitflip_probs:
             moments.append(
                 cirq.Moment(
                     cirq.BitFlipChannel(self.bitflip_probs[q])(q)
                     for q in system_qubits))
         moments.append(moment)
         return moments
     else:
         moments.append(moment)
         if self.depol_probs:
             gated_qubits = [
                 q for q in system_qubits
                 if moment.operates_on_single_qubit(q)
             ]
             if gated_qubits:
                 moments.append(
                     cirq.Moment(
                         cirq.DepolarizingChannel(self.depol_probs[q])(q)
                         for q in gated_qubits))
         return moments
示例#2
0
def test_per_qubit_readout_decay_from_data():
    # Generate the readout decay noise model from calibration data.
    calibration = cirq.google.Calibration(_CALIBRATION_DATA)
    noise_model = simple_noise_from_calibration_metrics(
        calibration=calibration, readout_decay_noise=True)

    # Create the circuit and apply the noise model.
    qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)]
    program = cirq.Circuit(
        cirq.Moment([cirq.H(qubits[0])]),
        cirq.Moment([cirq.CNOT(qubits[0], qubits[1])]),
        cirq.Moment([cirq.CNOT(qubits[0], qubits[2])]),
        cirq.Moment([
            cirq.measure(qubits[0], key='q0'),
            cirq.measure(qubits[1], key='q1'),
            cirq.measure(qubits[2], key='q2')
        ]))
    noisy_circuit = cirq.Circuit(noise_model.noisy_moments(program, qubits))

    # Insert channels explicitly to construct expected output.
    decay_prob = [1 - exp(-1 / 0.007), 1 - exp(-1 / 0.008), 1 - exp(-1 / 0.009)]
    expected_program = cirq.Circuit(
        cirq.Moment([cirq.H(qubits[0])]),
        cirq.Moment([cirq.CNOT(qubits[0], qubits[1])]),
        cirq.Moment([cirq.CNOT(qubits[0], qubits[2])]),
        cirq.Moment([
            cirq.AmplitudeDampingChannel(decay_prob[i]).on(qubits[i])
            for i in range(3)
        ]),
        cirq.Moment([
            cirq.measure(qubits[0], key='q0'),
            cirq.measure(qubits[1], key='q1'),
            cirq.measure(qubits[2], key='q2')
        ]))
    _assert_equivalent_op_tree(expected_program, noisy_circuit)
示例#3
0
def test_decay_noise_after_moment():
    program = cirq.Circuit()
    qubits = cirq.LineQubit.range(3)
    program.append([
        cirq.H(qubits[0]),
        cirq.CNOT(qubits[0], qubits[1]),
        cirq.CNOT(qubits[1], qubits[2])
    ])
    program.append([
        cirq.measure(qubits[0], key='q0'),
        cirq.measure(qubits[1], key='q1'),
        cirq.measure(qubits[2], key='q2')
    ],
                   strategy=cirq.InsertStrategy.NEW_THEN_INLINE)

    # Use noise model to generate circuit
    depol_noise = ccn.DepolarizingNoiseModel(depol_prob=0.01)
    readout_noise = ccn.ReadoutNoiseModel(bitflip_prob=0.05)
    damping_noise = ccn.DampedReadoutNoiseModel(decay_prob=0.02)
    noisy_circuit = cirq.Circuit(depol_noise.noisy_moments(program, qubits))
    noisy_circuit = cirq.Circuit(
        damping_noise.noisy_moments(noisy_circuit, qubits))
    noisy_circuit = cirq.Circuit(
        readout_noise.noisy_moments(noisy_circuit, qubits))

    # Insert channels explicitly
    true_noisy_program = cirq.Circuit()
    true_noisy_program.append([cirq.H(qubits[0])])
    true_noisy_program.append([
        cirq.DepolarizingChannel(0.01).on(q).with_tags(ops.VirtualTag())
        for q in qubits
    ],
                              strategy=cirq.InsertStrategy.NEW_THEN_INLINE)
    true_noisy_program.append([cirq.CNOT(qubits[0], qubits[1])])
    true_noisy_program.append([
        cirq.DepolarizingChannel(0.01).on(q).with_tags(ops.VirtualTag())
        for q in qubits
    ],
                              strategy=cirq.InsertStrategy.NEW_THEN_INLINE)
    true_noisy_program.append([cirq.CNOT(qubits[1], qubits[2])])
    true_noisy_program.append([
        cirq.DepolarizingChannel(0.01).on(q).with_tags(ops.VirtualTag())
        for q in qubits
    ],
                              strategy=cirq.InsertStrategy.NEW_THEN_INLINE)
    true_noisy_program.append([
        cirq.AmplitudeDampingChannel(0.02).on(q).with_tags(ops.VirtualTag())
        for q in qubits
    ])
    true_noisy_program.append([
        cirq.BitFlipChannel(0.05).on(q).with_tags(ops.VirtualTag())
        for q in qubits
    ])
    true_noisy_program.append([
        cirq.measure(qubits[0], key='q0'),
        cirq.measure(qubits[1], key='q1'),
        cirq.measure(qubits[2], key='q2')
    ])
    _assert_equivalent_op_tree(true_noisy_program, noisy_circuit)
示例#4
0
def get_supported_channels():
    """A helper to get the channels that are supported in TFQ.

    Returns a dictionary mapping from supported channel types
    to number of qubits.
    """
    # Add new channels here whenever additional support is needed.
    channel_mapping = dict()
    channel_mapping[cirq.DepolarizingChannel(0.01)] = 1
    channel_mapping[cirq.AsymmetricDepolarizingChannel(0.01, 0.02, 0.03)] = 1
    channel_mapping[cirq.AmplitudeDampingChannel(0.01)] = 1
    channel_mapping[cirq.ResetChannel()] = 1

    return channel_mapping
示例#5
0
def test_aggregate_decay_noise_after_moment():
    program = cirq.Circuit()
    qubits = cirq.LineQubit.range(3)
    program.append([
        cirq.H(qubits[0]),
        cirq.CNOT(qubits[0], qubits[1]),
        cirq.CNOT(qubits[1], qubits[2])
    ])
    program.append(
        [
            cirq.measure(qubits[0], key='q0'),
            cirq.measure(qubits[1], key='q1'),
            cirq.measure(qubits[2], key='q2'),
        ],
        strategy=cirq.InsertStrategy.NEW_THEN_INLINE,
    )

    # Use noise model to generate circuit
    noise_model = ccn.DepolarizingWithDampedReadoutNoiseModel(
        depol_prob=0.01, decay_prob=0.02, bitflip_prob=0.05)
    noisy_circuit = cirq.Circuit(noise_model.noisy_moments(program, qubits))

    # Insert channels explicitly
    true_noisy_program = cirq.Circuit()
    true_noisy_program.append([cirq.H(qubits[0])])
    true_noisy_program.append(
        [cirq.DepolarizingChannel(0.01).on(q) for q in qubits],
        strategy=cirq.InsertStrategy.NEW_THEN_INLINE,
    )
    true_noisy_program.append([cirq.CNOT(qubits[0], qubits[1])])
    true_noisy_program.append(
        [cirq.DepolarizingChannel(0.01).on(q) for q in qubits],
        strategy=cirq.InsertStrategy.NEW_THEN_INLINE,
    )
    true_noisy_program.append([cirq.CNOT(qubits[1], qubits[2])])
    true_noisy_program.append(
        [cirq.DepolarizingChannel(0.01).on(q) for q in qubits],
        strategy=cirq.InsertStrategy.NEW_THEN_INLINE,
    )
    true_noisy_program.append(
        [cirq.AmplitudeDampingChannel(0.02).on(q) for q in qubits])
    true_noisy_program.append(
        [cirq.BitFlipChannel(0.05).on(q) for q in qubits])
    true_noisy_program.append([
        cirq.measure(qubits[0], key='q0'),
        cirq.measure(qubits[1], key='q1'),
        cirq.measure(qubits[2], key='q2'),
    ])
    assert_equivalent_op_tree(true_noisy_program, noisy_circuit)
示例#6
0
    def markovianity(self):
        if self.bath_type == 'Markovian':

            # Dissipative dynamics
            self.c.append(cirq.AmplitudeDampingChannel(gamma=1).on_each(
                *self.bath_qubits),
                          strategy=cirq.InsertStrategy.NEW)
            self.partition_function(operation="Append")

        elif self.bath_type == 'non-Markovian':
            pass
        else:
            raise TypeError(
                "bath_type must be either \"Markovian\" or \"non-Markovian\", not \"{0}\" "
                .format(self.bath_type))
示例#7
0
    def grovers_step_oqs(self):
        """

        Adds one iteration of Grover's algorithm to the circuit.
        This is in the style of Keshav and Matt's circuit, as opposed to more frequent interactions.
        oqs stands for "open quantum system"

        """

        # oqs
        self.bath_append()

        # Boolean oracle from ArXiV[1703.10535]
        self.append_oracle()

        # oqs
        self.bath_append()

        # diffusion operator
        self.c.append(cirq.H.on_each(*self.computation_qubits))
        self.c.append(cirq.X.on_each(*self.computation_qubits))
        ncz = cirq.ControlledGate(cirq.Z,
                                  num_controls=self.n_computation_qubits - 1)  # phase flip gate; ncz => n-controlled Z
        self.c.append(ncz.on(*self.computation_qubits))
        self.c.append(cirq.X.on_each(*self.computation_qubits))
        self.c.append(cirq.H.on_each(*self.computation_qubits))

        # loss from the bath and reinitialization
        if self.bath_type == 'Markovian':

            # Dissipative dynamics
            self.c.append(cirq.AmplitudeDampingChannel(gamma=1).on_each(*self.bath_qubits), strategy=cirq.InsertStrategy.NEW)
            self.partition_function(operation="Append")

        elif self.bath_type == 'non-Markovian':
            pass
        else:
            raise TypeError(
                "bath_type must be either \"Markovian\" or \"non-Markovian\", not \"{0}\" ".format(self.bath_type))
示例#8
0
def test_amplitude_damping_channel_repr():
    cirq.testing.assert_equivalent_repr(cirq.AmplitudeDampingChannel(0.3))
示例#9
0
文件: json_test.py 项目: c-poole/Cirq
    }
    """)
    buffer.seek(0)

    with pytest.raises(ValueError) as e:
        cirq.read_json(buffer)
    assert e.match("Could not resolve type 'MyCustomClass' "
                   "during deserialization")


QUBITS = cirq.LineQubit.range(5)
Q0, Q1, Q2, Q3, Q4 = QUBITS

TEST_OBJECTS = {
    'AmplitudeDampingChannel':
    cirq.AmplitudeDampingChannel(0.5),
    'AsymmetricDepolarizingChannel':
    cirq.AsymmetricDepolarizingChannel(0.1, 0.2, 0.3),
    'BitFlipChannel':
    cirq.BitFlipChannel(0.5),
    'Bristlecone':
    cirq.google.Bristlecone,
    'CCNOT':
    cirq.CCNOT,
    'CCX':
    cirq.CCX,
    'CCXPowGate':
    cirq.CCXPowGate(exponent=0.123, global_shift=0.456),
    'CCZ':
    cirq.CCZ,
    'CCZPowGate':
示例#10
0
 def __init__(self, depol_prob: float, bitflip_prob: float,
              decay_prob: float):
     self.qubit_noise_gate = cirq.DepolarizingChannel(depol_prob)
     self.readout_noise_gate = cirq.BitFlipChannel(bitflip_prob)
     self.readout_decay_gate = cirq.AmplitudeDampingChannel(decay_prob)