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

Level 1 chooses between trival and dense layout selection, depending on the layout score #3324

Closed
wants to merge 134 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
efd8065
initial version of the controller
Aug 20, 2019
a707c5d
controller.do_passes
Aug 20, 2019
925eb45
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2969
Aug 21, 2019
9abf8ca
property set linked at pass runtime instead of a partial evaluation
Aug 21, 2019
d240e17
docstringing and linting
Aug 21, 2019
c86c2f1
changelog
Aug 21, 2019
ba7825f
setup
Aug 21, 2019
49fa3b9
Merge branch 'master' into 2969
Aug 21, 2019
c5192d8
Merge branch 'master' into 2969
Aug 23, 2019
efd1aa8
TranspileConfig defaults
Aug 23, 2019
4527a17
defatuls for TranspileConfig
Aug 23, 2019
e82efad
Merge branch 'master' into 2969
Aug 26, 2019
fb5bad8
release note
Aug 26, 2019
76befce
Merge branch 'master' into defaults_TranspileConfig
Sep 5, 2019
e95a102
explicit kwargs
Sep 5, 2019
75ca2cd
remove __getattr__ None
Sep 5, 2019
ca3e1d2
move cm checks to _parse_coupling_map
Sep 8, 2019
ba39d87
transpile_config as a dict
Sep 8, 2019
203280f
pass manager config
Sep 8, 2019
eccfd27
circuit is yet another transpiler param
Sep 8, 2019
ea8d6a2
TranspileConfigSchema -> PassManagerConfigSchema
Sep 8, 2019
cc393d1
removing unsed parameters in PassManagerConfig
Sep 8, 2019
24ce889
no need for _transpile_circuit anymore
Sep 8, 2019
fc488b8
pass manager callback at construction time
Sep 8, 2019
44677ce
Merge branch 'master' of github.com:Qiskit/qiskit-terra into defaults…
Sep 8, 2019
b5ee757
docstring
Sep 9, 2019
01de59b
changelog
Sep 10, 2019
fe54db6
deprecate callback from construction time
Sep 10, 2019
26b379e
_parse_output_name creates Nones instead of circuit.name
Sep 10, 2019
4aeb87e
transpile_config -> transpile_args
Sep 10, 2019
117d813
merge
Sep 10, 2019
948b3d4
CouplingMap(backend.configuration().coupling_map)
Sep 10, 2019
a909c5f
reformat
Sep 10, 2019
85eeb69
merge
Sep 12, 2019
f552ee6
Merge branch 'master' into 2969
Sep 13, 2019
db462bc
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2969
Sep 13, 2019
83a79d1
merge
Sep 23, 2019
2f1e60e
Merge branch 'master' into defaults_TranspileConfig
Sep 30, 2019
2ceb8a7
merge
Sep 30, 2019
643efe6
Merge branch 'master' into 2969
Oct 2, 2019
87a09d6
merge
Oct 23, 2019
19a21bd
merge!
Oct 23, 2019
397e5e8
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2969
Oct 23, 2019
adc5408
style
Oct 23, 2019
ff3b56b
lint
Oct 23, 2019
0dbca81
better test_pass_scheduler
Oct 23, 2019
474f335
poc
Oct 23, 2019
dd1339c
handleing the property set
Oct 24, 2019
e6e3862
propagate property set into inter
Oct 24, 2019
278e4c9
undo level1
Oct 24, 2019
0d5bbb5
failing test
Oct 25, 2019
4d27c33
lint
Oct 25, 2019
c9d27eb
test
Oct 25, 2019
b8cb0dc
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2969
Oct 25, 2019
044fc5f
initial commit
Oct 25, 2019
9a7428d
docstring
Oct 25, 2019
30ed4d9
docstring
Oct 25, 2019
4eebb7b
Merge branch 'master' of github.com:Qiskit/qiskit-terra into layout_s…
Oct 25, 2019
efb475a
Merge branch 'layout_score' into 2845
Oct 25, 2019
f4824e7
No SetLayout when initial_layout provided
Oct 25, 2019
29271ff
level1
Oct 25, 2019
2517d98
adjust test
Oct 25, 2019
17ff28a
lint
Oct 27, 2019
bd89b1f
lint!
Oct 27, 2019
bd794ab
Merge branch 'master' into 2845
Oct 27, 2019
6153296
Merge branch 'master' into 2969
Oct 27, 2019
fccad46
Update qiskit/transpiler/passes/mapping/layout_score.py
Oct 27, 2019
d38c52d
Merge branch 'master' into layout_score
Oct 27, 2019
d0c1d6b
Merge branch 'master' of github.com:Qiskit/qiskit-terra into layout_s…
Oct 28, 2019
ea87e66
+= -> =
Oct 28, 2019
a5d1a4a
docstring
Oct 28, 2019
23d1742
merge
Oct 30, 2019
e3af64e
Merge branch 'master' into layout_score
Oct 30, 2019
9b8603b
remove initial_layout param
Oct 30, 2019
26d19e2
Merge branch 'master' into defaults_TranspileConfig
Oct 30, 2019
73b21c2
fixing test/python/transpiler/test_passmanager_run.py
Oct 31, 2019
bbb1c45
run(..., output_name=None, callback=None)
Oct 31, 2019
142e298
basis
Oct 31, 2019
321b906
Merge branch 'master' of github.com:Qiskit/qiskit-terra into defaults…
Oct 31, 2019
4c98cc5
kwargs
Oct 31, 2019
38f7c56
transpile_args[pass_manager_config].basis_gates
Oct 31, 2019
af9a914
callback at run time
Oct 31, 2019
5627f46
lint
Oct 31, 2019
559f21f
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2969
Oct 31, 2019
bda9b87
Update qiskit/transpiler/runningpassmanager.py
Oct 31, 2019
9f59e64
qiskit/transpiler/runningpassmanager.py
Oct 31, 2019
e1b12c1
Merge branch '2969' of github.com:1ucian0/qiskit-terra into 2969
Oct 31, 2019
d23d4f5
fixes test/python/transpiler/test_pass_scheduler.py
Oct 31, 2019
7deb4ba
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2845
Oct 31, 2019
6814a92
merge
Oct 31, 2019
dee0d29
Merge branch '2969' into 2845
Oct 31, 2019
c8cfd3d
rename qiskit/transpiler/passes/mapping/layout_score.py qiskit/transp…
Oct 31, 2019
4f7a743
LayoutScore -> Layout2qDistance
Oct 31, 2019
c852aaf
counter
Oct 31, 2019
4d740eb
Merge branch 'layout_score' into 2845
Oct 31, 2019
147891a
dyn property name
Oct 31, 2019
69463eb
Merge branch 'layout_score' into 2845
Oct 31, 2019
3c27ebc
merge
Oct 31, 2019
e546b39
Merge branch 'master' of github.com:Qiskit/qiskit-terra into layout_s…
Nov 1, 2019
2561536
docstring
Nov 1, 2019
a277e86
Merge branch 'layout_score' into 2845
Nov 1, 2019
058c602
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2969
Nov 1, 2019
bface9d
FlowControllerLinear.do_passes
Nov 1, 2019
30fa4e4
release notes
Nov 1, 2019
a70db25
Merge branch '2969' into 2845
Nov 1, 2019
1ad6b25
Merge branch 'master' of github.com:Qiskit/qiskit-terra into defaults…
Nov 1, 2019
77d678a
merge #3035 into this branch
Nov 1, 2019
a537689
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2845
Nov 2, 2019
2e27145
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2969
Nov 2, 2019
ec8e31a
self.dag_might_have_modifications
Nov 2, 2019
48166e7
merge 2969
Nov 2, 2019
1c91111
Merge branch 'master' of github.com:Qiskit/qiskit-terra into defaults…
Nov 2, 2019
6b0b4be
release note
Nov 3, 2019
e83e03f
Merge branch 'defaults_TranspileConfig' into 2845
Nov 4, 2019
cc7ddc1
Merge branch 'master' into defaults_TranspileConfig
mergify[bot] Nov 5, 2019
187a58e
Merge branch 'master' into defaults_TranspileConfig
mergify[bot] Nov 6, 2019
d261510
Merge branch 'master' into defaults_TranspileConfig
mergify[bot] Nov 6, 2019
d4af0f8
Merge branch 'master' of github.com:Qiskit/qiskit-terra into defaults…
Nov 7, 2019
b58e603
Merge branch 'master' into 2969
Nov 7, 2019
3037240
Merge branch 'master' into defaults_TranspileConfig
Nov 7, 2019
2a99885
Merge branch 'master' into defaults_TranspileConfig
mergify[bot] Nov 7, 2019
009238d
Merge branch 'master' of github.com:Qiskit/qiskit-terra into defaults…
Nov 8, 2019
ad5bb3a
docstring
Nov 8, 2019
b21e0b3
other -> upgrade
Nov 8, 2019
70aaf6c
release note
Nov 8, 2019
33c0e19
Merge branch '2969' of github.com:1ucian0/qiskit-terra into 2969
Nov 8, 2019
6593ed3
set up to keep the order of the controllers
Nov 8, 2019
6da5bf2
Merge branch 'master' of github.com:Qiskit/qiskit-terra into 2969
Nov 8, 2019
6dbac3b
Merge branch 'master' of github.com:Qiskit/qiskit-terra into defaults…
Nov 8, 2019
34146c5
Merge branch 'defaults_TranspileConfig' into 2845
Nov 8, 2019
b583d8e
Merge branch '2969' into 2845
Nov 8, 2019
ba4a219
lint
Nov 8, 2019
bc4c6fd
Merge branch '2969' into 2845
Nov 8, 2019
97d04d3
doesnt run DenseLayout if TrivialLayout is already perfect
Nov 8, 2019
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
126 changes: 52 additions & 74 deletions qiskit/compiler/transpile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qiskit.transpiler import Layout, CouplingMap
from qiskit.tools.parallel import parallel_map
from qiskit.transpiler.transpile_config import TranspileConfig
from qiskit.transpiler.pass_manager_config import PassManagerConfig
from qiskit.transpiler.transpile_circuit import transpile_circuit
from qiskit.pulse import Schedule
from qiskit.circuit.quantumregister import Qubit
Expand Down Expand Up @@ -179,49 +179,21 @@ def callback_func(**kwargs):
config = user_config.get_config()
optimization_level = config.get('transpile_optimization_level', None)

# Get TranspileConfig(s) to configure the circuit transpilation job(s)
# Get transpiler argument(s) to configure the circuit transpilation job(s)
circuits = circuits if isinstance(circuits, list) else [circuits]
transpile_configs = _parse_transpile_args(circuits, backend, basis_gates, coupling_map,
backend_properties, initial_layout,
seed_transpiler, optimization_level,
pass_manager, callback, output_name)
# Check circuit width against number of qubits in coupling_map(s)
coupling_maps_list = list(config.coupling_map for config in transpile_configs)
for circuit, parsed_coupling_map in zip(circuits, coupling_maps_list):
# If coupling_map is not None
if isinstance(parsed_coupling_map, CouplingMap):
n_qubits = len(circuit.qubits)
max_qubits = parsed_coupling_map.size()
if n_qubits > max_qubits:
raise TranspilerError('Number of qubits ({}) '.format(n_qubits) +
'in {} '.format(circuit.name) +
'is greater than maximum ({}) '.format(max_qubits) +
'in the coupling_map')
transpile_args = _parse_transpile_args(circuits, backend, basis_gates, coupling_map,
backend_properties, initial_layout,
seed_transpiler, optimization_level,
pass_manager, callback, output_name)

# Transpile circuits in parallel
circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_configs)))
circuits = parallel_map(transpile_circuit, transpile_args)

if len(circuits) == 1:
return circuits[0]
return circuits


# FIXME: This is a helper function because of parallel tools.
def _transpile_circuit(circuit_config_tuple):
"""Select a PassManager and run a single circuit through it.

Args:
circuit_config_tuple (tuple):
circuit (QuantumCircuit): circuit to transpile
transpile_config (TranspileConfig): configuration dictating how to transpile

Returns:
QuantumCircuit: transpiled circuit
"""
circuit, transpile_config = circuit_config_tuple

return transpile_circuit(circuit, transpile_config)


def _parse_transpile_args(circuits, backend,
basis_gates, coupling_map, backend_properties,
initial_layout, seed_transpiler, optimization_level,
Expand All @@ -235,45 +207,38 @@ def _parse_transpile_args(circuits, backend,
arg has more priority than the arg set by backend)

Returns:
list[TranspileConfig]: a transpile config for each circuit, which is a standardized
object that configures the transpiler and determines the pass manager to use.
list[dicts]: a list of transpile parameters.
"""
# Each arg could be single or a list. If list, it must be the same size as
# number of circuits. If single, duplicate to create a list of that size.
num_circuits = len(circuits)

basis_gates = _parse_basis_gates(basis_gates, backend, circuits)

coupling_map = _parse_coupling_map(coupling_map, backend, num_circuits)

coupling_map = _parse_coupling_map(coupling_map, backend, circuits)
backend_properties = _parse_backend_properties(backend_properties, backend, num_circuits)

initial_layout = _parse_initial_layout(initial_layout, circuits)

seed_transpiler = _parse_seed_transpiler(seed_transpiler, num_circuits)

optimization_level = _parse_optimization_level(optimization_level, num_circuits)

pass_manager = _parse_pass_manager(pass_manager, num_circuits)
output_name = _parse_output_name(output_name, num_circuits)

output_name = _parse_output_name(output_name, circuits)

transpile_configs = []
transpile_args_circuits = []
for args in zip(basis_gates, coupling_map, backend_properties,
initial_layout, seed_transpiler, optimization_level,
pass_manager, output_name):
transpile_config = TranspileConfig(basis_gates=args[0],
coupling_map=args[1],
backend_properties=args[2],
initial_layout=args[3],
seed_transpiler=args[4],
optimization_level=args[5],
pass_manager=args[6],
callback=callback,
output_name=args[7])
transpile_configs.append(transpile_config)

return transpile_configs
pass_manager, output_name, circuits):
transpile_args = {'pass_manager_config': PassManagerConfig(basis_gates=args[0],
coupling_map=args[1],
backend_properties=args[2],
initial_layout=args[3],
seed_transpiler=args[4]),
'optimization_level': args[5],
'pass_manager': args[6],
'output_name': args[7],
'circuit': args[8],
'callback': callback}
transpile_args_circuits.append(transpile_args)

return transpile_args_circuits


def _parse_basis_gates(basis_gates, backend, circuits):
Expand Down Expand Up @@ -302,18 +267,31 @@ def _parse_basis_gates(basis_gates, backend, circuits):
return basis_gates


def _parse_coupling_map(coupling_map, backend, num_circuits):
def _parse_coupling_map(coupling_map, backend, circuits):
num_circuits = len(circuits)
# try getting coupling_map from user, else backend
if coupling_map is None:
if getattr(backend, 'configuration', None):
coupling_map = getattr(backend.configuration(), 'coupling_map', None)
# 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):
coupling_map = [coupling_map] * num_circuits
elif isinstance(coupling_map, list) and all(isinstance(i, list) and len(i) == 2
for i in coupling_map):
coupling_map = [coupling_map] * num_circuits
coupling_map = [CouplingMap(cm) if isinstance(cm, list) else cm for cm in coupling_map]
configuration = backend.configuration()
if hasattr(configuration, 'coupling_map') and configuration.coupling_map:
coupling_map = CouplingMap(configuration.coupling_map)

coupling_map = [coupling_map] * num_circuits

for index, parsed_coupling_map in enumerate(coupling_map):
if isinstance(parsed_coupling_map, list):
parsed_coupling_map = CouplingMap(parsed_coupling_map)
# If coupling_map is not None
if isinstance(parsed_coupling_map, CouplingMap):
n_qubits = len(circuits[index].qubits)
max_qubits = parsed_coupling_map.size()
if n_qubits > max_qubits:
raise TranspilerError('Number of qubits ({}) '.format(n_qubits) +
'in {} '.format(circuits[index].name) +
'is greater than maximum ({}) '.format(max_qubits) +
'in the coupling_map')
coupling_map[index] = parsed_coupling_map

return coupling_map


Expand Down Expand Up @@ -375,21 +353,21 @@ def _parse_pass_manager(pass_manager, num_circuits):
return pass_manager


def _parse_output_name(output_name, circuits):
def _parse_output_name(output_name, num_circuits):
# naming and returning circuits
# output_name could be either a string or a list
if output_name is not None:
if isinstance(output_name, str):
# single circuit
if len(circuits) == 1:
if num_circuits == 1:
return [output_name]
# multiple circuits
else:
raise TranspilerError("Expected a list object of length equal " +
"to that of the number of circuits " +
"being transpiled")
elif isinstance(output_name, list):
if len(circuits) == len(output_name) and \
if num_circuits == len(output_name) and \
all(isinstance(name, str) for name in output_name):
return output_name
else:
Expand All @@ -401,4 +379,4 @@ def _parse_output_name(output_name, circuits):
raise TranspilerError("The parameter output_name should be a string or a"
"list of strings: %s was used." % type(output_name))
else:
return [circuit.name for circuit in circuits]
return [None] * num_circuits
6 changes: 3 additions & 3 deletions qiskit/transpiler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Models for TranspileConfig and RunConfig."""
"""Models for PassManagerConfig and RunConfig."""

from qiskit.validation import BaseSchema


class TranspileConfigSchema(BaseSchema):
"""Schema for TranspileConfig."""
class PassManagerConfigSchema(BaseSchema):
"""Schema for PassManagerConfig."""

# Required properties.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,35 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Models for TranspileConfig and its related components."""
"""Models for PassManagerConfig and its related components."""

from qiskit.transpiler.models import TranspileConfigSchema
from qiskit.transpiler.models import PassManagerConfigSchema
from qiskit.validation import BaseModel, bind_schema


@bind_schema(TranspileConfigSchema)
class TranspileConfig(BaseModel):
"""Model for TranspileConfig.
@bind_schema(PassManagerConfigSchema)
class PassManagerConfig(BaseModel):
"""Model for PassManagerConfig.

Please note that this class only describes the required fields. For the
full description of the model, please check ``TranspileConfigSchema``.
full description of the model, please check ``PassManagerConfigSchema``.

Attributes:
optimization_level (int): a non-negative integer indicating the
optimization level. 0 means no transformation on the circuit. Higher
levels may produce more optimized circuits, but may take longer.
"""
def __init__(self, optimization_level, **kwargs):
self.optimization_level = optimization_level
super().__init__(**kwargs)

def __init__(self,
initial_layout=None,
basis_gates=None,
coupling_map=None,
backend_properties=None,
seed_transpiler=None,
**kwargs):
super().__init__(initial_layout=initial_layout,
basis_gates=basis_gates,
coupling_map=coupling_map,
backend_properties=backend_properties,
seed_transpiler=seed_transpiler,
**kwargs)
Loading