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

Add dynamical decoupling transpiler pass #6619

Merged
merged 24 commits into from
Jul 6, 2021

Conversation

ajavadia
Copy link
Member

@ajavadia ajavadia commented Jun 22, 2021

Co-authored-by: Lauren Capelluto lcapelluto@users.noreply.github.com

Closes #6438

Summary

This commit adds a dynamical decoupling insertion pass. Given a scheduled circuit (i.e. a circuit where all the operations are annotated with a duration and where delays are inserted), it finds idle periods of time and inserts DD pulses. The circuit duration will remain the same. The user can select which qubits and what kind of spacing.

Details and comments

@ajavadia ajavadia requested a review from a team as a code owner June 22, 2021 03:04
@ajavadia ajavadia added this to the 0.18 milestone Jun 22, 2021
@mtreinish mtreinish added Changelog: New Feature Include in the "Added" section of the changelog priority: high labels Jun 22, 2021
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This obviously still needs tests and a release note. But I left some initial comments and questions inline.

qiskit/transpiler/passes/decoupling/insert_dd.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/decoupling/insert_dd.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/decoupling/insert_dd.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/decoupling/insert_dd.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/decoupling/insert_dd.py Outdated Show resolved Hide resolved
qiskit/transpiler/passes/decoupling/insert_dd.py Outdated Show resolved Hide resolved
if len(dag.qregs) != 1 or dag.qregs.get('q', None) is None:
raise TranspilerError('DD runs on physical circuits only')

new_dag = DAGCircuit()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine, I'm just wondering why you went for doing a fresh dag vs just doing in place replacement with subtitute_node_with_dag for the dd sequence? With the in place approach you could probably just loop over dag.named_nodes() and work directly with only the delays. Did you benchmark to see which is faster?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't benchmarked this, agree it would be good to know. Probably as a follow up.

@ajavadia ajavadia force-pushed the dynamical-decoupling-pass branch from ea8a10f to 11e0380 Compare June 30, 2021 20:25
@ajavadia ajavadia changed the title [WIP] dynamical decoupling pass dynamical decoupling pass Jun 30, 2021
@mtreinish mtreinish changed the title dynamical decoupling pass Add dynamical decoupling transpiler pass Jun 30, 2021
Comment on lines 148 to 153
dd_sequence = []
dd_sequence_duration = 0
for g in self._dd_sequence:
g.duration = self._durations.get(g, physical_qubit)
dd_sequence.append(g)
dd_sequence_duration += g.duration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be memoized for each qubit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately the physical_qubit changes the duration. but I did realize that I needlessly created a dd_sequence again which is the same as self._dd_sequence

else:
new_dag.apply_operation_back(nd.op, nd.qargs, nd.cargs)

new_dag.duration = dag.duration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be part of dag._copy_circuit_metadata()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, though I think duration as metadata is a bit dangerous because it can be overwritten easily. In reality duration should be calculated, similar to how we don't attach depth to the circuit. But for now I'll add it, requires a bit of though to improve.

@ajavadia ajavadia force-pushed the dynamical-decoupling-pass branch from c71a62e to e40d3f4 Compare July 1, 2021 14:47
@ajavadia ajavadia mentioned this pull request Jul 1, 2021
2 tasks
@ajavadia ajavadia force-pushed the dynamical-decoupling-pass branch from 1d917c5 to 37fedeb Compare July 2, 2021 17:40
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, just a few comments inline

Comment on lines 166 to 169
dd_sequence_duration = 0
for gate in self._dd_sequence:
gate.duration = self._durations.get(gate, physical_qubit)
dd_sequence_duration += gate.duration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to do this outside the for loop, since it should be static based on the configured dd sequence we don't need to recompute it for every delay.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lauren mentioned the same thing above. The duration is different for every qubit, but yes same across differernt delays of the same qubit. I did this in fa9da78

mtreinish
mtreinish previously approved these changes Jul 6, 2021
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for making the updates from the earlier reviews. Just one tiny comment inline but not a strong blocker. The only other thing I think is missing is a test case for _skip_reset_qubits with a Reset instruction (that would have caught the bug I found in my earlier review) but also not necessarily a blocker.

@mergify mergify bot merged commit 1270f7c into Qiskit:main Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog priority: high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamical decoupling
3 participants