Skip to content

Commit

Permalink
working on initial_state type cases
Browse files Browse the repository at this point in the history
  • Loading branch information
shef4 committed Feb 13, 2024
1 parent 1c16227 commit 9e0b4d0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cirq-core/cirq/sim/classical_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


from typing import Dict, Generic, Any, Sequence, TYPE_CHECKING, List, Union
from typing import Dict, Generic, Any, Sequence, Optional, List, Union, TYPE_CHECKING
from cirq import ops, qis
from cirq.value import big_endian_int_to_bits
from cirq.ops.raw_types import Qid
Expand Down Expand Up @@ -64,7 +64,12 @@ def __init__(
classical_data: The shared classical data container for this
simulation.
"""
state = ClassicalBasisState(big_endian_int_to_bits(initial_state, bit_count=len(qubits)))
if not isinstance(initial_state, np.ndarray):
if qubits is None:
raise ValueError('qubits must be provided if initial_state is not ndarray')
state = ClassicalBasisState(big_endian_int_to_bits(initial_state, bit_count=len(qubits)))
else:
state = ClassicalBasisState(initial_state)
super().__init__(state=state, qubits=qubits, classical_data=classical_data)

def _act_on_fallback_(self, action, qubits: Sequence[Qid], allow_decompose: bool = True):
Expand Down

0 comments on commit 9e0b4d0

Please sign in to comment.