-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.py
68 lines (56 loc) · 2.51 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
import pandas as pd
from analogrb.gatefactory import UniformNNHGateFactory
from analogrb.channel import DepolarizingChannel
from analogrb.bosonic import OnSiteIntNNHamiltonian, NonintNNHamiltonian
from analogrb.arb_protocol import simulate_data_acquisition, postprocess, aggregate
# number of nodes.
d = 4
# number of particles.
n = 2
# the y dimension of the lattice.
ydim = d
# Set if the system is interacting or not.
interacting_gates = False
# Build the Hamiltonian with which the system will be time evolved.
Hamiltonian = OnSiteIntNNHamiltonian(d, n, ydim) if interacting_gates else NonintNNHamiltonian(d, n, ydim)
# The evolution time of the Hamiltonian
time = 1.
# When called, returns a random unitary, here a unitary from a uniformly drawn NN = nearest neighbour Hamiltonian.
gatefactory = iter(UniformNNHGateFactory(Hamiltonian, time = time))
# The initial quantum state, here the |0x0| density matrix.
rho_init = np.zeros((Hamiltonian.fock_dim, Hamiltonian.fock_dim), dtype=np.complex128)
rho_init[0, 0] = 1.
# Set the error channel.
depol_param = 0.05
error_channel = DepolarizingChannel(depol_param)
# Set the parameters to run the arb protocol. ms are the depths of the quenches.
ms = [5, 10, 15]
# How many time the protocol is repeated.
naverage = 10
save = True
data_path = simulate_data_acquisition(d, n, interacting_gates, ms, gatefactory, rho_init, error_channel, naverage, save)
data = postprocess(data_path)
df = pd.DataFrame(data)
# Set the statistical analysis paramters.
nbootstraps = 100
confidence = 95
start_fitting = 10
df_result, df_result_capped, names = aggregate(data_path, start_fitting, nbootstraps, confidence)
import matplotlib.pyplot as plt
from analogrb.save_load import extract_from_data
from analogrb.bootstrap import EXP_FUNC
COLORS = ['#469DD4', '#DB3932', '#638537', '#853763', '#D79B00'] # blue, red, green, purple, orange
for k, name in enumerate(names):
ms, qs = extract_from_data(df, name, 'm', list)
color = COLORS[k]
plt.scatter(*extract_from_data(df, name, 'm'), alpha=0.1, color=color)
ms = df_result.loc[name, 'm']
plt.errorbar(ms, df_result.loc[name, 'avg'], yerr=df_result.loc[name, 'yerr'], fmt='x', capsize=2, color=color, label=f"irrep {name[2:]}")
ms_finespaced = np.linspace(np.min(ms), np.max(ms), len(ms)*20)
plt.plot(ms_finespaced, EXP_FUNC(ms_finespaced, *df_result.loc[name, 'popt']), '--', color = color)
print(f"irrep {name[2:]} popt: A, p = {df_result.loc[name, 'popt']}")
plt.ylabel('q')
plt.xlabel('m')
plt.legend()
plt.show()