def test_cphase_compatability(self): cz_op_nz = lib.cphase(angle=np.pi, leakage_rate=0, leakage_phase=-np.pi / 2, integrate_idling=False, model='NetZero') cz_op_legacy = lib.cphase(angle=np.pi, leakage_rate=0, integrate_idling=False, model='legacy') b = (cz_op_nz.bases_in, cz_op_nz.bases_out) assert np.allclose(cz_op_nz.ptm(*b), cz_op_legacy.ptm(*b)) input_leakage_rate = 0.001 cz_op_nz = lib.cphase(angle=np.pi, leakage_rate=input_leakage_rate, leakage_phase=-np.pi / 2, integrate_idling=False, model='netzero') cz_op_legacy = lib.cphase(angle=np.pi, leakage_rate=4 * input_leakage_rate, integrate_idling=False, model='legacy') assert np.allclose(cz_op_nz.ptm(*b), cz_op_legacy.ptm(*b))
def test_zz_parity_compilation(self): b_full = bases.general(3) b0 = b_full.subbasis([0]) b01 = b_full.subbasis([0, 1]) b012 = b_full.subbasis([0, 1, 2]) bases_in = (b01, b01, b0) bases_out = (b_full, b_full, b012) zz = Operation.from_sequence( lib3.rotate_x(-np.pi / 2).at(2), lib3.cphase(leakage_rate=0.1).at(0, 2), lib3.cphase(leakage_rate=0.25).at(2, 1), lib3.rotate_x(np.pi / 2).at(2), lib3.rotate_x(np.pi).at(0), lib3.rotate_x(np.pi).at(1)) zz_ptm = zz.ptm(bases_in, bases_out) zzc = zz.compile(bases_in=bases_in, bases_out=bases_out) zzc_ptm = zzc.ptm(bases_in, bases_out) assert zz_ptm == approx(zzc_ptm) assert len(zzc.operations) == 2 op1, ix1 = zzc.operations[0] op2, ix2 = zzc.operations[1] assert ix1 == (0, 2) assert ix2 == (1, 2) assert op1.bases_in[0] == bases_in[0] assert op2.bases_in[0] == bases_in[1] assert op1.bases_in[1] == bases_in[2] # Qubit 0 did not leak assert op1.bases_out[0] == bases_out[0].subbasis([0, 1, 3, 4]) # Qubit 1 leaked assert op2.bases_out[0] == bases_out[1].subbasis([0, 1, 2, 6]) # Qubit 2 is measured assert op2.bases_out[1] == bases_out[2] dm = random_hermitian_matrix(3**3, seed=85) pv1 = PauliVector.from_dm(dm, (b01, b01, b0)) pv2 = PauliVector.from_dm(dm, (b01, b01, b0)) zz(pv1, 0, 1, 2) zzc(pv2, 0, 1, 2) # Compiled version still needs to be projected, so we can't compare # Pauli vectors, so we can to check only DM diagonals. assert np.allclose(pv1.diagonal(), pv2.diagonal())
def test_zz_parity_compilation(self): b_full = bases.general(3) b0 = b_full.subbasis([0]) b01 = b_full.subbasis([0, 1]) b012 = b_full.subbasis([0, 1, 2]) bases_in = (b01, b01, b0) bases_out = (b_full, b_full, b012) zz = Operation.from_sequence( lib3.rotate_x(-np.pi/2).at(2), lib3.cphase(leakage=0.1).at(0, 2), lib3.cphase(leakage=0.25).at(2, 1), lib3.rotate_x(np.pi/2).at(2), lib3.rotate_x(np.pi).at(0), lib3.rotate_x(np.pi).at(1) ) zzc = zz.compile(bases_in=bases_in, bases_out=bases_out) assert len(zzc.operations) == 2 op1, ix1 = zzc.operations[0] op2, ix2 = zzc.operations[1] assert ix1 == (0, 2) assert ix2 == (1, 2) assert op1.bases_in[0] == bases_in[0] assert op2.bases_in[0] == bases_in[1] assert op1.bases_in[1] == bases_in[2] # Qubit 0 did not leak assert op1.bases_out[0] == bases_out[0].subbasis([0, 1, 3, 4]) # Qubit 1 leaked assert op2.bases_out[0] == bases_out[1].subbasis([0, 1, 2, 6]) # Qubit 2 is measured assert op2.bases_out[1] == bases_out[2] dm = random_density_matrix(3**3, seed=85) state1 = State.from_dm(dm, (b01, b01, b0)) state2 = State.from_dm(dm, (b01, b01, b0)) zz(state1, 0, 1, 2) zzc(state2, 0, 1, 2) # Compiled version still needs to be projected, so we can't compare # Pauli vectors, so we can to check only DM diagonals. assert np.allclose(state1.diagonal(), state2.diagonal())
def test_chain_compile_leaking(self): b = bases.general(3) chain0 = Operation.from_sequence( lib3.rotate_x(0.5*np.pi).at(2), lib3.cphase(leakage=0.1).at(0, 2), lib3.cphase(leakage=0.1).at(1, 2), lib3.rotate_x(-0.75*np.pi).at(2), lib3.rotate_x(0.25*np.pi).at(2), ) b0 = b.subbasis([0]) b01 = b.subbasis([0, 1]) b0134 = b.subbasis([0, 1, 3, 4]) chain1 = chain0.compile((b0, b0, b0134), (b, b, b)) # Ancilla is not leaking here anc_basis = chain1.operations[1].operation.bases_out[1] for label in anc_basis.labels: assert '2' not in label chain2 = chain0.compile((b01, b01, b0134), (b, b, b)) # Ancilla is leaking here anc_basis = chain2.operations[1].operation.bases_out[1] for label in '2', 'X20', 'Y20', 'X21', 'Y21': assert label in anc_basis.labels