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 14 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
98 changes: 66 additions & 32 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,12 @@ 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 backend_version <= 1:
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 @@ -585,30 +589,40 @@ def _create_faulty_qubits_map(backend):

if faulty_qubits or faulty_edges:
faulty_qubits_map = {}
configuration = backend.configuration()
full_coupling_map = configuration.coupling_map
backend_version = getattr(backend, "version", 0)
if backend_version <= 1:
configuration = backend.configuration()
full_coupling_map = configuration.coupling_map
else:
full_coupling_map = backend.coupling_map
num_qubits = backend.num_qubits
functional_cm_list = [
edge
for edge in full_coupling_map
if (set(edge).isdisjoint(faulty_qubits) and edge not in faulty_edges)
]

connected_working_qubits = CouplingMap(functional_cm_list).largest_connected_component()
dummy_qubit_counter = 0
for qubit in range(configuration.n_qubits):
for qubit in range(num_qubits):
if qubit in connected_working_qubits:
faulty_qubits_map[qubit] = dummy_qubit_counter
dummy_qubit_counter += 1
else:
faulty_qubits_map[qubit] = None

return faulty_qubits_map


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 backend_version <= 1:
if getattr(backend, "configuration", None):
basis_gates = getattr(backend.configuration(), "basis_gates", None)
else:
basis_gates = [gate.name for gate in backend.basis_gates]

# 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 @@ -634,28 +648,39 @@ 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 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
faulty_map = _create_faulty_qubits_map(backend)
if faulty_map:
coupling_map = CouplingMap()
for qubit1, qubit2 in configuration.coupling_map:
mtreinish marked this conversation as resolved.
Show resolved Hide resolved
if faulty_map[qubit1] is not None and faulty_map[qubit2] is not None:
coupling_map.add_edge(faulty_map[qubit1], faulty_map[qubit2])

# 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 @@ -710,11 +735,20 @@ def _parse_backend_properties(backend_properties, backend, num_circuits):
def _parse_backend_num_qubits(backend, num_circuits):
if backend is None:
return [None] * num_circuits
backend_version = getattr(backend, "version", 0)
if not isinstance(backend, list):
return [backend.configuration().n_qubits] * num_circuits
if backend_version <= 1:
num_qubits = backend.configuration().n_qubits
else:
num_qubits = backend.num_qubits
return [num_qubits] * num_circuits
backend_num_qubits = []
for a_backend in backend:
backend_num_qubits.append(a_backend.configuration().n_qubits)
if backend_version <= 1:
num_qubits = a_backend.configuration().n_qubits
else:
num_qubits = a_backend.num_qubits
backend_num_qubits.append(num_qubits)
return backend_num_qubits


Expand Down
Loading