Transpiler updates for optional registers.#5515
Conversation
cdfd7dd to
46e8fa7
Compare
46e8fa7 to
c7ef6fc
Compare
c7ef6fc to
68afca2
Compare
mtreinish
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
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.
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.
yeah I can push a follow up to do this, it's not crtiical
There was a problem hiding this comment.
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.
Functionally, only that Layout is a bidirectional (instead of unidirectional) mapping from Qubits to ints. Since I wrote that comment though, I've moved away from the idea of using Layouts as a generic mapping (outside the contexts of layout and routing) because the resulting code ends up for me harder to read.
There was a problem hiding this comment.
Good catch, added in 49865fc .
68afca2 to
13a63e6
Compare
mtreinish
left a comment
There was a problem hiding this comment.
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 . |
mtreinish
left a comment
There was a problem hiding this comment.
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_layoutwhich raises aKeyErrorfromLayoutinstead of the expectedDAGCircuitErrorSome cases where we buildqubit_indicesmight be better asLayout.generate_trivial_layout