diff --git a/qiskit_dynamics/pulse/pulse_to_signals.py b/qiskit_dynamics/pulse/pulse_to_signals.py index b91f88bc9..1377d5941 100644 --- a/qiskit_dynamics/pulse/pulse_to_signals.py +++ b/qiskit_dynamics/pulse/pulse_to_signals.py @@ -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 + if isinstance(inst, Play): # get the instruction samples inst_samples = None @@ -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] ) ) diff --git a/releasenotes/notes/0.4/0.4-summary-3de98711c3b7aa09.yaml b/releasenotes/notes/0.4/0.4-summary-3de98711c3b7aa09.yaml index 7fc784cf7..7fade71a3 100644 --- a/releasenotes/notes/0.4/0.4-summary-3de98711c3b7aa09.yaml +++ b/releasenotes/notes/0.4/0.4-summary-3de98711c3b7aa09.yaml @@ -83,6 +83,9 @@ fixes: :class:`~qiskit.pulse.instructions.SetFrequency` and :class:`~qiskit.pulse.instructions.ShiftFrequency` instructions has also been fixed. (`#140 `__) + - | + :class:`.InstructionToSignals` has been updated to fix an error when parsing schedules that + include barrier instructions. `#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 diff --git a/test/dynamics/pulse/test_pulse_to_signals.py b/test/dynamics/pulse/test_pulse_to_signals.py index 735079afe..8652ac60a 100644 --- a/test/dynamics/pulse/test_pulse_to_signals.py +++ b/test/dynamics/pulse/test_pulse_to_signals.py @@ -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 @@ -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."""