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

Add BackendV2 abstract class #5885

Merged
merged 130 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
adbd651
Add BackendV2 abstract class
mtreinish Feb 19, 2021
fac5a5b
Adjust GateMap to be a dict instead of a graph
mtreinish Sep 9, 2021
39e5750
Add fields from properties to v2 backend interface
mtreinish Sep 13, 2021
267a8bd
Adjust GateMap structure
mtreinish Sep 14, 2021
e61abcd
Rename GateMap -> Target and drop readout error (as it'll be per inst…
mtreinish Sep 22, 2021
9e9c778
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Sep 22, 2021
1278c8e
Add instruction durations method to target
mtreinish Sep 22, 2021
1d4c151
Add optional dt properties to backend object
mtreinish Sep 22, 2021
b34d242
Add instruction durations method to backendv2
mtreinish Sep 22, 2021
d92e6cb
Fix lint
mtreinish Sep 22, 2021
31eedbc
Rename max_experiments -> max_circuits
mtreinish Sep 23, 2021
fd57146
Add two_q_gate option to Target.coupling_map()
mtreinish Sep 23, 2021
282a511
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Sep 23, 2021
ad7bbf5
Add option for a list of qubits to t1, t2, and frequency
mtreinish Sep 23, 2021
4e22110
Change list return to numpy array for t1 and t2
mtreinish Sep 28, 2021
154eee7
Drop qubit frequency
mtreinish Sep 28, 2021
1dc54d7
Add pulse to instruction durations
mtreinish Sep 28, 2021
28d8faa
Update units for dt and dtm
mtreinish Sep 28, 2021
4bc34af
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Sep 28, 2021
8c57845
Update qiskit/transpiler/target.py
mtreinish Sep 28, 2021
8a33fcf
Fix type hints for t1 and t2
mtreinish Sep 28, 2021
4a76c0b
Fix transpile() to actually use BackendV2 correctly
mtreinish Sep 28, 2021
79884eb
Merge branch 'backends-v2' of github.com:mtreinish/qiskit-core into b…
mtreinish Sep 28, 2021
46b3807
Add transpile() test case with BackendV2
mtreinish Sep 28, 2021
3eaeaeb
Merge branch 'main' into backends-v2
mtreinish Sep 28, 2021
0572572
Add repr for InstructionProperties
mtreinish Sep 28, 2021
519c579
Tweak docs
mtreinish Oct 4, 2021
d10fce1
Replace get_qargs_from_name with get_instructions_for_qarg
mtreinish Oct 4, 2021
d0454b7
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Oct 4, 2021
979a17b
Add tests for target
mtreinish Oct 4, 2021
f881140
Fix black's insane formatting choice
mtreinish Oct 4, 2021
87ca4dd
Add more target tests
mtreinish Oct 4, 2021
0dbdbaf
Cleanup debug prints
mtreinish Oct 5, 2021
2048ce9
Make Target a mapping
mtreinish Oct 5, 2021
4e8ad6b
Rename get_gate_from_name to get_instruction_from_name
mtreinish Oct 5, 2021
5d94c0b
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Oct 5, 2021
ea74429
Fix test issue with rename of get_gate_from_name
mtreinish Oct 5, 2021
a34481e
Add support for running schedule() with a backend v2
mtreinish Oct 8, 2021
9802c58
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Oct 8, 2021
9f290d0
Add method to update instruction properties in target
mtreinish Oct 8, 2021
8011cb8
Fix caching
mtreinish Oct 8, 2021
0f00322
Add tests for new target methods
mtreinish Oct 8, 2021
dfdf79a
Fix lint
mtreinish Oct 8, 2021
26398ad
Add support for qargs being None in ideal simulator case
mtreinish Oct 8, 2021
ce068be
Add test for ideal sim target instruction_schedule_map() method
mtreinish Oct 8, 2021
d3155c9
Add release note
mtreinish Oct 8, 2021
80d11af
Add BackendV2 to autodoc
mtreinish Oct 8, 2021
f40c7fe
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Oct 12, 2021
9c46637
Drop distance() and distance() matrix from Target
mtreinish Oct 12, 2021
f93ed28
Fix leftovers in doc strings
mtreinish Oct 12, 2021
26a179d
Add __str__ for target
mtreinish Oct 12, 2021
43955ad
Add logging when instruction_names includes instructions not on all q…
mtreinish Oct 12, 2021
639a190
Documentation fixes from code review
mtreinish Oct 13, 2021
89af78a
Use seconds everywhere
mtreinish Oct 13, 2021
3302041
Fixes from recent changes
mtreinish Oct 13, 2021
b13e127
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Oct 13, 2021
3e8930a
Add update_from_instruction_schedule_map() method
mtreinish Oct 18, 2021
6e63dd8
Merge branch 'main' into backends-v2
mtreinish Oct 18, 2021
a7c0317
Use defaultdict for _qarg_gate_map in target
mtreinish Oct 18, 2021
4228df2
Merge branch 'main' into backends-v2
mtreinish Oct 18, 2021
60de926
Explicitly add ScheduleBlock to backend.run()
mtreinish Oct 18, 2021
dad88f3
Tweak docs for target
mtreinish Oct 18, 2021
6792586
Add pulse channel abstract methods to BackendV2 class
mtreinish Oct 19, 2021
282002f
Merge branch 'main' into backends-v2
mtreinish Oct 19, 2021
8cac343
Fix lint
mtreinish Oct 19, 2021
e3ac45f
Improve target's update_from_instruction_schedule_map
mtreinish Oct 28, 2021
171b40c
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Oct 28, 2021
16ea95b
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Nov 4, 2021
3e7f45b
Add timing constraints to the target
mtreinish Nov 4, 2021
f9a2a2d
Fix typos in release note
mtreinish Nov 5, 2021
bffb477
Merge branch 'main' into backends-v2
mtreinish Nov 5, 2021
95a5e65
Re-export FakeBackendV2 in qiskit.test.mock
mtreinish Nov 5, 2021
b2511e0
Update target docstring example
mtreinish Nov 5, 2021
31ad33a
Make properties optional on Target.add_instruction()
mtreinish Nov 5, 2021
62f36bd
Add docstring type to BackendV2.target attribute
mtreinish Nov 5, 2021
5c252d4
Make Target.instructions property return tuple and add operations
mtreinish Nov 8, 2021
fe2e903
Rename instruction property schedule -> calibration
mtreinish Nov 8, 2021
7552406
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Nov 8, 2021
d457229
Add optional backend metadata as constructor kwargs
mtreinish Nov 9, 2021
be403b8
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Nov 9, 2021
6334bc0
More instruction->Operation renames
mtreinish Nov 9, 2021
0b5a539
Remove conditional and max_shots abstract properties
mtreinish Nov 9, 2021
5440ee5
Add optional validators to Options object
mtreinish Nov 9, 2021
1150fe0
Include dt in output InstructionDurations from Target
mtreinish Nov 10, 2021
598f513
Add QubitProperties class and qubits() backend method
mtreinish Nov 10, 2021
b07fedd
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Nov 10, 2021
debae29
Add instruction_properties() method
mtreinish Nov 10, 2021
4d43414
Fix lint in mock backend
mtreinish Nov 10, 2021
836efb8
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Nov 11, 2021
099a77b
Make provider backref optional and fix docstring
mtreinish Nov 11, 2021
0d1b2dc
Rename BackendV2.qubits() BackendV2.qubit_properties()
mtreinish Nov 11, 2021
2031f7f
Add note to QubitProperties docstring on subclassing
mtreinish Nov 11, 2021
6078d09
Fix Options.set_validator() docstring
mtreinish Nov 11, 2021
13c4f89
Add missing **fields docstring to BackendV2 init
mtreinish Nov 16, 2021
0ec5e6d
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Nov 16, 2021
d2c2796
Remove t1/t2 methods from BackendV2 class
mtreinish Nov 16, 2021
43a1ca5
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Nov 16, 2021
8e9ffa4
Remove unused imports
mtreinish Nov 17, 2021
2942118
Remove properties field from Properties classes
mtreinish Nov 17, 2021
076e815
Apply suggestions from code review
mtreinish Nov 18, 2021
d27df8c
Rename InstructionProperties.length -> duration
mtreinish Nov 18, 2021
7d4b90d
Merge branch 'main' into backends-v2
mtreinish Nov 18, 2021
2d02871
Docstring improvements and more instruction->operation
mtreinish Nov 18, 2021
9e1d544
Merge branch 'main' into backends-v2
mtreinish Nov 19, 2021
efaccb9
Merge branch 'main' into backends-v2
mtreinish Nov 22, 2021
4a9ccfa
Update releasenotes/notes/add-backend-v2-ce84c976fb13b038.yaml
mtreinish Nov 23, 2021
7e78e68
Merge remote-tracking branch 'origin/main' into backends-v2
mtreinish Nov 23, 2021
16475f2
Rename and fix incomplete basis computation
mtreinish Nov 23, 2021
da767e4
Tweak release note wording on custom attributes of backend
mtreinish Nov 23, 2021
071e7d8
Finish set_validator docstring on options class
mtreinish Nov 23, 2021
d638209
Update qiskit/providers/backend.py
mtreinish Nov 24, 2021
0619df8
Merge branch 'main' into backends-v2
mtreinish Nov 24, 2021
6a3e914
Apply suggestions from code review
mtreinish Nov 29, 2021
4839d4d
Merge branch 'main' into backends-v2
mtreinish Nov 29, 2021
9d2532c
Return dict .keys() directly for Target properties
mtreinish Nov 29, 2021
b1fb1b3
Fix stray use of properties attr in QubitProperties
mtreinish Nov 29, 2021
e125578
Update stray set() return for property
mtreinish Nov 29, 2021
d602568
Apply suggestions from code review
mtreinish Nov 29, 2021
814dc91
Merge branch 'main' into backends-v2
mtreinish Nov 29, 2021
65c3e71
Rename Target.get_qargs() -> qargs_for_operation_name()
mtreinish Nov 29, 2021
4bf8885
Fix lint
mtreinish Nov 29, 2021
24b6078
Rename Target.coupling_map() -> build_coupling_map()
mtreinish Nov 29, 2021
a94be6c
Fix test name for discovery
mtreinish Nov 29, 2021
599d2fd
qarg -> qargs in target method arguments
mtreinish Nov 30, 2021
1159856
Add target to docs build
mtreinish Nov 30, 2021
aa734af
Fix target docs
mtreinish Nov 30, 2021
2739221
Fix lint
mtreinish Nov 30, 2021
316c9e0
Tweak documentation for target to make intent and future clear
mtreinish Nov 30, 2021
1ecc09c
Fix typo in QubitProperties docstring
mtreinish Dec 1, 2021
5c2549a
Merge branch 'main' into backends-v2
mtreinish Dec 1, 2021
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
46 changes: 28 additions & 18 deletions qiskit/compiler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,34 @@ def schedule(
QiskitError: If ``inst_map`` and ``meas_map`` are not passed and ``backend`` is not passed
"""
start_time = time()
if inst_map is None:
if backend is None:
raise QiskitError(
"Must supply either a backend or InstructionScheduleMap for scheduling passes."
)
defaults = backend.defaults()
if defaults is None:
raise QiskitError(
"The backend defaults are unavailable. The backend may not support pulse."
)
inst_map = defaults.instruction_schedule_map
if meas_map is None:
if backend is None:
raise QiskitError("Must supply either a backend or a meas_map for scheduling passes.")
meas_map = backend.configuration().meas_map
if dt is None:
if backend is not None:
dt = backend.configuration().dt
if backend and getattr(backend, "version", 0) > 1:
if inst_map is None:
inst_map = backend.instruction_schedule_map
if meas_map is None:
meas_map = backend.meas_map
if dt is None:
dt = backend.dt
else:
if inst_map is None:
if backend is None:
raise QiskitError(
"Must supply either a backend or InstructionScheduleMap for scheduling passes."
)
defaults = backend.defaults()
if defaults is None:
raise QiskitError(
"The backend defaults are unavailable. The backend may not support pulse."
)
inst_map = defaults.instruction_schedule_map
if meas_map is None:
if backend is None:
raise QiskitError(
"Must supply either a backend or a meas_map for scheduling passes."
)
meas_map = backend.configuration().meas_map
if dt is None:
if backend is not None:
dt = backend.configuration().dt

schedule_config = ScheduleConfig(inst_map=inst_map, meas_map=meas_map, dt=dt)
circuits = circuits if isinstance(circuits, list) else [circuits]
Expand Down
107 changes: 74 additions & 33 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,15 @@ def _check_circuits_coupling_map(circuits, transpile_args, backend):
max_qubits = parsed_coupling_map.size()

# If coupling_map is None, the limit might be in the backend (like in 1Q devices)
elif backend is not None and not backend.configuration().simulator:
max_qubits = backend.configuration().n_qubits
elif backend is not None:
backend_version = getattr(backend, "version", 0)
if not isinstance(backend_version, int):
kdk marked this conversation as resolved.
Show resolved Hide resolved
backend_version = 0
if backend_version <= 1:
if not backend.configuration().simulator:
max_qubits = backend.configuration().n_qubits
else:
max_qubits = backend.num_qubits

if max_qubits is not None and (num_qubits > max_qubits):
raise TranspilerError(
Expand Down Expand Up @@ -608,6 +615,11 @@ def _create_faulty_qubits_map(backend):
from working qubit in the backend to dummy qubits that are consecutive and connected."""
faulty_qubits_map = None
if backend is not None:
backend_version = getattr(backend, "version", 0)
if not isinstance(backend_version, int):
backend_version = 0
if backend_version > 1:
return None
if backend.properties():
faulty_qubits = backend.properties().faulty_qubits()
faulty_edges = [gates.qubits for gates in backend.properties().faulty_gates()]
Expand Down Expand Up @@ -639,8 +651,14 @@ def _create_faulty_qubits_map(backend):
def _parse_basis_gates(basis_gates, backend, circuits):
# try getting basis_gates from user, else backend
if basis_gates is None:
if getattr(backend, "configuration", None):
basis_gates = getattr(backend.configuration(), "basis_gates", None)
backend_version = getattr(backend, "version", 0)
if not isinstance(backend_version, int):
backend_version = 0
if backend_version <= 1:
if getattr(backend, "configuration", None):
basis_gates = getattr(backend.configuration(), "basis_gates", None)
else:
basis_gates = backend.operation_names
# basis_gates could be None, or a list of basis, e.g. ['u3', 'cx']
if basis_gates is None or (
isinstance(basis_gates, list) and all(isinstance(i, str) for i in basis_gates)
Expand All @@ -666,28 +684,34 @@ def _parse_inst_map(inst_map, backend, num_circuits):
def _parse_coupling_map(coupling_map, backend, num_circuits):
# try getting coupling_map from user, else backend
if coupling_map is None:
if getattr(backend, "configuration", None):
configuration = backend.configuration()
if hasattr(configuration, "coupling_map") and configuration.coupling_map:
faulty_map = _create_faulty_qubits_map(backend)
if faulty_map:
faulty_edges = [gate.qubits for gate in backend.properties().faulty_gates()]
functional_gates = [
edge for edge in configuration.coupling_map if edge not in faulty_edges
]
coupling_map = CouplingMap()
for qubit1, qubit2 in functional_gates:
if faulty_map[qubit1] is not None and faulty_map[qubit2] is not None:
coupling_map.add_edge(faulty_map[qubit1], faulty_map[qubit2])
if configuration.n_qubits != coupling_map.size():
warnings.warn(
"The backend has currently some qubits/edges out of service."
" This temporarily reduces the backend size from "
f"{configuration.n_qubits} to {coupling_map.size()}",
UserWarning,
)
else:
coupling_map = CouplingMap(configuration.coupling_map)
backend_version = getattr(backend, "version", 0)
if not isinstance(backend_version, int):
backend_version = 0
if backend_version <= 1:
if getattr(backend, "configuration", None):
configuration = backend.configuration()
if hasattr(configuration, "coupling_map") and configuration.coupling_map:
faulty_map = _create_faulty_qubits_map(backend)
if faulty_map:
faulty_edges = [gate.qubits for gate in backend.properties().faulty_gates()]
functional_gates = [
edge for edge in configuration.coupling_map if edge not in faulty_edges
]
coupling_map = CouplingMap()
for qubit1, qubit2 in functional_gates:
if faulty_map[qubit1] is not None and faulty_map[qubit2] is not None:
coupling_map.add_edge(faulty_map[qubit1], faulty_map[qubit2])
if configuration.n_qubits != coupling_map.size():
warnings.warn(
"The backend has currently some qubits/edges out of service."
" This temporarily reduces the backend size from "
f"{configuration.n_qubits} to {coupling_map.size()}",
UserWarning,
)
else:
coupling_map = CouplingMap(configuration.coupling_map)
else:
coupling_map = backend.coupling_map

# coupling_map could be None, or a list of lists, e.g. [[0, 1], [2, 1]]
if coupling_map is None or isinstance(coupling_map, CouplingMap):
Expand Down Expand Up @@ -743,10 +767,22 @@ def _parse_backend_num_qubits(backend, num_circuits):
if backend is None:
return [None] * num_circuits
if not isinstance(backend, list):
return [backend.configuration().n_qubits] * num_circuits
backend_version = getattr(backend, "version", 0)
if not isinstance(backend_version, int):
backend_version = 0
if backend_version <= 1:
return [backend.configuration().n_qubits] * num_circuits
else:
return [backend.num_qubits] * num_circuits
backend_num_qubits = []
for a_backend in backend:
backend_num_qubits.append(a_backend.configuration().n_qubits)
backend_version = getattr(backend, "version", 0)
if not isinstance(backend_version, int):
backend_version = 0
if backend_version <= 1:
backend_num_qubits.append(a_backend.configuration().n_qubits)
else:
backend_num_qubits.append(a_backend.num_qubits)
return backend_num_qubits


Expand Down Expand Up @@ -938,11 +974,16 @@ def _parse_timing_constraints(backend, timing_constraints, num_circuits):
if backend is None and timing_constraints is None:
timing_constraints = TimingConstraints()
else:
if timing_constraints is None:
# get constraints from backend
timing_constraints = getattr(backend.configuration(), "timing_constraints", {})
timing_constraints = TimingConstraints(**timing_constraints)

backend_version = getattr(backend, "version", 0)
if not isinstance(backend_version, int):
backend_version = 0
if backend_version <= 1:
if timing_constraints is None:
# get constraints from backend
timing_constraints = getattr(backend.configuration(), "timing_constraints", {})
timing_constraints = TimingConstraints(**timing_constraints)
else:
timing_constraints = backend.target.timing_constraints()
return [timing_constraints] * num_circuits


Expand Down
4 changes: 4 additions & 0 deletions qiskit/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@

Backend
BackendV1
BackendV2
QubitProperties

Options
-------
Expand Down Expand Up @@ -547,6 +549,8 @@ def status(self):
from qiskit.providers.provider import ProviderV1
from qiskit.providers.backend import Backend
from qiskit.providers.backend import BackendV1
from qiskit.providers.backend import BackendV2
from qiskit.providers.backend import QubitProperties
from qiskit.providers.options import Options
from qiskit.providers.job import Job
from qiskit.providers.job import JobV1
Expand Down
Loading