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 20 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
185 changes: 184 additions & 1 deletion test/python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017.
# (C) Copyright IBM 2017, 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 @@ -11,3 +11,186 @@
# that they have been altered from the originals.

"""Qiskit unit tests."""

# Coupling maps for fake backend generation

# 5 qubits
# bidirectional
BOGOTA_CMAP = [[0, 1], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3]]
ElePT marked this conversation as resolved.
Show resolved Hide resolved
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],
]
24 changes: 14 additions & 10 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 @@ -25,14 +25,18 @@
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.test import QiskitTestCase
from qiskit.transpiler import PassManager
from qiskit.utils import optionals

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 @@ -272,14 +276,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):
"""FakeBackend V2 with job size limit."""
ElePT marked this conversation as resolved.
Show resolved Hide resolved

@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 @@ -388,7 +392,7 @@ 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):
if optionals.HAS_AER and not isinstance(backend, GenericBackendV2):
self.assertEqual(value, -0.916)
else:
self.assertEqual(value, -1)
Expand All @@ -403,7 +407,7 @@ 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):
if optionals.HAS_AER and not isinstance(backend, GenericBackendV2):
self.assertEqual(value, -0.8902)
else:
self.assertEqual(value, -1)
Expand Down
19 changes: 12 additions & 7 deletions test/python/primitives/test_backend_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
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.basicaer import QasmSimulatorPy
from qiskit.test import QiskitTestCase
from qiskit.transpiler import PassManager
from qiskit.utils import optionals

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


class CallbackPass(DummyAP):
Expand Down Expand Up @@ -242,15 +246,15 @@ def test_run_empty_parameter(self, backend):
self.assertEqual(len(result.quasi_dists), 1)
for q_d in result.quasi_dists:
quasi_dist = {k: v for k, v in q_d.items() if v != 0.0}
self.assertDictAlmostEqual(quasi_dist, {0: 1.0}, delta=0.1)
self.assertDictAlmostEqual(quasi_dist, {0: 1.0}, delta=0.15)
kevinhartman marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(len(result.metadata), 1)

with self.subTest("two circuits"):
result = sampler.run([qc, qc], shots=1000).result()
self.assertEqual(len(result.quasi_dists), 2)
for q_d in result.quasi_dists:
quasi_dist = {k: v for k, v in q_d.items() if v != 0.0}
self.assertDictAlmostEqual(quasi_dist, {0: 1.0}, delta=0.1)
self.assertDictAlmostEqual(quasi_dist, {0: 1.0}, delta=0.15)
self.assertEqual(len(result.metadata), 2)

@combine(backend=BACKENDS)
Expand Down Expand Up @@ -299,8 +303,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):
"""FakeBackend V2 with job size limit."""
ElePT marked this conversation as resolved.
Show resolved Hide resolved

@property
def max_circuits(self):
Expand All @@ -311,11 +315,12 @@ 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)

print(result.quasi_dists)
ElePT marked this conversation as resolved.
Show resolved Hide resolved
self.assertDictAlmostEqual(result.quasi_dists[0], {0: 1}, 0.1)
self.assertDictAlmostEqual(result.quasi_dists[1], {1: 1}, 0.1)

Expand Down
Loading
Loading