Skip to content

Results are limited to State Vector emulator (EMU_SV) v1.2.7

Product news
You are reading State Vector emulator (EMU_SV) v1.2.7, an older version of this documentation. Go to the latest version (v2.11.0)

Emulation of sequences: AFM state sequence

import numpy as np
import matplotlib.pyplot as plt
import pulser
# Setup
L = 10
Omega_max = 2.3 * 2 * np.pi
U = Omega_max / 2.3
delta_0 = -3 * U
delta_f = 1 * U
t_rise = 2000
t_fall = 2000
t_sweep = (delta_f - delta_0) / (2 * np.pi * 10) * 5000
# Define a ring of atoms distanced by a blockade radius distance:
R_interatomic = pulser.MockDevice.rydberg_blockade_radius(U)
coords = (
R_interatomic
/ (2 * np.sin(np.pi / L))
* np.array(
[
(np.cos(theta * 2 * np.pi / L), np.sin(theta * 2 * np.pi / L))
for theta in range(L)
]
)
)
# ring, periodic register
reg = pulser.Register.from_coordinates(coords, prefix="q")
# or try open boundaries
#reg = pulser.Register.rectangle(1,L,spacing=R_interatomic/1.2, prefix="q")
reg.draw(blockade_radius=R_interatomic, draw_half_radius=True, draw_graph=True)
rise = pulser.Pulse.ConstantDetuning(
pulser.RampWaveform(t_rise, 0.0, Omega_max), delta_0, 0.0
)
sweep = pulser.Pulse.ConstantAmplitude(
Omega_max, pulser.RampWaveform(t_sweep, delta_0, delta_f), 0.0
)
fall = pulser.Pulse.ConstantDetuning(
pulser.RampWaveform(t_fall, Omega_max, 0.0), delta_f, 0.0
)
seq = pulser.Sequence(reg, pulser.MockDevice)
seq.declare_channel("global", "rydberg_global")
seq.add(rise, "global")
seq.add(sweep, "global")
seq.add(fall, "global")
seq.draw()

First, we initialize the state vector backend:

from emu_sv import SVBackend
bknd = SVBackend()
from emu_sv import StateResult, SVConfig, QubitDensity
dt = 10 # timestep in ns
seq_duration = seq.get_duration()
eval_times = list(range(0, seq_duration + dt, dt))
#magnetization is given by -1+2*qubit_density
density = QubitDensity(evaluation_times=eval_times, basis=("r","g"), nqubits=L)
state = StateResult(evaluation_times=[seq_duration])
config = SVConfig(dt=dt, observables = [density, state], log_level=2000)
results = bknd.run(seq, config)

The Results object returned at the end of an emulation run, is a dictionary that contains the observables defined above, at each time step. We can access them using their name and time. The Results object that we created contains the final quantum state for example:

results["state"][seq_duration].vector[:10]
#getting the observables names
results.get_result_names()
final_state = results["state"][seq_duration]
counts = final_state.sample(1000)
large_counts = {k: v for k, v in counts.items() if v > 5}
plt.figure(figsize=(15, 4))
plt.xticks(rotation=90, fontsize=14)
plt.title("Most frequent observations")
plt.bar(large_counts.keys(), large_counts.values())
Terminal window
times = np.array(eval_times)
mag = np.stack([-1.0+2.0*np.array(results["qubit_density"][t]) for t in eval_times[1:]], axis=1)
fig, axs = plt.subplots(1,2, figsize=(8,4))
for i in range(L):
axs[0].plot(eval_times[1:], mag[i,:])
axs[0].set_xlabel("time [ns]")
axs[0].set_ylabel(r"$\langle Z_i\rangle$")
pc = axs[1].pcolor(eval_times[1:], range(L), mag)
axs[1].set_xlabel("time [ns]")
axs[1].set_ylabel("qubit")
fig.colorbar(pc, ax=axs[1], label = r"$\langle Z_i\rangle$")