1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- import warnings
16- from typing import Dict , List , Optional , Sequence , Tuple , Union
15+ from typing import Dict , List , Sequence , Tuple , Union
1716
1817import cirq
1918import numpy as np
@@ -159,7 +158,7 @@ def _translate_MatrixGate(gate: cirq.MatrixGate):
159158 return qsim .kMatrixGate
160159 raise NotImplementedError (
161160 f"Received matrix on { gate .num_qubits ()} qubits; "
162- + "only up to 6-qubit gates are supported."
161+ "only up to 6-qubit gates are supported."
163162 )
164163
165164
@@ -219,17 +218,17 @@ def _control_details(
219218 assignments = list (gate .control_values .expand ())
220219 if len (qubits ) > 1 and len (assignments ) > 1 :
221220 raise ValueError (
222- f"Cannot translate controlled gate with multiple assignments for multiple qubits: { gate } "
221+ "Cannot translate controlled gate with multiple assignments for "
222+ f"multiple qubits: { gate } "
223223 )
224224 for q , cvs in zip (qubits , zip (* assignments )):
225225 if 0 in cvs and 1 in cvs :
226226 # This qubit does not affect control.
227227 continue
228228 elif any (cv not in (0 , 1 ) for cv in cvs ):
229229 raise ValueError (
230- f"Cannot translate control values other than 0 and 1: cvs={ cvs } "
231- )
232- # Either 0 or 1 is in cvs, but not both.
230+ f"Cannot translate control values other than 0 and 1: { cvs = } "
231+ ) # Either 0 or 1 is in cvs, but not both.
233232 control_qubits .append (q )
234233 if 0 in cvs :
235234 control_values .append (0 )
@@ -247,7 +246,7 @@ def add_op_to_opstring(
247246 """Adds an operation to an opstring (observable).
248247
249248 Raises:
250- ValueError if qsim_op is not a single-qubit Pauli (I, X, Y, or Z).
249+ ValueError if qsim_op is not a single-qubit Pauli (I, X, Y, or Z).
251250 """
252251 qsim_gate = qsim_op .gate
253252 gate_kind = _cirq_gate_kind (qsim_gate )
@@ -258,7 +257,7 @@ def add_op_to_opstring(
258257
259258 is_controlled = isinstance (qsim_gate , cirq .ControlledGate )
260259 if is_controlled :
261- raise ValueError (f "OpString ops should not be controlled." )
260+ raise ValueError ("OpString ops should not be controlled." )
262261
263262 qubits = [qubit_to_index_dict [q ] for q in qsim_op .qubits ]
264263 qsim .add_gate_to_opstring (gate_kind , qubits , opstring )
@@ -289,7 +288,7 @@ def add_op_to_circuit(
289288 if num_targets > 4 :
290289 raise NotImplementedError (
291290 f"Received control gate on { num_targets } target qubits; "
292- + "only up to 4-qubit gates are supported."
291+ "only up to 4-qubit gates are supported."
293292 )
294293
295294 qsim_qubits = qubits [qsim_gate .num_controls () :]
@@ -366,8 +365,10 @@ def _resolve_parameters_(
366365
367366 def _check_for_confusion_matrix (self ):
368367 """Checks cirq Circuit for Measurement Gates with confusion matrices.
368+
369369 Returns:
370- Throws a runtime exception if a MeasurementGate with a confusion matrix is included in the circuit
370+ Throws a runtime exception if a MeasurementGate with a confusion
371+ matrix is included in the circuit.
371372 """
372373 confusion_maps_on_measurement_gates = [
373374 op .gate .confusion_map
@@ -377,14 +378,14 @@ def _check_for_confusion_matrix(self):
377378 if confusion_maps_on_measurement_gates :
378379 raise ValueError (
379380 "Confusion Matrices are not currently supported in Qsim. "
380- "See https://github.com/quantumlib/Cirq/issues/6305 for latest status"
381+ "See https://github.com/quantumlib/Cirq/issues/6305 "
382+ "for latest status"
381383 )
382384
383385 def translate_cirq_to_qsim (
384386 self , qubit_order : cirq .QubitOrderOrList = cirq .QubitOrder .DEFAULT
385387 ) -> qsim .Circuit :
386- """
387- Translates this Cirq circuit to the qsim representation.
388+ """Translates this Cirq circuit to the qsim representation.
388389 :qubit_order: Ordering of qubits
389390 :return: a tuple of (C++ qsim Circuit object, moment boundary
390391 gate indices)
@@ -436,8 +437,7 @@ def to_matrix(op: cirq.GateOperation):
436437 def translate_cirq_to_qtrajectory (
437438 self , qubit_order : cirq .QubitOrderOrList = cirq .QubitOrder .DEFAULT
438439 ) -> qsim .NoisyCircuit :
439- """
440- Translates this noisy Cirq circuit to the qsim representation.
440+ """Translates this noisy Cirq circuit to the qsim representation.
441441 :qubit_order: Ordering of qubits
442442 :return: a tuple of (C++ qsim NoisyCircuit object, moment boundary
443443 gate indices)
@@ -476,15 +476,12 @@ def to_matrix(op: cirq.GateOperation):
476476 )
477477 ops_by_gate .append (oplist )
478478 moment_length = max (moment_length , len (oplist ))
479- pass
480479 elif cirq .has_mixture (qsim_op ):
481480 ops_by_mix .append (qsim_op )
482481 moment_length = max (moment_length , 1 )
483- pass
484482 elif cirq .has_kraus (qsim_op ):
485483 ops_by_channel .append (qsim_op )
486484 moment_length = max (moment_length , 1 )
487- pass
488485 else :
489486 raise ValueError (f"Encountered unparseable op: { qsim_op } " )
490487
0 commit comments