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
Transpiler updates for optional registers. #5515
Transpiler updates for optional registers. #5515
Conversation
cdfd7dd
to
46e8fa7
Compare
46e8fa7
to
c7ef6fc
Compare
c7ef6fc
to
68afca2
Compare
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.
This LGTM a couple small comments and questions inline. The big takeaway for me though is just like in the previous PR we basically are reconstructing a qubit indices dict for anywhere there was index based access before. I know we're already tracking a follow up where we move that to the QuantumCircuit, but it might make sense to copy that to the dag metadata as well in that follow up so we don't need to reconstruct it in all the passes.
@@ -31,7 +31,8 @@ cdef class NLayout: | |||
|
|||
|
|||
cpdef NLayout nlayout_from_layout(object layout, | |||
object dag, | |||
object dag, |
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.
Is there a reason this has a different name than the implementation in utils.pyx
? I probably would make this also typed as a dict
. So something like:
object dag, | |
dict qubit_indices, |
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.
Agree, added in 23a6597 .
@@ -162,32 +162,27 @@ cdef class NLayout: | |||
return out | |||
|
|||
|
|||
cpdef NLayout nlayout_from_layout(object layout, object qregs, | |||
cpdef NLayout nlayout_from_layout(object layout, | |||
object qubit_indices, |
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.
I would make this a dict (assuming the signature declaration in the pxd is updated to match:
object qubit_indices, | |
dict qubit_indices, |
I don't think it matters too much, but feels like explicitly typing the argument to always be a dict makes the most sense instead of taking any object. (I expect it was object before because an OrderedDict
was used for python 3.5 compat)
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.
Agree, added in 23a6597 .
int_layout = nlayout_from_layout(layout, qregs, coupling.size()) | ||
int_qubit_subset = np.fromiter((self._qubit_indices[bit] | ||
for bit in qubit_subset), | ||
dtype=np.int32, |
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.
Looking at these I do wonder we don't make these unsigned since we can't have negative qubit indices. But that would require more cython changes because this array gets passed as an arg to the swap_trial
cython function.
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.
That's a good idea, maybe an issue as a future improvement (or as a target of opportunity next time we need to dive into the cython code)?
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.
yeah I can push a follow up to do this, it's not crtiical
@@ -47,9 +48,11 @@ def run(self, dag): | |||
self.property_set['is_direction_mapped'] = True | |||
edges = self.coupling_map.get_edges() | |||
|
|||
trivial_layout = Layout.generate_trivial_layout(*dag.qregs.values()) |
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.
I saw the WIP todo in the PR summary about this, but what is the functional difference between using a layout here versus building a qubit indices dict?
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.
Functionally, only that Layout
is a bidirectional (instead of unidirectional) mapping from Qubit
s to int
s. Since I wrote that comment though, I've moved away from the idea of using Layout
s as a generic mapping (outside the contexts of layout and routing) because the resulting code ends up for me harder to read.
""" After each gate generate a new unique variable name for each of the | ||
qubits, using scheme: 'q[id]_[gatenum]', e.g. q1_0 -> q1_1 -> q1_2, | ||
q2_0 -> q2_1 | ||
Args: | ||
qb_id (int): index of qubit to generate new variable for | ||
qbt (Qubit): qubit to generate new variable for |
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.
Any reason to not use qubit
?
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.
Good catch, added in 49865fc .
68afca2
to
13a63e6
Compare
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.
Thanks for the update I think it LGTM. The one thing I think would be good to have before we merge is some testing of the passes without registers, especially for ones not in the default pipeline (like the hoare optimization pass).
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
13a63e6
to
ffe7ac0
Compare
Good idea, added in 3d745bb . |
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.
LGTM, good to see the extra test coverage and that it caught a bunch of bugs. I think this LGTM now. I still think there are some coverage gaps on some of the non default passes, but we can always fix those in follow ups too.
Summary
Following #5504 updates transpiler and in-tree passes to support optional registers, and to prefer inspecting bits over registers where possible.
Details and comments
on-hold until #5504 .
Commits in this PR (without #5504, #5498 and #5486): https://github.com/Qiskit/qiskit-terra/pull/5515/files/51db5270a21a98ca408ad9eca470b715b92639d0..cdfd7ddbbe7542d949426b7c90a7ac723e202569
WIP:
Skips(Resolved by Better initial_layout validation #5526 .)test.python.compiler.test_transpiler.TestTranspile.test_wrong_initial_layout
which raises aKeyError
fromLayout
instead of the expectedDAGCircuitError
Some cases where we buildqubit_indices
might be better asLayout.generate_trivial_layout