Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sub_dims bug in _get_iq_data #297

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading