def loss_piecewise_linear(atoms: AtomArrangement, x: list):
assert len(x) == 3
Delta_start = -13 * 2 * np.pi * 1e6
Delta_0 = 11 * 2 * np.pi * 1e6
Delta_end = 11 * 2 * np.pi * 1e6
Omega_max = 2.5e7
T_max = 0.6 * 1e-6
Deltas = TimeSeries()
Deltas.put(0.0, Delta_start)
Deltas.put(0.05 * 1e-6, Delta_start)
Deltas.put(0.2 * 1e-6, Delta_0 * x[0])
Deltas.put(0.3 * 1e-6, Delta_0 * x[1])
Deltas.put(0.4 * 1e-6, Delta_0 * x[2])
Deltas.put(0.55 * 1e-6, Delta_end)
Deltas.put(T_max, Delta_end)
Omegas = TimeSeries()
Omegas.put(0.0, 0.0)
Omegas.put(0.05 * 1e-6, 0.0)
Omegas.put(0.1 * 1e-6, Omega_max)
Omegas.put(0.5 * 1e-6, Omega_max)
Omegas.put(0.55 * 1e-6, 0.0)
Omegas.put(T_max, 0.0)
Phi = TimeSeries().put(0.0, 0.0).put(T_max, 0.0)
H = DrivingField(amplitude=Omegas, phase=Phi, detuning=Deltas)
program = AnalogHamiltonianSimulation(hamiltonian=H, register=atoms)
device = LocalSimulator("braket_ahs")
results = device.run(program, shots=1000, steps=100).result()
r_counts = []
states = ["e", "r", "g"]
for shot in results.measurements:
pre = shot.pre_sequence
post = shot.post_sequence
state_idx = np.array(pre) * (1 + np.array(post))
state_labels = [states[s_idx] for s_idx in state_idx]
r_count = np.count_nonzero([sl == "r" for sl in state_labels]) / len(atoms)
r_counts.append(r_count)
density_sum = np.mean(r_counts)
return -density_sum, results, Deltas
Join the Discussion
Comments (0)
No comments yet. Be the first to share your thoughts!