-
Notifications
You must be signed in to change notification settings - Fork 12
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
Overloaded get_compiled_circuit/s
#423
Changes from 20 commits
c007b96
b96a6a8
4445109
7551213
2024583
c6b4143
dd70416
b5842ee
ec53bbb
58a24e7
8ff847f
4c408eb
e6f2d55
174c39b
b355f55
42d9329
031c601
ea9770e
48147a5
205a777
b4f5928
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,7 +410,34 @@ def default_compilation_pass_offline( | |
passlist.append(FullPeepholeOptimise()) | ||
elif optimisation_level == 3: | ||
passlist.append(RemoveBarriers()) | ||
passlist.append(AutoRebase({OpType.CX, OpType.H, OpType.Rz})) | ||
passlist.append( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a relevant change, that should be in the changelog, too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we don't need to include this - all I've done is update the set of gates we |
||
AutoRebase( | ||
{ | ||
OpType.Z, | ||
OpType.X, | ||
OpType.Y, | ||
OpType.S, | ||
OpType.Sdg, | ||
OpType.V, | ||
OpType.Vdg, | ||
OpType.H, | ||
OpType.CX, | ||
OpType.CY, | ||
OpType.CZ, | ||
OpType.SWAP, | ||
OpType.Rz, | ||
OpType.Rx, | ||
OpType.Ry, | ||
OpType.T, | ||
OpType.Tdg, | ||
OpType.ZZMax, | ||
OpType.ZZPhase, | ||
OpType.XXPhase, | ||
OpType.YYPhase, | ||
OpType.PhasedX, | ||
} | ||
), | ||
) | ||
passlist.append( | ||
GreedyPauliSimp(thread_timeout=timeout, only_reduce=True, trials=10) | ||
) | ||
|
@@ -441,6 +468,75 @@ def default_compilation_pass_offline( | |
) | ||
return SequencePass(passlist) | ||
|
||
def get_compiled_circuit( | ||
self, circuit: Circuit, optimisation_level: int = 2, timeout: int = 300 | ||
) -> Circuit: | ||
""" | ||
Return a single circuit compiled with :py:meth:`default_compilation_pass`. | ||
|
||
:param optimisation_level: Allows values of 0, 1, 2 or 3, with higher values | ||
prompting more computationally heavy optimising compilation that | ||
can lead to reduced gate count in circuits. | ||
:type optimisation_level: int, optional | ||
:param timeout: Only valid for optimisation level 3, gives a maximimum time | ||
for running a single thread of the pass `GreedyPauliSimp`. Increase for | ||
optimising larger circuits. | ||
:type timeout: int, optional | ||
|
||
:return: An optimised quantum circuit | ||
:rtype: Circuit | ||
""" | ||
return_circuit = circuit.copy() | ||
if optimisation_level == 3 and circuit.n_gates_of_type(OpType.Barrier) > 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same answer as for |
||
warn( | ||
"Barrier operations in this circuit will be removed when using " | ||
"optimisation level 3." | ||
) | ||
self.default_compilation_pass(optimisation_level, timeout).apply(return_circuit) | ||
return return_circuit | ||
|
||
def get_compiled_circuits( | ||
self, | ||
circuits: Sequence[Circuit], | ||
optimisation_level: int = 2, | ||
timeout: int = 300, | ||
) -> list[Circuit]: | ||
"""Compile a sequence of circuits with :py:meth:`default_compilation_pass` | ||
and return the list of compiled circuits (does not act in place). | ||
|
||
As well as applying a degree of optimisation (controlled by the | ||
`optimisation_level` parameter), this method tries to ensure that the circuits | ||
can be run on the backend (i.e. successfully passed to | ||
:py:meth:`process_circuits`), for example by rebasing to the supported gate set, | ||
or routing to match the connectivity of the device. However, this is not always | ||
possible, for example if the circuit contains classical operations that are not | ||
supported by the backend. You may use :py:meth:`valid_circuit` to check whether | ||
the circuit meets the backend's requirements after compilation. This validity | ||
check is included in :py:meth:`process_circuits` by default, before any circuits | ||
are submitted to the backend. | ||
|
||
If the validity check fails, you can obtain more information about the failure | ||
by iterating through the predicates in the `required_predicates` property of the | ||
backend, and running the :py:meth:`verify` method on each in turn with your | ||
circuit. | ||
|
||
:param circuits: The circuits to compile. | ||
:type circuit: Sequence[Circuit] | ||
:param optimisation_level: The level of optimisation to perform during | ||
compilation. See :py:meth:`default_compilation_pass` for a description of | ||
the different levels (0, 1, 2 or 3). Defaults to 2. | ||
:type optimisation_level: int, optional | ||
:param timeout: Only valid for optimisation level 3, gives a maximimum time | ||
for running a single thread of the pass `GreedyPauliSimp`. Increase for | ||
optimising larger circuits. | ||
:type timeout: int, optional | ||
:return: Compiled circuits. | ||
:rtype: List[Circuit] | ||
""" | ||
return [ | ||
self.get_compiled_circuit(c, optimisation_level, timeout) for c in circuits | ||
] | ||
|
||
@property | ||
def _result_id_type(self) -> _ResultIdTuple: | ||
# IBMQ job ID, index, number of bits, post-processing circuit | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this check not in the other function
get_compiled_circuits
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_compiled_circuits
calls this method so the check is done implicitly