Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Data Management Workshop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ml4q
Data Management Workshop
Commits
aafed1a2
Commit
aafed1a2
authored
Apr 18, 2024
by
Simon Sebastian Humpohl
Browse files
Options
Downloads
Patches
Plain Diff
Improve documentation
parent
c93413da
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+4
-4
4 additions, 4 deletions
.gitignore
DataGenerationQuTipT2.ipynb
+29
-19
29 additions, 19 deletions
DataGenerationQuTipT2.ipynb
with
33 additions
and
23 deletions
.gitignore
+
4
−
4
View file @
aafed1a2
.ipynb_checkpoints/
.ipynb_checkpoints
simulation_venv/
__pycache__
__pycache__
/.jupyter_ystore.db
.jupyter_ystore.db
/.virtual_documents/
.virtual_documents
.venv
This diff is collapsed.
Click to expand it.
DataGenerationQuTipT2.ipynb
+
29
−
19
View file @
aafed1a2
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
"source": [
"source": [
"# Data generation\n",
"# Data generation\n",
"\n",
"\n",
"This notebook simulates some kind of T2* Ramsey characterization.\n",
"This notebook simulates some kind of T2* Ramsey characterization
although we ommited the pulsing for simplicity
.\n",
"\n",
"\n",
"## Imports"
"## Imports"
]
]
...
@@ -25,11 +25,12 @@
...
@@ -25,11 +25,12 @@
"\n",
"\n",
"# mostly tuse qutip o add more complex dependencies \n",
"# mostly tuse qutip o add more complex dependencies \n",
"# It's not a necessity to do the ramsey experiment \n",
"# It's not a necessity to do the ramsey experiment \n",
"from qutip import mesolve, Options, basis, sigmax, sigmay, sigmaz\n",
"from qutip import mesolve, Options, basis, sigmax, sigmay, sigmaz
, Qobj
\n",
"\n",
"\n",
"from matplotlib import pyplot as plt\n",
"from matplotlib import pyplot as plt\n",
"\n",
"\n",
"data_dir = pathlib.Path(\"data\")"
"data_dir = pathlib.Path(\"data\")\n",
"data_dir.mkdir(exist_ok=True)"
]
]
},
},
{
{
...
@@ -56,14 +57,27 @@
...
@@ -56,14 +57,27 @@
"noise_sigma = 0.02\n",
"noise_sigma = 0.02\n",
"rng = np.random.default_rng(seed=42)\n",
"rng = np.random.default_rng(seed=42)\n",
"\n",
"\n",
"psi0 = 1/np.sqrt(2)*(basis(2, 0)+basis(2, 1))\n",
"hadamard = 1 / np.sqrt(2.0) * Qobj([[1, 1],\n",
" [1, -1]])\n",
"\n",
"\n",
"psi0 = basis(2, 0)\n",
"# initialize to Hadamard |0> = |+> = |0> + |1>\n",
"psi_plus = hadamard @ psi0\n",
"\n",
"# hamiltonian\n",
"H = 2*np.pi * detuning * sigmaz()\n",
"H = 2*np.pi * detuning * sigmaz()\n",
"\n",
"\n",
"result = mesolve(H, psi0, times, [np.sqrt(1/T2) * sigmax()], e_ops=[sigmax()])\n",
"# meas operator\n",
"e_op = psi_plus @ psi_plus.dag()\n",
"\n",
"result = mesolve(H, psi_plus, times,\n",
" # collapse operator \n",
" c_ops=[np.sqrt(1/T2) * sigmax()],\n",
" # operator for expectation value\n",
" e_ops=[e_op])\n",
"\n",
"\n",
"# Get probability data\n",
"# Get probability data
.
\n",
"P_1 = result.expect
[0]*0.5+0.5
\n",
"P_1
,
= result.expect\n",
"\n",
"\n",
"# add calibration points\n",
"# add calibration points\n",
"clean_signal = P_1 * scale + offset\n",
"clean_signal = P_1 * scale + offset\n",
...
@@ -76,26 +90,22 @@
...
@@ -76,26 +90,22 @@
"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",
"metadata": {},
"source": [
"# Plot data (Just for debugging in this notebook)"
]
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"# plot signal and calibration for debugging\n",
"\n",
"fig, ax = plt.subplots()\n",
"fig, ax = plt.subplots()\n",
"ax.plot(times, raw_signal, \".\")\n",
"ax.plot(times, raw_signal, \".\"
, label=\"Signal\"
)\n",
"plt.xlabel('t ($\\mathrm{\\mu}$s)')\n",
"plt.xlabel('t ($\\mathrm{\\mu}$s)')\n",
"plt.ylabel('$U (V)$')\n",
"plt.ylabel('$U (V)$')\n",
"\n",
"\n",
"ax.plot(calib_1, \".\")\n",
"ax.plot(calib_1, \".\", label=\"Calibration 1\")\n",
"ax.plot(calib_0, \".\")\n"
"ax.plot(calib_0, \".\", label=\"Calibration 0\")\n",
"plt.legend()"
]
]
},
},
{
{
...
@@ -171,7 +181,7 @@
...
@@ -171,7 +181,7 @@
"kernelspec": {
"kernelspec": {
"display_name": "ML4Q",
"display_name": "ML4Q",
"language": "python",
"language": "python",
"name": "
ml4qws1
"
"name": "
python3
"
},
},
"language_info": {
"language_info": {
"codemirror_mode": {
"codemirror_mode": {
...
@@ -183,7 +193,7 @@
...
@@ -183,7 +193,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.1
1.2
"
"version": "3.1
0.11
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% 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
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment