Skip to content

Commit

Permalink
fix tests for the latest Qiskit (#2138)
Browse files Browse the repository at this point in the history
  • Loading branch information
doichanj authored May 14, 2024
1 parent 83c1445 commit 18987e0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
5 changes: 4 additions & 1 deletion test/terra/backends/aer_simulator/test_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TestChunkSimulators(SimulatorTestCase):
def test_chunk_QuantumVolume(self, method, device):
"""Test multi-chunk with quantum volume"""
opts = {"blocking_enable": True, "blocking_qubits": 2}
opts["basis_gates"] = ["h", "cx", "u3"]

backend = self.backend(method=method, device=device, **opts)
backend_no_chunk = self.backend(method=method, device=device)
Expand All @@ -57,10 +58,12 @@ def test_chunk_QuantumVolumeWithFusion(self, method, device):
opts_no_chunk = {
"fusion_enable": True,
"fusion_threshold": 5,
"fusion_max_qubit": 4,
}
opts_chunk = copy.copy(opts_no_chunk)
opts_chunk["blocking_enable"] = True
opts_chunk["blocking_qubits"] = 4
opts_chunk["blocking_qubits"] = 5
opts_chunk["basis_gates"] = ["h", "cx", "u3"]

backend = self.backend(method=method, device=device, **opts_chunk)
backend_no_chunk = self.backend(method=method, device=device, **opts_no_chunk)
Expand Down
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(self, 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(self.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(self.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
8 changes: 4 additions & 4 deletions test/terra/states/test_aer_densitymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ def test_QFT(self):
self.assertEqual(1, len(counts))
self.assertTrue("0000" in counts)

def test_single_qubit_QV(self):
def test_two_qubit_QV(self):
"""Test single qubit QuantumVolume"""
state = AerDensityMatrix(QuantumVolume(1))
state = AerDensityMatrix(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 evolve method for circuits"""
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 18987e0

Please sign in to comment.