@@ -210,29 +210,26 @@ func (m *Matrix) PartialTrace(qb ...int) *Matrix {
210210}
211211
212212// Depolarizing returns the depolarizing channel.
213- // It applies the identity with probability (1 - p),
214- // and applies each of the Pauli gates X, Y, and Z with probability p/3.
213+ // It applies the identity with probability (1 - p), and applies each of the Pauli gates X, Y, and Z with probability p/3.
215214func (m * Matrix ) Depolarizing (p float64 , qb int ) * Matrix {
216215 n := m .NumQubits ()
217216
218- idx := []int {qb }
219- id := m .rho .Mul (complex (1 - p , 0 ))
220- xg := gate .TensorProduct (gate .X (), n , idx )
221- yg := gate .TensorProduct (gate .Y (), n , idx )
222- zg := gate .TensorProduct (gate .Z (), n , idx )
217+ xg := gate .TensorProduct (gate .X (), n , []int {qb })
218+ yg := gate .TensorProduct (gate .Y (), n , []int {qb })
219+ zg := gate .TensorProduct (gate .Z (), n , []int {qb })
223220
224221 x := matrix .MatMul (xg , m .rho , xg .Dagger ()).Mul (complex (p / 3 , 0 ))
225222 y := matrix .MatMul (yg , m .rho , yg .Dagger ()).Mul (complex (p / 3 , 0 ))
226223 z := matrix .MatMul (zg , m .rho , zg .Dagger ()).Mul (complex (p / 3 , 0 ))
227224
228225 return & Matrix {
229- rho : id .Add (x ).Add (y ).Add (z ),
226+ rho : m . rho . Mul ( complex ( 1 - p , 0 )) .Add (x ).Add (y ).Add (z ),
230227 }
231228}
232229
233- // ApplyChannel applies a channel to the density matrix.
230+ // FlipChannel applies a channel to the density matrix.
234231// It applies the identity with probability 1-p, and applies the gate g with probability p.
235- func (m * Matrix ) ApplyChannel (p float64 , u * matrix.Matrix , qb ... int ) * Matrix {
232+ func (m * Matrix ) FlipChannel (p float64 , u * matrix.Matrix , qb ... int ) * Matrix {
236233 n := m .NumQubits ()
237234
238235 e0 := gate .I ().Mul (complex (math .Sqrt (1 - p ), 0 ))
@@ -252,17 +249,17 @@ func (m *Matrix) ApplyChannel(p float64, u *matrix.Matrix, qb ...int) *Matrix {
252249
253250// BitFlip applies a bit flip channel to the density matrix.
254251func (m * Matrix ) BitFlip (p float64 , qb int ) * Matrix {
255- return m .ApplyChannel (p , gate .X (), qb )
252+ return m .FlipChannel (p , gate .X (), qb )
256253}
257254
258255// BitPhaseFlip applies a bit-phase flip channel to the density matrix.
259256func (m * Matrix ) BitPhaseFlip (p float64 , qb int ) * Matrix {
260- return m .ApplyChannel (p , gate .Y (), qb )
257+ return m .FlipChannel (p , gate .Y (), qb )
261258}
262259
263260// PhaseFlip applies a phase flip channel to the density matrix.
264261func (m * Matrix ) PhaseFlip (p float64 , qb int ) * Matrix {
265- return m .ApplyChannel (p , gate .Z (), qb )
262+ return m .FlipChannel (p , gate .Z (), qb )
266263}
267264
268265// split separates the bits of x into two integers according to mask.
0 commit comments