Skip to content

Commit

Permalink
fix recent test failures with the latest qiskit
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii committed May 13, 2024
1 parent 87b1a92 commit 965c75c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions test/terra/primitives/test_sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ def test_circuit_with_unitary(self):
self.assertEqual(len(result), 1)
self._assert_allclose(result[0].data.meas, np.array({1: self._shots}))

def get_data_bin_len(data):
if "keys" in dir(data): # qiskit 1.1 or later
return len(data.keys())
else:
return len(astuple(data))

def test_circuit_with_multiple_cregs(self):
"""Test for circuit with multiple classical registers."""
cases = []
Expand Down Expand Up @@ -581,7 +587,7 @@ def test_circuit_with_multiple_cregs(self):
result = sampler.run([qc], shots=self._shots).result()
self.assertEqual(len(result), 1)
data = result[0].data
self.assertEqual(len(astuple(data)), 3)
self.assertEqual(get_data_bin_len(data), 3)
for creg in qc.cregs:
self.assertTrue(hasattr(data, creg.name))
self._assert_allclose(getattr(data, creg.name), np.array(target[creg.name]))
Expand Down Expand Up @@ -614,7 +620,7 @@ def test_circuit_with_aliased_cregs(self):
result = sampler.run([qc2], shots=self._shots).result()
self.assertEqual(len(result), 1)
data = result[0].data
self.assertEqual(len(astuple(data)), 3)
self.assertEqual(get_data_bin_len(data), 3)
for creg_name in target:
self.assertTrue(hasattr(data, creg_name))
self._assert_allclose(getattr(data, creg_name), np.array(target[creg_name]))
Expand Down
10 changes: 5 additions & 5 deletions test/terra/states/test_aer_statevector.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def test_QFT(self):
self.assertEqual(1, len(counts))
self.assertTrue("0000" in counts)

def test_single_qubit_QV(self):
"""Test single qubit QuantumVolume"""
state = AerStatevector(QuantumVolume(1))
def test_two_qubit_QV(self):
"""Test two qubit QuantumVolume"""
state = AerStatevector(QuantumVolume(2))
counts = state.sample_counts(shots=1024)
self.assertEqual(1, len(counts))
self.assertTrue("0" in counts)
self.assertEqual(4, len(counts))
self.assertTrue("00" in counts)

def test_evolve(self):
"""Test method and device properties"""
Expand Down

0 comments on commit 965c75c

Please sign in to comment.