From 18987e012905253d39343f8ade4a2c54045744b9 Mon Sep 17 00:00:00 2001 From: Jun Doi Date: Tue, 14 May 2024 17:06:26 +0900 Subject: [PATCH] fix tests for the latest Qiskit (#2138) --- test/terra/backends/aer_simulator/test_chunk.py | 5 ++++- test/terra/primitives/test_sampler_v2.py | 10 ++++++++-- test/terra/states/test_aer_densitymatrix.py | 8 ++++---- test/terra/states/test_aer_statevector.py | 10 +++++----- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/test/terra/backends/aer_simulator/test_chunk.py b/test/terra/backends/aer_simulator/test_chunk.py index ca4c20d90b..23dad5589d 100644 --- a/test/terra/backends/aer_simulator/test_chunk.py +++ b/test/terra/backends/aer_simulator/test_chunk.py @@ -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) @@ -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) diff --git a/test/terra/primitives/test_sampler_v2.py b/test/terra/primitives/test_sampler_v2.py index 0fe645e263..ecf9cc6048 100644 --- a/test/terra/primitives/test_sampler_v2.py +++ b/test/terra/primitives/test_sampler_v2.py @@ -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 = [] @@ -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])) @@ -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])) diff --git a/test/terra/states/test_aer_densitymatrix.py b/test/terra/states/test_aer_densitymatrix.py index 61aacb20cc..55a1a26a86 100644 --- a/test/terra/states/test_aer_densitymatrix.py +++ b/test/terra/states/test_aer_densitymatrix.py @@ -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""" diff --git a/test/terra/states/test_aer_statevector.py b/test/terra/states/test_aer_statevector.py index 0a78d681d5..0b11b1681d 100644 --- a/test/terra/states/test_aer_statevector.py +++ b/test/terra/states/test_aer_statevector.py @@ -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"""