File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ def apply_general_gate(
6666 "gate" : gate ,
6767 "index" : index ,
6868 "name" : name ,
69- "split" : False ,
69+ "split" : None ,
7070 "mpo" : False ,
7171 }
7272 ir_dict = kws ["ir_dict" ]
@@ -89,6 +89,22 @@ def apply_general_gate(
8989
9090 apply = apply_general_gate
9191
92+ def random_gate (self , * index : int , recorded : bool = False ) -> None :
93+ """
94+ Apply a random Clifford gate to the circuit.
95+ This operation will not record in qir
96+
97+ :param index: Qubit indices to apply the gate to
98+ :type index: int
99+ :param recorded: Whether the gate is recorded in ``stim.Circuit``, defaults to False
100+ :type recorded: bool, optional
101+ """
102+ m = len (index )
103+ t = stim .Tableau .random (m )
104+ self .current_sim .do_tableau (t , index )
105+ if recorded :
106+ self ._stim_circuit += t .to_circuit ()
107+
92108 def measure (self , * index : int , with_prob : bool = False ) -> Tensor :
93109 """
94110 Measure qubits in Z basis.
Original file line number Diff line number Diff line change @@ -134,3 +134,24 @@ def test_to_openqasm():
134134
135135 c1 = tc .StabilizerCircuit .from_openqasm (qasm )
136136 print (c1 .draw ())
137+
138+
139+ def test_ee ():
140+ c = tc .Circuit (8 )
141+ for i in range (3 ):
142+ c .h (i )
143+ c .cx (i , i + 4 )
144+ c .sd (i + 2 )
145+ ee0 = tc .quantum .entanglement_entropy (c .state (), list (range (4 )))
146+ c1 = tc .StabilizerCircuit .from_openqasm (c .to_openqasm ())
147+ ee1 = c1 .entanglement_entropy (list (range (4 )))
148+ np .testing .assert_allclose (ee0 , ee1 , atol = 1e-6 )
149+
150+
151+ def test_random_gates ():
152+ c = tc .StabilizerCircuit (4 )
153+ c .random_gate (0 , 1 , recorded = True )
154+ c .random_gate (2 , 3 )
155+ c .random_gate (1 , 2 )
156+ print (c .entanglement_entropy (list (range (2 ))))
157+ print (len (c .current_circuit ()))
You can’t perform that action at this time.
0 commit comments