-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Make heuristic score sorting robust in 1q optimization pass #9239
Changes from all commits
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 |
---|---|---|
|
@@ -112,13 +112,18 @@ def _substitution_checks(self, dag, old_run, new_circ, basis, qubit): | |
# if we're outside of the basis set, we're obligated to logically decompose. | ||
# if we're outside of the set of gates for which we have physical definitions, | ||
# then we _try_ to decompose, using the results if we see improvement. | ||
new_error = _error(new_circ, self._target, qubit) | ||
if isinstance(new_error, tuple): | ||
error_rate = new_error[0] | ||
else: | ||
error_rate = new_error | ||
Comment on lines
+115
to
+119
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. If |
||
return ( | ||
uncalibrated_and_not_basis_p | ||
or ( | ||
uncalibrated_p | ||
and _error(new_circ, self._target, qubit) < _error(old_run, self._target, qubit) | ||
and new_error < _error(old_run, self._target, qubit) | ||
) | ||
or np.isclose(_error(new_circ, self._target, qubit), 0) | ||
or np.isclose(error_rate, 0) | ||
Comment on lines
-121
to
+126
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. This check feels weird, because before this PR the last line could only have triggered if the error rate was "close to" 0, but not actually 0 - in that case, it would have been replaced by |
||
) | ||
|
||
@control_flow.trivial_recurse | ||
|
@@ -189,7 +194,4 @@ def _error(circuit, target, qubit): | |
for inst in circuit | ||
] | ||
gate_error = 1 - np.product(gate_fidelities) | ||
if gate_error == 0.0: | ||
return -100 + len(circuit) # prefer shorter circuits among those with zero error | ||
else: | ||
return gate_error | ||
return (gate_error, len(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.
Not sure if it's overkill, but I think it might be cleaner and less error-prone to add a local class to encapsulate the error tuple, and then generate a total ordering for it with
@functools.total_ordering
.It looks likeI'd worry there might be times where code accidentally compares tuples to numbers._error
is used by_resynthesize_run
as a key tomin
soEDIT: crossed-out isn't relevant (didn't notice at first glance that the target is bound as the same for all).
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.
Tuple[T, ...]
has an automatic total ordering in Python if typeT
has a total ordering itself, regardless of whether the lengths match - using tuples in comparisons is fairly idiomatic (e.g.if sys.version_info < (3, 10)
etc). Maybe I'm misunderstanding what you meant, though.