Noisy simulator

Note

Every time that a Circuit is run on a Simulator, the results are overwritten.

import trueq as tq
import numpy as np

# Define the circuit we are interested in
circuit = tq.Circuit({0: tq.Gate.x, 1: tq.Gate.y}, {(0, 1): tq.Gate.cz})
circuit.measure_all()

# Initialize a noiseless simulator.
sim0 = tq.Simulator()

# Initialize a simulator with depolarizing noise at 8% per qubit.
sim1 = tq.Simulator().add_depolarizing(p=0.08)

# Initialize a simulator with pauli noise and overrotation.
sim2 = (
    tq.Simulator()
    .add_stochastic_pauli(px=0.01, py=0.02)
    .add_overrotation(single_sys=0.04)
)

# Initialize a simulator with dephasing noise.
kraus_ops = [np.sqrt(0.99) * np.eye(2), np.sqrt(0.01) * np.diag([1, -1])]
sim3 = tq.Simulator().add_kraus(kraus_ops)

# Initialize a simulator with state preparation and measurement errors
sim4 = tq.Simulator().add_prep({None: 0.03}).add_readout_error(0.01)
# Run circuit on each of the simulators above and print the results.
sim0.run(circuit)
print(f"{'Ideal':>28}:", circuit.results)

Out:

Ideal: Results({'11': 50})
sim1.run(circuit, overwrite=True)
print(f"{'Depolarizing':>28}:", circuit.results)

Out:

Depolarizing: Results({'01': 1, '10': 3, '11': 46})
sim2.run(circuit, overwrite=True)
print(f"{'Stochastic w/ overrotation':>28}:", circuit.results)

Out:

Stochastic w/ overrotation: Results({'01': 2, '10': 1, '11': 47})
sim3.run(circuit, overwrite=True)
print(f"{'Dephasing':>28}:", circuit.results)

Out:

Dephasing: Results({'11': 50})
sim4.run(circuit, overwrite=True)
print(f"{'SPAM Error':>28}:", circuit.results)

Out:

SPAM Error: Results({'01': 1, '11': 49})

Total running time of the script: ( 0 minutes 0.010 seconds)

Gallery generated by Sphinx-Gallery