quantum icon indicating copy to clipboard operation
quantum copied to clipboard

Multi qubit noise channels and noisy training.

Open L-P-B opened this issue 3 years ago • 1 comments

Hi there,

Sorry for the noob question.

Is is possible to define multi qubit noise channels and use tfq to do noisy training?

My work flow is similar to that of the tutorials with noise, but instead I'm trying to define the channel

cirq.asymmetric_depolarize(error_probabilities={'XX': 0.1})

This throws errors which vanish upon removing this channel.

Thanks!

Max

L-P-B avatar Apr 26 '22 22:04 L-P-B

Hi, I'm also learning and I had the same problem, testing a neural network on a noisy circuit. This is what worked for me, using tfq.layers.NoisyControlledPQC:

controller = tf.keras.Sequential([
    tf.keras.layers.Dense(10, activation='elu'),
    tf.keras.layers.Dense(2)
])

circuits_input = tf.keras.Input(shape=(),
                                # The circuit-tensor has dtype `tf.string` 
                                dtype=tf.string,
                                name='circuits_input')

commands_input = tf.keras.Input(shape=(1,),
                                dtype=tf.dtypes.float32,
                                name='commands_input')

dense_2 = controller(commands_input)

expectation_layer = tfq.layers.NoisyControlledPQC(model_circuit.with_noise(cirq.bit_flip(p=0.05)),
                                             operators = [cirq.Z(qubit),cirq.Z(qubit)],repetitions=5000,sample_based=True)

expectation = expectation_layer([circuits_input, dense_2])

model = tf.keras.Model(inputs=[circuits_input, commands_input],
                       outputs=expectation)

This was the circuit:

def make_GHZ_withbitflips(num_qubits,measurements=True):
    myqubits = cirq.LineQubit.range(num_qubits)
    GHZ_circuit = cirq.Circuit([
        cirq.Moment([cirq.H(myqubits[0])]),
        cirq.rx(a).on(q0),
        
    cirq.ry(b).on(q1),cirq.ry(a).on(q2), cirq.CNOT(control=q2, target=q3), cirq.CNOT(control=q1, target=q0)
    ])

    for x in range(num_qubits-1):
        GHZ_circuit.append([cirq.CNOT(myqubits[x],myqubits[x+1]),cirq.bit_flip(p=0.1)(myqubits[x+1])])

    if measurements:
        GHZ_circuit.append(cirq.Moment(cirq.measure_each(*myqubits)))
    return GHZ_circuit

model_circuit=make_GHZ_withbitflips(5)

RubensZimbres avatar Aug 17 '22 01:08 RubensZimbres