def test_decoherence_noise(): prog = Program(RX(np.pi / 2, 0), CZ(0, 1), RZ(np.pi, 0)) gates = _get_program_gates(prog) m1 = _decoherence_noise_model(gates, T1=INFINITY, T2=INFINITY, ro_fidelity=1.) # with no readout error, assignment_probs = identity matrix assert np.allclose(m1.assignment_probs[0], np.eye(2)) assert np.allclose(m1.assignment_probs[1], np.eye(2)) for g in m1.gates: # with infinite coherence time all kraus maps should only have a single, unitary kraus op assert len(g.kraus_ops) == 1 k0, = g.kraus_ops # check unitarity k0dk0 = k0.dot(k0.conjugate().transpose()) assert np.allclose(k0dk0, np.eye(k0dk0.shape[0])) # verify that selective (by qubit) dephasing and readout infidelity is working m2 = _decoherence_noise_model(gates, T1=INFINITY, T2={0: 30e-6}, ro_fidelity={ 0: .95, 1: 1.0 }) assert np.allclose(m2.assignment_probs[0], [[.95, 0.05], [.05, .95]]) assert np.allclose(m2.assignment_probs[1], np.eye(2)) for g in m2.gates: if 0 in g.targets: # single dephasing (no damping) channel on qc 0, no noise on qc1 -> 2 Kraus ops assert len(g.kraus_ops) == 2 else: assert len(g.kraus_ops) == 1 # verify that combined T1 and T2 will lead to 4 outcome Kraus map. m3 = _decoherence_noise_model(gates, T1={0: 30e-6}, T2={0: 30e-6}) for g in m3.gates: if 0 in g.targets: # damping (implies dephasing) channel on qc 0, no noise on qc1 -> 4 Kraus ops assert len(g.kraus_ops) == 4 else: assert len(g.kraus_ops) == 1 # verify that gate names are translated new_prog = apply_noise_model(prog, m3) new_gates = _get_program_gates(new_prog) # check that headers have been embedded headers = _noise_model_program_header(m3) assert all( (isinstance(i, Pragma) and i.command in ["ADD-KRAUS", "READOUT-POVM"]) or isinstance(i, DefGate) for i in headers) assert headers.out() in new_prog.out() # verify that high-level add_decoherence_noise reproduces new_prog new_prog2 = add_decoherence_noise(prog, T1={0: 30e-6}, T2={0: 30e-6}) assert new_prog == new_prog2
def test_apply_noise_model(): p = Program(RX(np.pi / 2, 0), RX(np.pi / 2, 1), CZ(0, 1), RX(np.pi / 2, 1)) noise_model = _decoherence_noise_model(_get_program_gates(p)) pnoisy = apply_noise_model(p, noise_model) for i in pnoisy: if isinstance(i, DefGate): pass elif isinstance(i, Pragma): assert i.command in ['ADD-KRAUS', 'READOUT-POVM'] elif isinstance(i, Gate): assert i.name in NO_NOISE or not i.params
def test_apply_noise_model_perturbed_angles(): eps = 1e-15 p = Program(RX(np.pi / 2 + eps, 0), RX(np.pi / 2 - eps, 1), CZ(0, 1), RX(np.pi / 2 + eps, 1)) noise_model = _decoherence_noise_model(_get_program_gates(p)) pnoisy = apply_noise_model(p, noise_model) for i in pnoisy: if isinstance(i, DefGate): pass elif isinstance(i, Pragma): assert i.command in ["ADD-KRAUS", "READOUT-POVM"] elif isinstance(i, Gate): assert i.name in NO_NOISE or not i.params
def decoherance_noise_with_asymettric_ro(isa: ISA): """Reimplementation of `add_decoherance_noise` with asymmetric readout. For simplicity, we use the default values for T1, T2, gate times, et al. and hard-code readout fidelities here. """ gates = gates_in_isa(isa) noise_model = _decoherence_noise_model(gates) p00 = 0.975 p11 = 0.911 aprobs = np.array([[p00, 1 - p00], [1 - p11, p11]]) aprobs = {q: aprobs for q in noise_model.assignment_probs.keys()} return NoiseModel(noise_model.gates, aprobs)
def noise_model(self, dev: device.Device) -> noise.NoiseModel: return noise._decoherence_noise_model(gates=device.gates_in_isa( dev.get_isa()), T1=300e-6, T2=300e-6, ro_fidelity=0.99)