Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Update dynamical decoupling pass to support staggered pulses #563

Merged
merged 13 commits into from
Jul 31, 2023

Conversation

dieris
Copy link
Contributor

@dieris dieris commented Apr 4, 2023

Summary

Closes #539. Add the option to select two different sets of spacings between pulses, given the coupling map of a backend.

Details and comments

Extends #480 with the qiskit-terra implementation of staggered DD

Example usage:

durations =  DynamicCircuitInstructionDurations.from_backend(backend)
dd_sequence = [XGate(), XGate()]
coupling_map = backend.coupling_map
pm = PassManager(
  [
      ALAPScheduleAnalysis(durations),
      PadDynamicalDecoupling(durations, dd_sequence, coupling_map = coupling_map),
  ]
)

As optional argument, alt_spacings can be provided to change the default [0.5 0.5 0] (for a 2-pulse sequence), which staggers the DD sequence with respect to the default spacings values [0.25 0.5 0.25]

@CLAassistant
Copy link

CLAassistant commented Apr 4, 2023

CLA assistant check
All committers have signed the CLA.

@dieris dieris marked this pull request as draft April 4, 2023 20:46
@coveralls
Copy link

coveralls commented Apr 4, 2023

Pull Request Test Coverage Report for Build 5719011032

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 20 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 51.167%

Files with Coverage Reduction New Missed Lines %
qiskit_ibm_provider/transpiler/passes/scheduling/dynamical_decoupling.py 20 90.57%
Totals Coverage Status
Change from base Build 5718855472: 0.2%
Covered Lines: 3310
Relevant Lines: 6469

💛 - Coveralls

@dieris dieris marked this pull request as ready for review April 5, 2023 20:24
@miamico
Copy link

miamico commented May 5, 2023

I'm planning to use this functionality in experiments, so I'm taking a look. I tested some instances of circuit generation and I think it's looking good!

A couple of things that maybe you can clarify based on the following example:

from qiskit.providers.fake_provider import FakePrague
from qiskit.compiler import transpile

import numpy as np

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import XGate, RZGate
from qiskit.transpiler.passmanager import PassManager

from qiskit_ibm_provider.transpiler.passes.scheduling.dynamical_decoupling import (
    PadDynamicalDecoupling,
)
from qiskit_ibm_provider.transpiler.passes.scheduling.scheduler import (
    ASAPScheduleAnalysis,
)
from qiskit_ibm_provider.transpiler.passes.scheduling.utils import (
    DynamicCircuitInstructionDurations,
)

backend = FakePrague()
coupling_map = backend.coupling_map

durations = DynamicCircuitInstructionDurations(
    [
        ("h", 0, 50),
        ("cx", [0, 1], 700),
        ("cx", [1, 2], 200),
        ("cx", [2, 3], 300),
        ("x", None, 50),
        ("y", None, 50),
        ("u", None, 100),
        ("rx", None, 100),
        ("rz", None, 0),
        ("measure", None, 840),
        ("reset", None, 1340),
    ]
)

dd_sequence = [XGate(), RZGate(np.pi), XGate(), RZGate(-np.pi)]
pm = PassManager(
    [
        ASAPScheduleAnalysis(durations),
        PadDynamicalDecoupling(
            durations,
            dd_sequence,
            spacings = [1 / 4, 1 / 2, 0, 0, 1 / 4],
            coupling_map=coupling_map,
            alt_spacings=[ 1 / 2, 0, 1/2, 0],
        ),
    ]
)

qc_barriers = QuantumCircuit(backend.num_qubits)
qc_barriers.x(range(backend.num_qubits))
qc_barriers.barrier()
qc_barriers.delay(1600, 0)

qc_barriers.barrier()

qc_trans = transpile(qc_barriers, backend)

qc_dd = pm.run(qc_trans)

  1. I'm finding unexpected small delays in the sequence.
    Screenshot 2023-05-05 at 2 40 51 PM
    Like the 16dt and 12dt delays in the picture. Is there a way to remove them and have them in the main delay parts?

  2. Something is breaking the timeline_drawer (which is quite useful when looking at DD sequences. I don't know if this is caused by the staggered DD pass or by something else in qiskit_ibm_provider but I thought I would flag it anyway

from qiskit.visualization import timeline_drawer
timeline_drawer(qc_dd)

@dieris
Copy link
Contributor Author

dieris commented May 8, 2023

Hi @miamico , thanks for trying this out! You raise good points, however, those limitations were not introduced by this PR.

On 1), that may be necessary due to backend constraints, i.e., the allowed resolution for the timing of pulses. You can set pulse_alignment if the backend has a different timing constraint than the default (16 dt).
In some cases, you can redistribute the 'extra' time by setting the extra_slack_distribution option to try setting where this difference is going to be added ('middle' or 'edges'), provided these constraints are still satisfied.

For 2), I suggest opening a separate issue to see if the timeline drawer can be made compatible with this version of the scheduler (at least for the case where circuits don't include control flow and timing is pre-determined, see also comment).

@miamico
Copy link

miamico commented May 11, 2023

Great! Thank you. Given your comments then I think this is behaving as expected.

@kt474 kt474 requested a review from taalexander May 15, 2023 18:16
@kt474 kt474 added this to the 0.6.3 milestone Jul 31, 2023
@kt474 kt474 added the Changelog: New Feature Include in the Added section of the changelog label Jul 31, 2023
@kt474 kt474 merged commit 131189a into Qiskit:main Jul 31, 2023
18 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Changelog: New Feature Include in the Added section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable qubit-dependent dynamical decoupling sequences as a transpiler pass
5 participants