Skip to content

Commit

Permalink
fix sub_dims bug in _get_iq_data (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
rupeshknn authored Jan 12, 2024
1 parent 27a804a commit d1cf278
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion qiskit_dynamics/backend/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _get_iq_data(
QiskitError: If number of centers and levels don't match.
"""
rng = np.random.default_rng(seed)
subsystem_dims = state.dims()
subsystem_dims = [dim for dim in state.dims() if dim != 1]
probabilities = state.probabilities()
probabilities_tensor = probabilities.reshape(list(reversed(subsystem_dims)))

Expand Down
21 changes: 19 additions & 2 deletions test/dynamics/backend/test_backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_basic_predict(self):
self.assertDictEqual(counts, {"0": 100})

def test_multi_qubit_predict(self):
"""Multi_qubit predict test case."""
"""Multi qubit predict test case."""
iq_data = _get_iq_data(
state=Statevector(np.array([0.5, 1, 0, 0]) / np.sqrt(1.25)),
measurement_subsystems=[0, 1],
Expand All @@ -297,8 +297,25 @@ def test_multi_qubit_predict(self):
self.assertDictEqual(counts0, {"0": 74, "1": 26})
self.assertDictEqual(counts1, {"1": 100})

def test_multi_qubit_with_1d_subsystem(self):
"""Multi qubit with 1d (trivial) subsystems."""
iq_data = _get_iq_data(
state=Statevector(np.array([0.5, 1, 0, 0]) / np.sqrt(1.25), dims=(1, 1, 2, 2, 1, 1)),
measurement_subsystems=[0, 1],
iq_centers=[[(1, 0), (-1, 0)], [(1, 0), (-1, 0)]],
iq_width=0.1,
shots=100,
memory_slot_indices=[0, 1],
seed=83248,
)

counts0 = self.iq_to_counts(iq_data[:, 0, :])
counts1 = self.iq_to_counts(iq_data[:, 1, :])
self.assertDictEqual(counts0, {"0": 74, "1": 26})
self.assertDictEqual(counts1, {"1": 100})

def test_mixed_subsystem_predict(self):
"""Multi_qubit predict test case."""
"""Multi qubit predict test case."""
iq_data = _get_iq_data(
state=Statevector(
np.kron(np.array([0.5, 1]), np.array([0, 0, 1])) / np.sqrt(1.25), dims=(3, 2)
Expand Down

0 comments on commit d1cf278

Please sign in to comment.