def seq_rydberg() -> pulser.Sequence: reg = pulser.Register.from_coordinates(np.array([[0.0, 0.0], [2.0, 0.0]]), prefix="q") seq = pulser.Sequence(reg, MockDevice) seq.declare_channel("ch0", "rydberg_global") seq.declare_channel("ch1", "rydberg_local", initial_target="q0") seq.add( Pulse.ConstantDetuning(BlackmanWaveform(100, np.pi / 8), 0.0, 0.0), "ch0", ) seq.delay(20, "ch0") seq.add( Pulse.ConstantAmplitude(0.0, BlackmanWaveform(100, np.pi / 8), 0.0), "ch0", ) seq.add( Pulse.ConstantDetuning(BlackmanWaveform(100, np.pi / 8), 0.0, 0.0), "ch1", ) seq.target("q1", "ch1") seq.add( Pulse.ConstantAmplitude(1.0, BlackmanWaveform(100, np.pi / 8), 0.0), "ch1", ) seq.target(["q0", "q1"], "ch1") seq.add( Pulse.ConstantDetuning(BlackmanWaveform(100, np.pi / 8), 0.0, 0.0), "ch1", ) seq.measure() return seq
def test_SLM_samples(seq_with_SLM): pulse = Pulse.ConstantDetuning(BlackmanWaveform(200, np.pi / 2), 0.0, 0.0) a_samples = pulse.amplitude.samples def z() -> np.ndarray: return np.zeros(seq_with_SLM.get_duration()) want: dict = { "Global": {}, "Local": { "ground-rydberg": { "batman": { "amp": z(), "det": z(), "phase": z() }, "superman": { "amp": z(), "det": z(), "phase": z() }, } }, } want["Local"]["ground-rydberg"]["batman"]["amp"][200:400] = a_samples want["Local"]["ground-rydberg"]["superman"]["amp"][0:200] = a_samples want["Local"]["ground-rydberg"]["superman"]["amp"][200:400] = a_samples got = sample(seq_with_SLM) assert_nested_dict_equality(got, want)
def test_amplitude_noise(): """Test the noise related to the amplitude profile of global pulses.""" N = 100 amplitude = 1.0 waist_width = 2.0 # µm coords = np.array([[-2.0, 0.0], [0.0, 0.0], [2.0, 0.0]]) reg = pulser.Register.from_coordinates(coords, prefix="q") seq = pulser.Sequence(reg, MockDevice) seq.declare_channel("ch0", "rydberg_global") seq.add( Pulse.ConstantAmplitude(amplitude, ConstantWaveform(N, 0.0), 0.0), "ch0", ) seq.measure() def expected_samples(vec: np.ndarray) -> np.ndarray: """Defines the non-noisy effect of a gaussian amplitude profile.""" r = np.linalg.norm(vec) a = np.ones(N) a *= amplitude a *= np.exp(-((r / waist_width)**2)) return a s = sample( seq, global_noises=[noises.amplitude(reg, waist_width, random=False)]) for q, coords in reg.qubits.items(): got = s["Local"]["ground-rydberg"][q]["amp"] want = expected_samples(coords) np.testing.assert_equal(got, want)
def mod_seq(mod_device: Device) -> pulser.Sequence: reg = pulser.Register.from_coordinates(np.array([[0.0, 0.0]]), prefix="q") seq = pulser.Sequence(reg, mod_device) seq.declare_channel("ch0", "rydberg_global") seq.add( Pulse.ConstantDetuning(BlackmanWaveform(1000, np.pi / 2), 0.0, 0.0), "ch0", ) seq.measure() return seq
def seq_with_SLM() -> pulser.Sequence: q_dict = { "batman": np.array([-4.0, 0.0]), # sometimes masked "superman": np.array([4.0, 0.0]), # always unmasked } reg = pulser.Register(q_dict) seq = pulser.Sequence(reg, MockDevice) seq.declare_channel("ch0", "rydberg_global") seq.config_slm_mask(["batman"]) seq.add( Pulse.ConstantDetuning(BlackmanWaveform(200, np.pi / 2), 0.0, 0.0), "ch0", ) seq.add( Pulse.ConstantDetuning(BlackmanWaveform(200, np.pi / 2), 0.0, 0.0), "ch0", ) seq.measure() return seq
def test_inXY() -> None: """Test sequence in XY mode.""" pulse = Pulse( BlackmanWaveform(200, np.pi / 2), RampWaveform(200, -np.pi / 2, np.pi / 2), 0.0, ) reg = pulser.Register.from_coordinates(np.array([[0.0, 0.0]]), prefix="q") seq = pulser.Sequence(reg, MockDevice) seq.declare_channel("ch0", "mw_global") seq.add(pulse, "ch0") seq.measure(basis="XY") assert_same_samples_as_sim(seq)
def test_one_pulse_sampling(): """Test the sample function on a one-pulse sequence.""" reg = pulser.Register.square(1, prefix="q") seq = pulser.Sequence(reg, MockDevice) seq.declare_channel("ch0", "rydberg_global") N = 1000 amp_wf = BlackmanWaveform(N, np.pi) det_wf = RampWaveform(N, -np.pi / 2, np.pi / 2) phase = 1.234 seq.add(Pulse(amp_wf, det_wf, phase), "ch0") seq.measure() got = sample(seq)["Global"]["ground-rydberg"] want = (amp_wf.samples, det_wf.samples, np.ones(N) * phase) for i, key in enumerate(["amp", "det", "phase"]): np.testing.assert_array_equal(got[key], want[i])
def seqs(seq_rydberg) -> list[pulser.Sequence]: seqs: list[pulser.Sequence] = [] pulse = Pulse( BlackmanWaveform(200, np.pi / 2), RampWaveform(200, -np.pi / 2, np.pi / 2), 0.0, ) reg = pulser.Register.from_coordinates(np.array([[0.0, 0.0]]), prefix="q") seq = pulser.Sequence(reg, MockDevice) seq.declare_channel("ch0", "raman_global") seq.add(pulse, "ch0") seq.measure() seqs.append(deepcopy(seq)) seqs.append(seq_rydberg) return seqs
def test_doppler_noise(): """What is exactly the doppler noise here? A constant detuning shift per pulse seems weird. A global shift seems more reasonable, but how can it be constant during the all sequence? It is not clear to me here, I find the current implementation in the simulation module to be unsatisfactory. No surprise I make it fail on purpose right now 😅 """ N = 100 det_value = np.pi reg = pulser.Register.from_coordinates(np.array([[0.0, 0.0]]), prefix="q") seq = pulser.Sequence(reg, MockDevice) seq.declare_channel("ch0", "rydberg_global") for _ in range(3): seq.add( Pulse.ConstantDetuning(ConstantWaveform(N, 1.0), det_value, 0.0), "ch0", ) seq.delay(100, "ch0") seq.measure() MASS = 1.45e-25 # kg KB = 1.38e-23 # J/K KEFF = 8.7 # µm^-1 doppler_sigma = KEFF * np.sqrt(KB * 50.0e-6 / MASS) seed = 42 rng = np.random.default_rng(seed) shifts = rng.normal(0, doppler_sigma, 3) want = np.zeros(6 * N) want[0:100] = det_value + shifts[0] want[200:300] = det_value + shifts[1] want[400:500] = det_value + shifts[2] local_noises = [noises.doppler(reg, doppler_sigma, seed=seed)] samples = sample(seq, common_noises=local_noises) got = samples["Local"]["ground-rydberg"]["q0"]["det"] np.testing.assert_array_equal(got, want)