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

Fix error in schedule -> signal conversion for schedules with barrier instructions #203

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions qiskit_dynamics/pulse/pulse_to_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def get_signals(self, schedule: Schedule) -> List[DiscreteSignal]:
)

for start_sample, inst in schedule.instructions:
chan = inst.channel.name
phi = phases[chan]
freq = frequency_shifts[chan]
# get channel name if instruction has it
chan = inst.channel.name if hasattr(inst, "channel") else None
DanPuzzuoli marked this conversation as resolved.
Show resolved Hide resolved

if isinstance(inst, Play):
# get the instruction samples
inst_samples = None
Expand All @@ -178,8 +178,8 @@ def get_signals(self, schedule: Schedule) -> List[DiscreteSignal]:
times = self._dt * (start_sample + np.arange(len(inst_samples)))
samples = inst_samples * np.exp(
Array(
2.0j * np.pi * freq * times
+ 1.0j * phi
2.0j * np.pi * frequency_shifts[chan] * times
+ 1.0j * phases[chan]
+ 2.0j * np.pi * phase_accumulations[chan]
)
)
Expand Down
3 changes: 3 additions & 0 deletions releasenotes/notes/0.4/0.4-summary-3de98711c3b7aa09.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ fixes:
:class:`~qiskit.pulse.instructions.SetFrequency` and
:class:`~qiskit.pulse.instructions.ShiftFrequency` instructions has also been fixed. (`#140
<https://github.com/Qiskit/qiskit-dynamics/issues/140>`__)
- |
:class:`.InstructionToSignals` has been updated to fix an error when parsing schedules that
include barrier instructions. `#202 <https://github.com/Qiskit/qiskit-dynamics/issues/202>`__)
- |
Fixes a bug in the automatic jit-compilation of :meth:`Solver.solve` when using the ``t_eval``
kwarg with a JAX method and ``Array.default_backend() == 'jax'``. The bug is fixed by updating
Expand Down
22 changes: 22 additions & 0 deletions test/dynamics/pulse/test_pulse_to_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from qiskit import pulse
from qiskit.pulse import Schedule
from qiskit.pulse.transforms.canonicalization import block_to_schedule
from qiskit.providers.fake_provider import FakeQuito
from qiskit import QiskitError

from qiskit_dynamics.pulse import InstructionToSignals
Expand Down Expand Up @@ -320,6 +321,27 @@ def test_InstructionToSignals(self):
signals = converter.get_signals(block_to_schedule(schedule))
self.assertAllClose(signals[0].samples, gauss_get_waveform_samples, atol=1e-7, rtol=1e-7)

def test_barrier_instructions(self):
"""Test correct parsing of schedule with barrier instructions."""

# this example needs any backend with at least 2 qubits
backend = FakeQuito()

with pulse.build(backend) as sched_block:
pulse.play(pulse.Constant(duration=3, amp=0.5), pulse.DriveChannel(0))
pulse.barrier(0, 1)
pulse.play(pulse.Constant(duration=3, amp=-0.5), pulse.DriveChannel(1))

converter = InstructionToSignals(
dt=1.0, carriers={"d0": 1.0, "d1": 1.0}, channels=["d0", "d1"]
)
sched = block_to_schedule(sched_block)

sigs = converter.get_signals(sched)

self.assertAllClose(sigs[0].samples, np.array([0.5, 0.5, 0.5, 0.0, 0.0, 0.0]))
self.assertAllClose(sigs[1].samples, np.array([0.0, 0.0, 0.0, -0.5, -0.5, -0.5]))


class TestPulseToSignalsJAXTransformations(QiskitDynamicsTestCase, TestJaxBase):
"""Tests InstructionToSignals class by using Jax."""
Expand Down