25
25
import quimb .tensor as qtn
26
26
27
27
from cirq import devices , protocols , qis , value
28
- from cirq ._compat import deprecated
28
+ from cirq ._compat import deprecated_parameter
29
29
from cirq .sim import simulator_base
30
30
from cirq .sim .act_on_args import ActOnArgs
31
31
@@ -53,9 +53,7 @@ class MPSOptions:
53
53
54
54
55
55
class MPSSimulator (
56
- simulator_base .SimulatorBase [
57
- 'MPSSimulatorStepResult' , 'MPSTrialResult' , 'MPSState' , 'MPSState'
58
- ],
56
+ simulator_base .SimulatorBase ['MPSSimulatorStepResult' , 'MPSTrialResult' , 'MPSState' , 'MPSState' ]
59
57
):
60
58
"""An efficient simulator for MPS circuits."""
61
59
@@ -83,10 +81,7 @@ def __init__(
83
81
raise ValueError (f'noise must be unitary or mixture but was { noise_model } ' )
84
82
self .simulation_options = simulation_options
85
83
self .grouping = grouping
86
- super ().__init__ (
87
- noise = noise ,
88
- seed = seed ,
89
- )
84
+ super ().__init__ (noise = noise , seed = seed )
90
85
91
86
def _create_partial_act_on_args (
92
87
self ,
@@ -120,10 +115,7 @@ def _create_partial_act_on_args(
120
115
classical_data = classical_data ,
121
116
)
122
117
123
- def _create_step_result (
124
- self ,
125
- sim_state : 'cirq.OperationTarget[MPSState]' ,
126
- ):
118
+ def _create_step_result (self , sim_state : 'cirq.OperationTarget[MPSState]' ):
127
119
return MPSSimulatorStepResult (sim_state )
128
120
129
121
def _create_simulator_trial_result (
@@ -182,10 +174,7 @@ def _repr_pretty_(self, p: Any, cycle: bool):
182
174
class MPSSimulatorStepResult (simulator_base .StepResultBase ['MPSState' , 'MPSState' ]):
183
175
"""A `StepResult` that can perform measurements."""
184
176
185
- def __init__ (
186
- self ,
187
- sim_state : 'cirq.OperationTarget[MPSState]' ,
188
- ):
177
+ def __init__ (self , sim_state : 'cirq.OperationTarget[MPSState]' ):
189
178
"""Results of a step of the simulator.
190
179
Attributes:
191
180
sim_state: The qubit:ActOnArgs lookup for this step.
@@ -576,6 +565,19 @@ def sample(
576
565
class MPSState (ActOnArgs ):
577
566
"""A state of the MPS simulation."""
578
567
568
+ @deprecated_parameter (
569
+ deadline = 'v0.16' ,
570
+ fix = 'Use kwargs instead of positional args' ,
571
+ parameter_desc = 'args' ,
572
+ match = lambda args , kwargs : len (args ) > 1 ,
573
+ )
574
+ @deprecated_parameter (
575
+ deadline = 'v0.16' ,
576
+ fix = 'Replace log_of_measurement_results with'
577
+ ' classical_data=cirq.ClassicalDataDictionaryStore(_records=logs).' ,
578
+ parameter_desc = 'log_of_measurement_results' ,
579
+ match = lambda args , kwargs : 'log_of_measurement_results' in kwargs ,
580
+ )
579
581
def __init__ (
580
582
self ,
581
583
qubits : Sequence ['cirq.Qid' ],
@@ -614,13 +616,16 @@ def __init__(
614
616
simulation_options = simulation_options ,
615
617
grouping = {qubit_map [k ]: v for k , v in final_grouping .items ()},
616
618
)
617
- super ().__init__ (
618
- state = state ,
619
- prng = prng ,
620
- qubits = qubits ,
621
- log_of_measurement_results = log_of_measurement_results ,
622
- classical_data = classical_data ,
623
- )
619
+ if log_of_measurement_results is not None :
620
+ super ().__init__ (
621
+ state = state ,
622
+ prng = prng ,
623
+ qubits = qubits ,
624
+ log_of_measurement_results = log_of_measurement_results ,
625
+ classical_data = classical_data ,
626
+ )
627
+ else :
628
+ super ().__init__ (state = state , prng = prng , qubits = qubits , classical_data = classical_data )
624
629
self ._state : _MPSHandler = state
625
630
626
631
def i_str (self , i : int ) -> str :
@@ -665,21 +670,8 @@ def to_numpy(self) -> np.ndarray:
665
670
"""An alias for the state vector."""
666
671
return self ._state .to_numpy ()
667
672
668
- @deprecated (deadline = "v0.15" , fix = "Use cirq.act_on(op, mps_state)" )
669
- def apply_op (self , op : 'cirq.Operation' , prng : np .random .RandomState ):
670
- """Applies a unitary operation, mutating the object to represent the new state.
671
-
672
- op:
673
- The operation that mutates the object. Note that currently, only 1-
674
- and 2- qubit operations are currently supported.
675
- """
676
- return self ._state .apply_op (op , self .get_axes (op .qubits ), prng )
677
-
678
673
def _act_on_fallback_ (
679
- self ,
680
- action : Any ,
681
- qubits : Sequence ['cirq.Qid' ],
682
- allow_decompose : bool = True ,
674
+ self , action : Any , qubits : Sequence ['cirq.Qid' ], allow_decompose : bool = True
683
675
) -> bool :
684
676
"""Delegates the action to self.apply_op"""
685
677
return self ._state .apply_op (action , self .get_axes (qubits ), self .prng )
@@ -691,21 +683,3 @@ def estimation_stats(self):
691
683
@property
692
684
def M (self ):
693
685
return self ._state ._M
694
-
695
- @deprecated (deadline = "v0.15" , fix = "Use cirq.act_on(measurement, mps_state)" )
696
- def perform_measurement (
697
- self , qubits : Sequence ['cirq.Qid' ], prng : np .random .RandomState , collapse_state_vector = True
698
- ) -> List [int ]:
699
- """Performs a measurement over one or more qubits.
700
-
701
- Args:
702
- qubits: The sequence of qids to measure, in that order.
703
- prng: A random number generator, used to simulate measurements.
704
- collapse_state_vector: A Boolean specifying whether we should mutate
705
- the state after the measurement.
706
-
707
- Raises:
708
- ValueError: If the probabilities for the measurements differ too much from one for the
709
- tolerance specified in simulation options.
710
- """
711
- return self ._state ._measure (self .get_axes (qubits ), prng , collapse_state_vector )
0 commit comments