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

Update remaining unit tests to use FakeGeneric #10918

Merged
merged 28 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d0a9647
Update V2 tests to use FakeGeneric or GenericTarget
ElePT Nov 23, 2023
f227917
Add missing tests and fixes
ElePT Nov 24, 2023
07f4213
Fix calibrations and adjust tests
ElePT Nov 30, 2023
548d084
Fix remaining tests
ElePT Nov 30, 2023
6569f29
Merge branch 'main' into fake-backends
ElePT Nov 30, 2023
bee2a2d
Add test_backend_v2 test
ElePT Nov 30, 2023
96fe781
Add Aer check to sparse_pauli_op test
ElePT Dec 1, 2023
a2ceed7
Fix noise defaults
ElePT Dec 4, 2023
ec4180a
Fix value
ElePT Dec 4, 2023
0d9509c
Merge branch 'main' into fake-backends
ElePT Dec 4, 2023
d1d98f9
Fix lint
ElePT Dec 4, 2023
56f4fba
Delete spurious files
ElePT Dec 5, 2023
fd7ac1a
Merge from main
ElePT Jan 29, 2024
518f2a2
Update class names, fix conflicts post-merge.
ElePT Jan 30, 2024
23a3d4d
Extract coupling maps, improve style
ElePT Jan 30, 2024
8b705fb
Fix passmanager test
ElePT Jan 30, 2024
a0e8d5b
More test fixes
ElePT Jan 30, 2024
2768e27
New attempt at fixing tests
ElePT Jan 30, 2024
5e57a10
Please, mr. backend_estimator test, give me a break and reproduce my …
ElePT Jan 30, 2024
724a6c5
Trying again
ElePT Jan 30, 2024
0f903e4
Apply suggestions from Kevin's code review
ElePT Jan 31, 2024
b21961c
Move cmaps to new file, fix black
ElePT Jan 31, 2024
31d5fc1
Merge branch 'main' of https://github.com/Qiskit/qiskit into fake-bac…
ElePT Jan 31, 2024
54ebd80
Fix tests
ElePT Jan 31, 2024
a68a293
Replace FakeBackendSimple with BasicSimulator
ElePT Jan 31, 2024
5a38910
Merge branch 'main' of https://github.com/Qiskit/qiskit into fake-bac…
ElePT Jan 31, 2024
9f7775b
Fix passmanager config test
ElePT Jan 31, 2024
025a11d
Fix seed for vf2 layout tests
ElePT Jan 31, 2024
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
10 changes: 5 additions & 5 deletions qiskit/providers/fake_provider/generic_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ def _get_calibration_sequence(
name="acquire",
duration=1792,
t0=0,
qubits=list(range(num_qubits)),
memory_slot=list(range(num_qubits)),
qubits=qargs,
memory_slot=qargs,
)
] + [PulseQobjInstruction(name=pulse_library[1], ch=f"m{i}", t0=0) for i in qargs]
] + [PulseQobjInstruction(name=pulse_library[1].name, ch=f"m{i}", t0=0) for i in qargs]
return sequence
if num_qubits == 1:
return [
PulseQobjInstruction(name="fc", ch=f"u{qargs}", t0=0, phase="-P0"),
PulseQobjInstruction(name=pulse_library[0].name, ch=f"d{qargs}", t0=0),
PulseQobjInstruction(name="fc", ch=f"u{qargs[0]}", t0=0, phase="-P0"),
PulseQobjInstruction(name=pulse_library[0].name, ch=f"d{qargs[0]}", t0=0),
]
return [
PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[0]}", t0=0),
Expand Down
194 changes: 194 additions & 0 deletions test/python/legacy_cmaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Coupling maps for fake backend generation and transpiler testing."""

# 5 qubits
# bidirectional
BOGOTA_CMAP = [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]]
LIMA_CMAP = [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]]
YORKTOWN_CMAP = [
[0, 1],
[0, 2],
[1, 0],
[1, 2],
[2, 0],
[2, 1],
[2, 3],
[2, 4],
[3, 2],
[3, 4],
[4, 2],
[4, 3],
]
# directional
TENERIFE_CMAP = [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]]

# 16 qubits
RUESCHLIKON_CMAP = [
[1, 0],
[1, 2],
[2, 3],
[3, 4],
[3, 14],
[5, 4],
[6, 5],
[6, 7],
[6, 11],
[7, 10],
[8, 7],
[9, 8],
[9, 10],
[11, 10],
[12, 5],
[12, 11],
[12, 13],
[13, 4],
[13, 14],
[15, 0],
[15, 2],
[15, 14],
]

# 20 qubits
TOKYO_CMAP = [
[0, 1],
[0, 5],
[1, 0],
[1, 2],
[1, 6],
[1, 7],
[2, 1],
[2, 6],
[3, 8],
[4, 8],
[4, 9],
[5, 0],
[5, 6],
[5, 10],
[5, 11],
[6, 1],
[6, 2],
[6, 5],
[6, 7],
[6, 10],
[6, 11],
[7, 1],
[7, 6],
[7, 8],
[7, 12],
[8, 3],
[8, 4],
[8, 7],
[8, 9],
[8, 12],
[8, 13],
[9, 4],
[9, 8],
[10, 5],
[10, 6],
[10, 11],
[10, 15],
[11, 5],
[11, 6],
[11, 10],
[11, 12],
[11, 16],
[11, 17],
[12, 7],
[12, 8],
[12, 11],
[12, 13],
[12, 16],
[13, 8],
[13, 12],
[13, 14],
[13, 18],
[13, 19],
[14, 13],
[14, 18],
[14, 19],
[15, 10],
[15, 16],
[16, 11],
[16, 12],
[16, 15],
[16, 17],
[17, 11],
[17, 16],
[17, 18],
[18, 13],
[18, 14],
[18, 17],
[19, 13],
[19, 14],
]

# 27 qubits
MUMBAI_CMAP = [
[0, 1],
[1, 0],
[1, 2],
[1, 4],
[2, 1],
[2, 3],
[3, 2],
[3, 5],
[4, 1],
[4, 7],
[5, 3],
[5, 8],
[6, 7],
[7, 4],
[7, 6],
[7, 10],
[8, 5],
[8, 9],
[8, 11],
[9, 8],
[10, 7],
[10, 12],
[11, 8],
[11, 14],
[12, 10],
[12, 13],
[12, 15],
[13, 12],
[13, 14],
[14, 11],
[14, 13],
[14, 16],
[15, 12],
[15, 18],
[16, 14],
[16, 19],
[17, 18],
[18, 15],
[18, 17],
[18, 21],
[19, 16],
[19, 20],
[19, 22],
[20, 19],
[21, 18],
[21, 23],
[22, 19],
[22, 25],
[23, 21],
[23, 24],
[24, 23],
[24, 25],
[25, 22],
[25, 24],
[25, 26],
[26, 25],
]
34 changes: 20 additions & 14 deletions test/python/primitives/test_backend_estimator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
# (C) Copyright IBM 2022, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -10,7 +10,7 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Tests for Estimator."""
"""Tests for BackendEstimator."""

import unittest
from unittest.mock import patch
Expand All @@ -21,8 +21,8 @@
from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import RealAmplitudes
from qiskit.primitives import BackendEstimator, EstimatorResult
from qiskit.providers.fake_provider import FakeNairobi, FakeNairobiV2
from qiskit.providers.fake_provider.fake_backend_v2 import FakeBackendSimple
from qiskit.providers.fake_provider import FakeNairobi, GenericBackendV2
from qiskit.providers.backend_compat import BackendV2Converter
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler import PassManager
from qiskit.utils import optionals
Expand All @@ -31,7 +31,11 @@
from test.python.transpiler._dummy_passes import DummyAP # pylint: disable=wrong-import-order


BACKENDS = [FakeNairobi(), FakeNairobiV2(), FakeBackendSimple()]
BACKENDS = [
FakeNairobi(),
ElePT marked this conversation as resolved.
Show resolved Hide resolved
BackendV2Converter(FakeNairobi()),
GenericBackendV2(num_qubits=5, seed=42),
]


class CallbackPass(DummyAP):
Expand Down Expand Up @@ -271,14 +275,14 @@ def test_options(self, backend):
def test_job_size_limit_v2(self):
"""Test BackendEstimator respects job size limit"""

class FakeNairobiLimitedCircuits(FakeNairobiV2):
"""FakeNairobiV2 with job size limit."""
class FakeBackendLimitedCircuits(GenericBackendV2):
"""Generic backend V2 with job size limit."""

@property
def max_circuits(self):
return 1

backend = FakeNairobiLimitedCircuits()
backend = FakeBackendLimitedCircuits(num_qubits=5)
backend.set_options(seed_simulator=123)
qc = RealAmplitudes(num_qubits=2, reps=2)
op = SparsePauliOp.from_list([("IZ", 1), ("XI", 2), ("ZY", -1)])
Expand Down Expand Up @@ -387,10 +391,11 @@ def test_layout(self, backend):
estimator = BackendEstimator(backend)
estimator.set_transpile_options(seed_transpiler=15)
value = estimator.run(qc, op, shots=10000).result().values[0]
if optionals.HAS_AER and not isinstance(backend, FakeBackendSimple):
self.assertEqual(value, -0.916)
if optionals.HAS_AER:
ref_value = -0.9922 if isinstance(backend, GenericBackendV2) else -0.916
else:
self.assertEqual(value, -1)
ref_value = -1
self.assertEqual(value, ref_value)

with self.subTest("final layout test"):
qc = QuantumCircuit(3)
Expand All @@ -402,10 +407,11 @@ def test_layout(self, backend):
estimator = BackendEstimator(backend)
estimator.set_transpile_options(initial_layout=[0, 1, 2], seed_transpiler=15)
value = estimator.run(qc, op, shots=10000).result().values[0]
if optionals.HAS_AER and not isinstance(backend, FakeBackendSimple):
self.assertEqual(value, -0.8902)
if optionals.HAS_AER:
ref_value = -0.9922 if isinstance(backend, GenericBackendV2) else -0.8902
else:
self.assertEqual(value, -1)
ref_value = -1
self.assertEqual(value, ref_value)

@unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test")
def test_circuit_with_measurement(self):
Expand Down
14 changes: 9 additions & 5 deletions test/python/primitives/test_backend_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from qiskit.circuit.library import RealAmplitudes
from qiskit.primitives import BackendSampler, SamplerResult
from qiskit.providers import JobStatus
from qiskit.providers.fake_provider import FakeNairobi, FakeNairobiV2
from qiskit.providers.fake_provider import FakeNairobi, GenericBackendV2
from qiskit.providers.backend_compat import BackendV2Converter
from qiskit.providers.basic_provider import BasicSimulator
from qiskit.transpiler import PassManager
from qiskit.utils import optionals
Expand All @@ -31,7 +32,10 @@
from test.python.transpiler._dummy_passes import DummyAP # pylint: disable=wrong-import-order


BACKENDS = [FakeNairobi(), FakeNairobiV2()]
BACKENDS = [
FakeNairobi(),
BackendV2Converter(FakeNairobi()),
]


class CallbackPass(DummyAP):
Expand Down Expand Up @@ -298,8 +302,8 @@ def test_primitive_job_status_done(self, backend):
def test_primitive_job_size_limit_backend_v2(self):
"""Test primitive respects backend's job size limit."""

class FakeNairobiLimitedCircuits(FakeNairobiV2):
"""FakeNairobiV2 with job size limit."""
class FakeBackendLimitedCircuits(GenericBackendV2):
"""Generic backend V2 with job size limit."""

@property
def max_circuits(self):
Expand All @@ -310,7 +314,7 @@ def max_circuits(self):
qc2 = QuantumCircuit(1)
qc2.x(0)
qc2.measure_all()
sampler = BackendSampler(backend=FakeNairobiLimitedCircuits())
sampler = BackendSampler(backend=FakeBackendLimitedCircuits(num_qubits=5))
result = sampler.run([qc, qc2]).result()
self.assertIsInstance(result, SamplerResult)
self.assertEqual(len(result.quasi_dists), 2)
Expand Down
Loading
Loading