@@ -63,3 +63,76 @@ def main():
6363"""
6464
6565 assert out == expected
66+
67+
68+ def test_loss ():
69+
70+ @qasm2 .extended
71+ def main ():
72+ qreg = qasm2 .qreg (4 )
73+
74+ qasm2 .cx (qreg [0 ], qreg [1 ])
75+ qasm2 .u (qreg [2 ], theta = 0.1 , phi = 0.2 , lam = 0.3 )
76+
77+ noise .native .atom_loss_channel (qargs = [qreg [0 ], qreg [1 ]], prob = 0.2 )
78+
79+ qasm2 .u (qreg [2 ], theta = 0.1 , phi = 0.2 , lam = 0.3 )
80+
81+ main .print ()
82+
83+ target = qasm2 .emit .QASM2 (allow_noise = True )
84+ out = target .emit_str (main )
85+
86+ expected = """OPENQASM 2.0;
87+ include "qelib1.inc";
88+ qreg qreg[4];
89+ CX qreg[0], qreg[1];
90+ U(0.1, 0.2, 0.3) qreg[2];
91+ // native.Atomloss(p=0.2)
92+ // -: qargs: qreg[0], qreg[1]
93+ U(0.1, 0.2, 0.3) qreg[2];
94+ """
95+
96+ assert out == expected
97+
98+
99+ def test_cz_noise ():
100+
101+ @qasm2 .extended
102+ def main ():
103+ qreg = qasm2 .qreg (4 )
104+
105+ qasm2 .cx (qreg [0 ], qreg [1 ])
106+ qasm2 .u (qreg [2 ], theta = 0.1 , phi = 0.2 , lam = 0.3 )
107+
108+ noise .native .cz_pauli_channel (
109+ ctrls = [qreg [0 ], qreg [1 ]],
110+ qargs = [qreg [2 ], qreg [3 ]],
111+ px_ctrl = 0.1 ,
112+ py_ctrl = 0.2 ,
113+ pz_ctrl = 0.3 ,
114+ px_qarg = 0.4 ,
115+ py_qarg = 0.5 ,
116+ pz_qarg = 0.6 ,
117+ paired = True ,
118+ )
119+
120+ qasm2 .u (qreg [2 ], theta = 0.1 , phi = 0.2 , lam = 0.3 )
121+
122+ main .print ()
123+
124+ target = qasm2 .emit .QASM2 (allow_noise = True )
125+ out = target .emit_str (main )
126+ print (out )
127+ expected = """OPENQASM 2.0;
128+ include "qelib1.inc";
129+ qreg qreg[4];
130+ CX qreg[0], qreg[1];
131+ U(0.1, 0.2, 0.3) qreg[2];
132+ // native.CZPauliChannel(paired=True, p_ctrl=[x:0.1, y:0.2, z:0.3], p_qarg[x:0.6, y:0.5, z:0.6])
133+ // -: ctrls: qreg[0], qreg[1]
134+ // -: qargs: qreg[2], qreg[3]
135+ U(0.1, 0.2, 0.3) qreg[2];
136+ """
137+
138+ assert out == expected
0 commit comments