Skip to content

Commit 77a0370

Browse files
authored
Delete the target_tensor parameter that was deprecated in 0.15 (#5225)
A few simulators used either initial_state or target_tensor to initialize their ActOnArgs. We deprecated the latter in 0.15. This PR deletes those. Note that one follow-on change included here is that the repr functions needed to be changed to emit the field as `initial_state` too. (I wish I'd just called it `quantum_state` now, but oh well). @95-martin-orion I also went ahead and removed the buffer from the repr, since it is just noise.
1 parent f1ea0bd commit 77a0370

7 files changed

+9
-53
lines changed

cirq-core/cirq/sim/act_on_density_matrix_args.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,9 @@ class ActOnDensityMatrixArgs(ActOnArgs):
245245
parameter_desc='log_of_measurement_results',
246246
match=lambda args, kwargs: 'log_of_measurement_results' in kwargs or len(args) > 5,
247247
)
248-
@_compat.deprecated_parameter(
249-
deadline='v0.15',
250-
fix='Use initial_state instead.',
251-
parameter_desc='target_tensor',
252-
match=lambda args, kwargs: 'target_tensor' in kwargs,
253-
)
254248
def __init__(
255249
self,
256250
*,
257-
target_tensor: Optional[np.ndarray] = None,
258251
available_buffer: Optional[List[np.ndarray]] = None,
259252
qid_shape: Optional[Tuple[int, ...]] = None,
260253
prng: Optional[np.random.RandomState] = None,
@@ -267,9 +260,6 @@ def __init__(
267260
"""Inits ActOnDensityMatrixArgs.
268261
269262
Args:
270-
target_tensor: The state vector to act on, stored as a numpy array
271-
with one dimension for each qubit in the system. Operations are
272-
expected to perform inplace edits of this object.
273263
available_buffer: A workspace with the same shape and dtype as
274264
`target_tensor`. Used by operations that cannot be applied to
275265
`target_tensor` inline, in order to avoid unnecessary
@@ -295,7 +285,7 @@ def __init__(
295285
and `qid_shape` is not provided.
296286
"""
297287
state = _BufferedDensityMatrix.create(
298-
initial_state=target_tensor if target_tensor is not None else initial_state,
288+
initial_state=initial_state,
299289
qid_shape=tuple(q.dimension for q in qubits) if qubits is not None else None,
300290
dtype=dtype,
301291
buffer=available_buffer,
@@ -338,8 +328,7 @@ def _act_on_fallback_(
338328
def __repr__(self) -> str:
339329
return (
340330
'cirq.ActOnDensityMatrixArgs('
341-
f'target_tensor={proper_repr(self.target_tensor)},'
342-
f' available_buffer={proper_repr(self.available_buffer)},'
331+
f'initial_state={proper_repr(self.target_tensor)},'
343332
f' qid_shape={self.qid_shape!r},'
344333
f' qubits={self.qubits!r},'
345334
f' log_of_measurement_results={proper_repr(self.log_of_measurement_results)})'

cirq-core/cirq/sim/act_on_density_matrix_args_test.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ def test_shallow_copy_buffers():
4444
assert copy.available_buffer is args.available_buffer
4545

4646

47-
def test_deprecated_warning_and_default_parameter_error():
48-
tensor = np.ndarray(shape=(2,))
49-
with cirq.testing.assert_deprecated('Use initial_state instead', deadline='v0.15'):
50-
with pytest.raises(ValueError, match='dimension of target_tensor is not divisible by 2'):
51-
cirq.ActOnDensityMatrixArgs(target_tensor=tensor)
52-
53-
5447
def test_decomposed_fallback():
5548
class Composite(cirq.Gate):
5649
def num_qubits(self) -> int:

cirq-core/cirq/sim/act_on_state_vector_args.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,9 @@ class ActOnStateVectorArgs(ActOnArgs):
343343
parameter_desc='log_of_measurement_results',
344344
match=lambda args, kwargs: 'log_of_measurement_results' in kwargs or len(args) > 4,
345345
)
346-
@_compat.deprecated_parameter(
347-
deadline='v0.15',
348-
fix='Use initial_state instead.',
349-
parameter_desc='target_tensor',
350-
match=lambda args, kwargs: 'target_tensor' in kwargs,
351-
)
352346
def __init__(
353347
self,
354348
*,
355-
target_tensor: Optional[np.ndarray] = None,
356349
available_buffer: Optional[np.ndarray] = None,
357350
prng: Optional[np.random.RandomState] = None,
358351
log_of_measurement_results: Optional[Dict[str, List[int]]] = None,
@@ -364,9 +357,6 @@ def __init__(
364357
"""Inits ActOnStateVectorArgs.
365358
366359
Args:
367-
target_tensor: The state vector to act on, stored as a numpy array
368-
with one dimension for each qubit in the system. Operations are
369-
expected to perform inplace edits of this object.
370360
available_buffer: A workspace with the same shape and dtype as
371361
`target_tensor`. Used by operations that cannot be applied to
372362
`target_tensor` inline, in order to avoid unnecessary
@@ -388,7 +378,7 @@ def __init__(
388378
simulation.
389379
"""
390380
state = _BufferedStateVector.create(
391-
initial_state=target_tensor if target_tensor is not None else initial_state,
381+
initial_state=initial_state,
392382
qid_shape=tuple(q.dimension for q in qubits) if qubits is not None else None,
393383
dtype=dtype,
394384
buffer=available_buffer,
@@ -506,8 +496,7 @@ def _act_on_fallback_(
506496
def __repr__(self) -> str:
507497
return (
508498
'cirq.ActOnStateVectorArgs('
509-
f'target_tensor={proper_repr(self.target_tensor)},'
510-
f' available_buffer={proper_repr(self.available_buffer)},'
499+
f'initial_state={proper_repr(self.target_tensor)},'
511500
f' qubits={self.qubits!r},'
512501
f' log_of_measurement_results={proper_repr(self.log_of_measurement_results)})'
513502
)

cirq-core/cirq/sim/act_on_state_vector_args_test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ def test_default_parameter():
3939
assert args.available_buffer.dtype == tensor.dtype
4040

4141

42-
def test_deprecated_target_tensor():
43-
with cirq.testing.assert_deprecated('Use initial_state instead', deadline='v0.15'):
44-
cirq.ActOnStateVectorArgs(target_tensor=np.array([1.0, 0.0, 0.0, 0.0], dtype=np.complex64))
45-
46-
4742
def test_infer_target_tensor():
4843
dtype = np.complex64
4944
args = cirq.ActOnStateVectorArgs(

cirq-core/cirq/sim/clifford/act_on_stabilizer_ch_form_args.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,11 @@ class ActOnStabilizerCHFormArgs(
3333
deadline='v0.15',
3434
fix='Use classical_data.',
3535
parameter_desc='log_of_measurement_results',
36-
match=lambda args, kwargs: 'log_of_measurement_results' in kwargs or len(args) > 3,
37-
)
38-
@_compat.deprecated_parameter(
39-
deadline='v0.15',
40-
fix='Use initial_state instead of state.',
41-
parameter_desc='state',
42-
match=lambda args, kwargs: 'state' in kwargs,
36+
match=lambda args, kwargs: 'log_of_measurement_results' in kwargs,
4337
)
4438
def __init__(
4539
self,
4640
*,
47-
state: Optional['cirq.StabilizerStateChForm'] = None,
4841
prng: Optional[np.random.RandomState] = None,
4942
log_of_measurement_results: Optional[Dict[str, List[int]]] = None,
5043
qubits: Optional[Sequence['cirq.Qid']] = None,
@@ -75,7 +68,6 @@ def __init__(
7568
ValueError: If initial state is an integer but qubits are not
7669
provided.
7770
"""
78-
initial_state = state or initial_state
7971
if isinstance(initial_state, int):
8072
if qubits is None:
8173
raise ValueError('Must specify qubits if initial state is integer')

cirq-core/cirq/sim/density_matrix_simulator_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,15 +1075,14 @@ def test_density_matrix_trial_result_repr():
10751075
"measurements={'m': np.array([[1]], dtype=np.int32)}, "
10761076
"final_step_result=cirq.DensityMatrixStepResult("
10771077
"sim_state=cirq.ActOnDensityMatrixArgs("
1078-
"target_tensor=np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.complex64), "
1079-
"available_buffer=[], "
1078+
"initial_state=np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.complex64), "
10801079
"qid_shape=(2,), "
10811080
"qubits=(cirq.LineQubit(0),), "
10821081
"log_of_measurement_results={}), "
10831082
"dtype=np.complex64))"
10841083
)
10851084
assert repr(trial_result) == expected_repr
1086-
with cirq.testing.assert_deprecated('Use initial_state instead', deadline='v0.15', count=2):
1085+
with cirq.testing.assert_deprecated('log_of_measurement_results', deadline='v0.15'):
10871086
assert eval(expected_repr) == trial_result
10881087

10891088

cirq-core/cirq/sim/state_vector_simulator_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@ def test_state_vector_trial_result_repr():
4141
"measurements={'m': np.array([[1]], dtype=np.int32)}, "
4242
"final_step_result=cirq.SparseSimulatorStep("
4343
"sim_state=cirq.ActOnStateVectorArgs("
44-
"target_tensor=np.array([0j, (1+0j)], dtype=np.complex64), "
45-
"available_buffer=np.array([0j, (1+0j)], dtype=np.complex64), "
44+
"initial_state=np.array([0j, (1+0j)], dtype=np.complex64), "
4645
"qubits=(cirq.NamedQubit('a'),), "
4746
"log_of_measurement_results={}), "
4847
"dtype=np.complex64))"
4948
)
5049
assert repr(trial_result) == expected_repr
51-
with cirq.testing.assert_deprecated('Use initial_state instead', deadline='v0.15', count=2):
50+
with cirq.testing.assert_deprecated('log_of_measurement_results', deadline='v0.15'):
5251
assert eval(expected_repr) == trial_result
5352

5453

0 commit comments

Comments
 (0)