def test_creation(): with pytest.raises(TypeError): Pulse(10, 0, 0, post_phase_shift=2) Pulse(cwf, 1, 0) Pulse(0, bwf, 1) Pulse(bwf, cwf, bwf) Pulse(bwf, cwf, 0, post_phase_shift=cwf) with pytest.raises(ValueError, match="The duration of"): Pulse(bwf, cwf, 0) with pytest.raises(ValueError, match="All samples of an amplitude"): Pulse(cwf, cwf, 0) Pulse.ConstantAmplitude(-1, cwf, 0) Pulse.ConstantPulse(100, -1, 0, 0) assert pls.phase == 0 assert pls2 == pls3 assert pls != pls4 assert pls4.detuning != cwf assert pls4.amplitude == pls.amplitude
def test_creation(): with pytest.raises(TypeError): Pulse(10, 0, 0, post_phase_shift=2) Pulse(cwf, 1, 0) Pulse(0, bwf, 1) Pulse(bwf, cwf, bwf) Pulse(bwf, cwf, 0, post_phase_shift=cwf) with pytest.raises(ValueError, match="durations don't match"): Pulse(bwf, cwf, 0) with pytest.raises(ValueError, match="has always to be non-negative."): Pulse(cwf, cwf, 0) Pulse.ConstantAmplitude(-1, cwf, 0) Pulse.ConstantPulse(100, -1, 0, 0) assert pls.phase == 0 assert pls2.amplitude == pls3.amplitude assert pls2.detuning == pls3.detuning assert pls2.phase == np.pi assert pls3.phase == 1 assert pls4.detuning != cwf assert pls4.amplitude == pls.amplitude
from unittest.mock import patch import numpy as np import pytest from pulser import Pulse from pulser.waveforms import BlackmanWaveform, ConstantWaveform, RampWaveform cwf = ConstantWaveform(100, -10) bwf = BlackmanWaveform(200, 3) rwf = RampWaveform(200, 0, 1) pls = Pulse(bwf, bwf, 2 * np.pi) pls2 = Pulse.ConstantPulse(100, 1, -10, -np.pi) pls3 = Pulse.ConstantAmplitude(1, cwf, -np.pi) pls4 = Pulse.ConstantDetuning(bwf, -10, 0) def test_creation(): with pytest.raises(TypeError): Pulse(10, 0, 0, post_phase_shift=2) Pulse(cwf, 1, 0) Pulse(0, bwf, 1) Pulse(bwf, cwf, bwf) Pulse(bwf, cwf, 0, post_phase_shift=cwf) with pytest.raises(ValueError, match="The duration of"): Pulse(bwf, cwf, 0) with pytest.raises(ValueError, match="All samples of an amplitude"):
def test_sequence(): seq = Sequence(reg, device) assert seq.get_duration() == 0 with pytest.raises(RuntimeError, match="empty sequence"): seq.draw() seq.declare_channel("ch0", "raman_local", initial_target="q0") seq.declare_channel("ch1", "rydberg_local", initial_target="q0") seq.declare_channel("ch2", "rydberg_global") assert seq.get_duration("ch0") == 0 assert seq.get_duration("ch2") == 0 seq.phase_shift(np.pi, "q0", basis="ground-rydberg") with patch("matplotlib.pyplot.show"): with patch("matplotlib.figure.Figure.savefig"): seq.draw(fig_name="my_sequence.pdf") seq.draw(draw_register=True, fig_name="both.pdf") pulse1 = Pulse( InterpolatedWaveform(500, [0, 1, 0]), InterpolatedWaveform(500, [-1, 1, 0]), phase=0, post_phase_shift=np.pi, ) pulse2 = Pulse.ConstantDetuning(BlackmanWaveform(1e3, np.pi / 4), 25, np.pi, post_phase_shift=1) with pytest.raises(TypeError): seq.add([1, 5, 3], "ch0") with pytest.raises(ValueError, match="amplitude goes over the maximum"): seq.add(Pulse.ConstantPulse(20, 2 * np.pi * 10, -2 * np.pi * 100, 0), "ch2") with pytest.raises(ValueError, match="detuning values go out of the range"): seq.add(Pulse.ConstantPulse(500, 2 * np.pi, -2 * np.pi * 100, 0), "ch0") with pytest.raises(ValueError, match="qubits with different phase ref"): seq.add(pulse2, "ch2") with pytest.raises(ValueError, match="Invalid protocol"): seq.add(pulse1, "ch0", protocol="now") wf_ = CompositeWaveform(BlackmanWaveform(30, 1), RampWaveform(15, 0, 2)) with pytest.raises(TypeError, match="Failed to automatically adjust"): with pytest.warns(UserWarning, match="rounded up to 48 ns"): seq.add(Pulse.ConstantAmplitude(1, wf_, 0), "ch0") pulse1_ = Pulse.ConstantPulse(499, 2, -10, 0, post_phase_shift=np.pi) with pytest.warns(UserWarning, match="rounded up to 500 ns"): seq.add(pulse1_, "ch0") seq.add(pulse1, "ch1") seq.add(pulse2, "ch2") assert seq._last("ch0").ti == 0 assert seq._last("ch0").tf == seq._last("ch1").ti assert seq._last("ch2").tf == seq._last("ch2").ti + 1000 assert seq.current_phase_ref("q0", "digital") == np.pi seq.add(pulse1, "ch2") assert seq.get_duration("ch2") == 2500 seq.add(pulse2, "ch1", protocol="no-delay") assert seq.get_duration("ch1") == 3500 seq.add(pulse1, "ch0", protocol="no-delay") assert seq._last("ch0").ti == 500 assert seq.get_duration("ch0") == 1000 assert seq.current_phase_ref("q0", "digital") == 0 seq.phase_shift(np.pi / 2, "q1") seq.target("q1", "ch0") assert seq._last_used["digital"]["q1"] == 0 assert seq._last_target["ch0"] == 1000 assert seq._last("ch0").ti == 1000 assert seq.get_duration("ch0") == 1000 seq.add(pulse1, "ch0") assert seq._last("ch0").ti == 2500 assert seq.get_duration("ch0") == 3000 seq.add(pulse1, "ch0", protocol="wait-for-all") assert seq._last("ch0").ti == 3500 assert seq.get_duration("ch2") != seq.get_duration("ch0") seq.align("ch0", "ch2") assert seq.get_duration("ch2") == seq.get_duration("ch0") with patch("matplotlib.pyplot.show"): seq.draw(draw_phase_shifts=True) assert seq.get_duration() == 4000 seq.measure(basis="digital") with patch("matplotlib.pyplot.show"): seq.draw(draw_phase_area=True) s = seq.serialize() assert json.loads(s)["__version__"] == pulser.__version__ seq_ = Sequence.deserialize(s) assert str(seq) == str(seq_)
from unittest.mock import patch import numpy as np import pytest from pulser import Pulse from pulser.waveforms import ConstantWaveform, BlackmanWaveform, RampWaveform cwf = ConstantWaveform(100, -10) bwf = BlackmanWaveform(200, 3) rwf = RampWaveform(200, 0, 1) pls = Pulse(bwf, bwf, 2 * np.pi) pls2 = Pulse.ConstantPulse(100, 1, -10, -np.pi) pls3 = Pulse.ConstantAmplitude(1, cwf, 1) pls4 = Pulse.ConstantDetuning(bwf, -10, 0) def test_creation(): with pytest.raises(TypeError): Pulse(10, 0, 0, post_phase_shift=2) Pulse(cwf, 1, 0) Pulse(0, bwf, 1) Pulse(bwf, cwf, bwf) Pulse(bwf, cwf, 0, post_phase_shift=cwf) with pytest.raises(ValueError, match="durations don't match"): Pulse(bwf, cwf, 0) with pytest.raises(ValueError, match="has always to be non-negative."):