Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"metadata": {},
"outputs": [],
"source": [
"from labcore.measurement import *"
"from labcore.sweep import *"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"import numpy as np\n",
"import qcodes as qc\n",
"\n",
"from labcore.measurement import *"
"from labcore.sweep import *"
]
},
{
Expand Down
390 changes: 390 additions & 0 deletions doc/examples/opx_demo/Simple OPX setup demo without mixers.ipynb

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions doc/examples/opx_demo/parameter_manager-simple_demo_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"simple_demo_params.readout.IF": {
"unit": "Hz",
"value": 50000000.0
},
"simple_demo_params.readout.short.amp": {
"unit": "",
"value": 0.25
},
"simple_demo_params.readout.short.buffer": {
"unit": "ns",
"value": 100
},
"simple_demo_params.readout.short.len": {
"unit": "ns",
"value": 1000
}
}
106 changes: 106 additions & 0 deletions doc/examples/opx_demo/qmcfg_simple_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""
A very basic OPX config
"""

from labcore.opx.config import QMConfig as QMConfig_


class QMConfig(QMConfig_):

def config_(self):

params = self.params

cfg = {
'version': 1,

# The hardware
'controllers': {

# edit this part so the hardware connections match your setup
'con2': {
'type': 'opx1',
'analog_outputs': {
5: {'offset': 0.0},
},
'digital_outputs': {
1: {},
},
'analog_inputs': {
2: {'offset': 0.0},
},
},
},

# The logical elements
'elements': {

'readout': {
'singleInput': {
'port': ('con2', 5),
},
'digitalInputs': {
'readout_trigger': {
'port': ('con2', 1),
'delay': 144,
'buffer': 0,
},
},

'intermediate_frequency': params.readout.IF(),

'operations': {
'readout_short': 'readout_short_pulse',
},

'outputs': {
'out1': ('con2', 2),
},

'time_of_flight': 188+28,
'smearing': 0,
},
},

# The pulses
'pulses': {

'readout_short_pulse': {
'operation': 'measurement',
'length': params.readout.short.len(),
'waveforms': {
'single': 'box_readout_wf'
},
'digital_marker': 'ON',
},

},

# the waveforms
'waveforms': {
'const_wf': {
'type': 'constant',
'sample': 0.1,
},
'zero_wf': {
'type': 'constant',
'sample': 0.0,
},
'box_readout_wf': {
'type': 'arbitrary',
'samples': [0.0] * params.readout.short.buffer() \
+ [params.readout.short.amp()] * \
(params.readout.short.len()-2*params.readout.short.buffer()) \
+ [0.0] * params.readout.short.buffer(),
},
},

'digital_waveforms': {

'ON': {
'samples': [(1, 0)]
},

},
}
return cfg
Empty file added labcore/analysis/__init__.py
Empty file.
114 changes: 114 additions & 0 deletions labcore/analysis/common_fits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import numpy as np

from plottr.analyzer.fitters.fitter_base import Fit


class ExponentialDecay(Fit):
@staticmethod
def model(coordinates, A, of, tau) -> np.ndarray:
"""$A * \exp(-x/\tau) + of$"""
return A * np.exp(-coordinates/tau) + of

@staticmethod
def guess(coordinates, data):

# offset guess: The mean of the last 10 percent of the data
of = np.mean(data[-data.size//10:])

# amplitude guess: difference between max and min.
A = np.abs(np.max(data) - np.min(data))
if data[0] < data[-1]:
A *= -1

# tau guess: pick the point where we reach roughly 1/e
one_over_e_val = of + A/3.
one_over_e_idx = np.argmin(np.abs(data-one_over_e_val))
tau = coordinates[one_over_e_idx]

return dict(A=A, of=of, tau=tau)


class ExponentiallyDecayingSine(Fit):
@staticmethod
def model(coordinates, A, of, f, phi, tau) -> np.ndarray:
"""$A \sin(2*\pi*(f*x + \phi/360)) \exp(-x/\tau) + of$"""
return A * np.sin(2 * np.pi * (f * coordinates + phi/360)) * np.exp(-coordinates/tau) + of

@staticmethod
def guess(coordinates, data):
"""This guess will ignore the first value because since it usually is not relaiable."""

# offset guess: The mean of the data
of = np.mean(data)

# amplitude guess: difference between max and min.
A = np.abs(np.max(data) - np.min(data)) / 2.
if data[0] < data[-1]:
A *= -1

# f guess: Maximum of the absolute value of the fourier transform.
fft_data = np.fft.rfft(data)[1:]
fft_coordinates = np.fft.rfftfreq(data.size, coordinates[1] - coordinates[0])[1:]

# note to confirm, could there be multiple peaks? I am always taking the first one here.
f_max_index = np.argmax(fft_data)
f = fft_coordinates[f_max_index]

# phi guess
phi = -np.angle(fft_data[f_max_index], deg=True)

# tau guess: pick the point where we reach roughly 1/e
one_over_e_val = of + A/3.
one_over_e_idx = np.argmin(np.abs(data-one_over_e_val))
tau = coordinates[one_over_e_idx]

return dict(A=A, of=of, phi=phi, f=f, tau=tau)

class Cosine(Fit):
@staticmethod
def model(coordinates, A, of, f, phi) -> np.ndarray:
"""$A \sin(2*\pi*(f*x + \phi/360)) + of$"""
return A * np.cos(2 * np.pi * (f * coordinates + phi/360.)) + of

@staticmethod
def guess(coordinates, data):
"""This guess will ignore the first value because since it usually is not relaiable."""

# offset guess: The mean of the data
of = np.mean(data)

# amplitude guess: difference between max and min.
A = np.abs(np.max(data) - np.min(data)) / 2.

# f guess: Maximum of the absolute value of the fourier transform.
fft_data = np.fft.rfft(data)[1:]
fft_coordinates = np.fft.rfftfreq(data.size, coordinates[1] - coordinates[0])[1:]

# note to confirm, could there be multiple peaks? I am always taking the first one here.
f_max_index = np.argmax(np.abs(fft_data))
f = fft_coordinates[f_max_index]

# phi guess
phi = -np.angle(fft_data[f_max_index], deg=True)

guess = dict(A=A, of=of, phi=phi, f=f)

return guess


class Gaussian(Fit):
@staticmethod
def model(coordinates, x0, sigma, A, of):
"""$A * np.exp(-(x-x_0)^2/(2\sigma^2)) + of"""
return A * np.exp(-(coordinates - x0) ** 2 / (2 * sigma ** 2)) + of

@staticmethod
def guess(coordinates, data):
# TODO: very crude at the moment, not likely to work well with not-so-nice data.
of = np.mean(data)
dev = data - of
i_max = np.argmax(np.abs(dev))
x0 = coordinates[i_max]
A = data[i_max] - of
sigma = np.abs((coordinates[-1] - coordinates[0])) / 20
return dict(x0=x0, sigma=sigma, A=A, of=of)
Loading