@@ -38,7 +38,7 @@ def _is_identity(action) -> bool:
38
38
class ClassicalBasisState (qis .QuantumStateRepresentation ):
39
39
"""Represents a classical basis state for efficient state evolution."""
40
40
41
- def __init__ (self , initial_state : list [int ] | np .ndarray ):
41
+ def __init__ (self , initial_state : Sequence [int ] | np .ndarray ):
42
42
"""Initializes the ClassicalBasisState object.
43
43
44
44
Args:
@@ -85,21 +85,19 @@ def __init__(
85
85
86
86
Args:
87
87
qubits: The qubits to simulate.
88
- initial_state: The initial state for the simulation. Accepts int or a sequence of int.
88
+ initial_state: The initial state for the simulation. Accepts int or Sequence[ int] .
89
89
classical_data: The classical data container for the simulation.
90
90
91
91
Raises:
92
92
ValueError: If qubits not provided and initial_state is int.
93
- If initial_state is not an int, list[int], tuple [int], or np.ndarray .
93
+ If initial_state is not an int or Sequence [int].
94
94
If initial_state is a np.ndarray and its shape is not 1-dimensional.
95
- If gate is not one of X, SWAP, QubitPermutationGate, a controlled version
96
- of X or SWAP, or a measurement.
97
95
98
96
An initial_state value of type integer is parsed in big endian order.
99
97
"""
100
98
if isinstance (initial_state , int ):
101
99
if qubits is None :
102
- raise ValueError ('qubits must be provided if initial_state is not list [int]' )
100
+ raise ValueError ('qubits must be provided if initial_state is not Sequence [int]' )
103
101
state = ClassicalBasisState (
104
102
big_endian_int_to_bits (initial_state , bit_count = len (qubits ))
105
103
)
@@ -109,10 +107,10 @@ def __init__(
109
107
f'initial_state must be 1-dimensional, got shape { initial_state .shape } '
110
108
)
111
109
state = ClassicalBasisState (list (initial_state ))
112
- elif isinstance (initial_state , ( list , tuple )):
110
+ elif isinstance (initial_state , Sequence ) and not isinstance ( initial_state , ( str , bytes )):
113
111
state = ClassicalBasisState (list (initial_state ))
114
112
else :
115
- raise ValueError ('initial_state must be an int, list[int], tuple [int], or np.ndarray ' )
113
+ raise ValueError ('initial_state must be an int or Sequence [int]' )
116
114
super ().__init__ (state = state , qubits = qubits , classical_data = classical_data )
117
115
118
116
def _act_on_fallback_ (self , action , qubits : Sequence [cirq .Qid ], allow_decompose : bool = True ):
@@ -125,6 +123,10 @@ def _act_on_fallback_(self, action, qubits: Sequence[cirq.Qid], allow_decompose:
125
123
126
124
Returns:
127
125
True if the operation was applied successfully.
126
+
127
+ Raises:
128
+ ValueError: If gate is not one of X, SWAP, QubitPermutationGate, a controlled version
129
+ of X or SWAP, or a measurement.
128
130
"""
129
131
gate = action .gate if isinstance (action , ops .Operation ) else action
130
132
mapped_qubits = [self .qubit_map [i ] for i in qubits ]
0 commit comments