Skip to content
Snippets Groups Projects
Commit aafed1a2 authored by Simon Sebastian Humpohl's avatar Simon Sebastian Humpohl
Browse files

Improve documentation

parent c93413da
No related branches found
No related tags found
No related merge requests found
.ipynb_checkpoints/ .ipynb_checkpoints
simulation_venv/
__pycache__ __pycache__
/.jupyter_ystore.db .jupyter_ystore.db
/.virtual_documents/ .virtual_documents
.venv
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Data generation # Data generation
This notebook simulates some kind of T2* Ramsey characterization. This notebook simulates some kind of T2* Ramsey characterization although we ommited the pulsing for simplicity.
## Imports ## Imports
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import pathlib import pathlib
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import xarray as xr import xarray as xr
# mostly tuse qutip o add more complex dependencies # mostly tuse qutip o add more complex dependencies
# It's not a necessity to do the ramsey experiment # It's not a necessity to do the ramsey experiment
from qutip import mesolve, Options, basis, sigmax, sigmay, sigmaz from qutip import mesolve, Options, basis, sigmax, sigmay, sigmaz, Qobj
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
data_dir = pathlib.Path("data") data_dir = pathlib.Path("data")
data_dir.mkdir(exist_ok=True)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Create T2 Dataset with noise # Create T2 Dataset with noise
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
n_calib = 5 n_calib = 5
times = np.linspace(0.0, 25.0, 250) times = np.linspace(0.0, 25.0, 250)
# system properties # system properties
detuning = 0.2 detuning = 0.2
T2 = 5 T2 = 5
offset = 0.2 offset = 0.2
scale = 0.5 scale = 0.5
noise_sigma = 0.02 noise_sigma = 0.02
rng = np.random.default_rng(seed=42) rng = np.random.default_rng(seed=42)
psi0 = 1/np.sqrt(2)*(basis(2, 0)+basis(2, 1)) hadamard = 1 / np.sqrt(2.0) * Qobj([[1, 1],
[1, -1]])
psi0 = basis(2, 0)
# initialize to Hadamard |0> = |+> = |0> + |1>
psi_plus = hadamard @ psi0
# hamiltonian
H = 2*np.pi * detuning * sigmaz() H = 2*np.pi * detuning * sigmaz()
result = mesolve(H, psi0, times, [np.sqrt(1/T2) * sigmax()], e_ops=[sigmax()]) # meas operator
e_op = psi_plus @ psi_plus.dag()
result = mesolve(H, psi_plus, times,
# collapse operator
c_ops=[np.sqrt(1/T2) * sigmax()],
# operator for expectation value
e_ops=[e_op])
# Get probability data # Get probability data.
P_1 = result.expect[0]*0.5+0.5 P_1, = result.expect
# add calibration points # add calibration points
clean_signal = P_1 * scale + offset clean_signal = P_1 * scale + offset
clean_calib_0 = np.ones(n_calib) * offset clean_calib_0 = np.ones(n_calib) * offset
clean_calib_1 = offset + scale * np.ones(n_calib) clean_calib_1 = offset + scale * np.ones(n_calib)
# add white noise # add white noise
raw_signal = clean_signal + rng.normal(0, noise_sigma, clean_signal.size) raw_signal = clean_signal + rng.normal(0, noise_sigma, clean_signal.size)
calib_0 = clean_calib_0 + rng.normal(0, noise_sigma, clean_calib_0.size) calib_0 = clean_calib_0 + rng.normal(0, noise_sigma, clean_calib_0.size)
calib_1 = clean_calib_1 + rng.normal(0, noise_sigma, clean_calib_1.size) calib_1 = clean_calib_1 + rng.normal(0, noise_sigma, clean_calib_1.size)
``` ```
%% Cell type:markdown id: tags:
# Plot data (Just for debugging in this notebook)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# plot signal and calibration for debugging
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.plot(times, raw_signal, ".") ax.plot(times, raw_signal, ".", label="Signal")
plt.xlabel('t ($\mathrm{\mu}$s)') plt.xlabel('t ($\mathrm{\mu}$s)')
plt.ylabel('$U (V)$') plt.ylabel('$U (V)$')
ax.plot(calib_1, ".") ax.plot(calib_1, ".", label="Calibration 1")
ax.plot(calib_0, ".") ax.plot(calib_0, ".", label="Calibration 0")
plt.legend()
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Save csv file via pandas # Save csv file via pandas
CSV does not allow attaching metadata so we would need to hack our calibration into the file or create a separate one. CSV does not allow attaching metadata so we would need to hack our calibration into the file or create a separate one.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
dataframe = pd.DataFrame() dataframe = pd.DataFrame()
csv_times = np.concatenate([times, np.full(10, np.nan)]) csv_times = np.concatenate([times, np.full(10, np.nan)])
csv_U = np.concatenate([raw_signal, calib_1, calib_0]) csv_U = np.concatenate([raw_signal, calib_1, calib_0])
dataframe['time [us]'] = csv_times dataframe['time [us]'] = csv_times
dataframe['U [V]'] = csv_U dataframe['U [V]'] = csv_U
dataframe.to_csv(data_dir/ 'P_one_vs_time.csv', encoding='utf-8', header=True, index=False) dataframe.to_csv(data_dir/ 'P_one_vs_time.csv', encoding='utf-8', header=True, index=False)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Save to netCDF via xarray # Save to netCDF via xarray
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
nc_U = xr.Variable( nc_U = xr.Variable(
data=raw_signal, data=raw_signal,
dims=('time [us]',), dims=('time [us]',),
attrs={ attrs={
'calib_1 [V]': calib_1, 'calib_1 [V]': calib_1,
'calib_0 [V]': calib_0, 'calib_0 [V]': calib_0,
} }
) )
dataset = xr.Dataset( dataset = xr.Dataset(
{ {
'U [V]': nc_U 'U [V]': nc_U
}, },
coords={'time [us]': times}, coords={'time [us]': times},
attrs={ attrs={
'comment': "Ramsey T2* experiment. Each voltage curve has callibration measurements for 0 and 1 probability." 'comment': "Ramsey T2* experiment. Each voltage curve has callibration measurements for 0 and 1 probability."
} }
) )
dataset.to_netcdf(data_dir / 'P_one_vs_time.nc') dataset.to_netcdf(data_dir / 'P_one_vs_time.nc')
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment