Repository: quantumlib/Cirq

Issue:
Unused qid_shape in DensityMatrixSimState constructor
**Description of the issue**

`qid_shape` is a parameter of `DensityMatrixSimulationState.__init__` but is not used.

**Cirq version**
v0.15


Discussion:

Resolving patch:
diff --git a/cirq-core/cirq/sim/density_matrix_simulation_state.py b/cirq-core/cirq/sim/density_matrix_simulation_state.py
--- a/cirq-core/cirq/sim/density_matrix_simulation_state.py
+++ b/cirq-core/cirq/sim/density_matrix_simulation_state.py
@@ -247,7 +247,6 @@ def __init__(
         self,
         *,
         available_buffer: Optional[List[np.ndarray]] = None,
-        qid_shape: Optional[Tuple[int, ...]] = None,
         prng: Optional[np.random.RandomState] = None,
         qubits: Optional[Sequence['cirq.Qid']] = None,
         initial_state: Union[np.ndarray, 'cirq.STATE_VECTOR_LIKE'] = 0,
@@ -264,7 +263,6 @@ def __init__(
             qubits: Determines the canonical ordering of the qubits. This
                 is often used in specifying the initial state, i.e. the
                 ordering of the computational basis states.
-            qid_shape: The shape of the target tensor.
             prng: The pseudo random number generator to use for probabilistic
                 effects.
             initial_state: The initial state for the simulation in the
@@ -276,8 +274,8 @@ def __init__(
                 simulation.
 
         Raises:
-            ValueError: The dimension of `target_tensor` is not divisible by 2
-                and `qid_shape` is not provided.
+            ValueError: If `initial_state` is provided as integer, but `qubits`
+                is not provided.
         """
         state = _BufferedDensityMatrix.create(
             initial_state=initial_state,
@@ -314,7 +312,6 @@ def __repr__(self) -> str:
         return (
             'cirq.DensityMatrixSimulationState('
             f'initial_state={proper_repr(self.target_tensor)},'
-            f' qid_shape={self.qid_shape!r},'
             f' qubits={self.qubits!r},'
             f' classical_data={self.classical_data!r})'
         )


Test patch:
diff --git a/cirq-core/cirq/sim/density_matrix_simulator_test.py b/cirq-core/cirq/sim/density_matrix_simulator_test.py
--- a/cirq-core/cirq/sim/density_matrix_simulator_test.py
+++ b/cirq-core/cirq/sim/density_matrix_simulator_test.py
@@ -952,7 +952,7 @@ def test_density_matrix_step_result_repr():
         )
         == "cirq.DensityMatrixStepResult(sim_state=cirq.DensityMatrixSimulationState("
         "initial_state=np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.complex64), "
-        "qid_shape=(2,), qubits=(cirq.LineQubit(0),), "
+        "qubits=(cirq.LineQubit(0),), "
         "classical_data=cirq.ClassicalDataDictionaryStore()), dtype=np.complex64)"
     )
 
@@ -1021,7 +1021,6 @@ def test_density_matrix_trial_result_repr():
     dtype = np.complex64
     final_simulator_state = cirq.DensityMatrixSimulationState(
         available_buffer=[],
-        qid_shape=(2,),
         prng=np.random.RandomState(0),
         qubits=[q0],
         initial_state=np.ones((2, 2), dtype=dtype) * 0.5,
@@ -1038,7 +1037,6 @@ def test_density_matrix_trial_result_repr():
         "measurements={'m': np.array([[1]], dtype=np.int32)}, "
         "final_simulator_state=cirq.DensityMatrixSimulationState("
         "initial_state=np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.complex64), "
-        "qid_shape=(2,), "
         "qubits=(cirq.LineQubit(0),), "
         "classical_data=cirq.ClassicalDataDictionaryStore()))"
     )
@@ -1109,7 +1107,6 @@ def test_density_matrix_trial_result_str():
     dtype = np.complex64
     final_simulator_state = cirq.DensityMatrixSimulationState(
         available_buffer=[],
-        qid_shape=(2,),
         prng=np.random.RandomState(0),
         qubits=[q0],
         initial_state=np.ones((2, 2), dtype=dtype) * 0.5,
@@ -1134,7 +1131,6 @@ def test_density_matrix_trial_result_repr_pretty():
     dtype = np.complex64
     final_simulator_state = cirq.DensityMatrixSimulationState(
         available_buffer=[],
-        qid_shape=(2,),
         prng=np.random.RandomState(0),
         qubits=[q0],
         initial_state=np.ones((2, 2), dtype=dtype) * 0.5,