Sweep of sweep #4561
Unanswered
DavidMerges
asked this question in
Q&A
Sweep of sweep
#4561
Replies: 2 comments
-
This works: na.n_points(11)
context_meas = Measurement(exp=tutorial_exp, station=station, name='context_example')
context_meas.register_parameter(na.sweep_trace)
with context_meas.run() as datasaver:
na.start(1000)
na.stop(2000)
datasaver.add_result(
(na.sweep_paramter, na.sweep_paramter()),
(na.sweep_trace, na.sweep_trace())
)
dataset = datasaver.dataset
plot_dataset(dataset) But this does not: na.n_points(11)
context_meas = Measurement(exp=tutorial_exp, station=station, name='context_example')
context_meas.register_parameter(na.sweep_trace)
with context_meas.run() as datasaver:
na.start(1000)
na.stop(2000)
datasaver.add_result(
(na.sweep_paramter, na.sweep_paramter()),
(na.sweep_trace, na.sweep_trace())
)
na.start(2100)
na.stop(3100)
datasaver.add_result(
(na.sweep_paramter, na.sweep_paramter()),
(na.sweep_trace, na.sweep_trace())
)
dataset = datasaver.dataset
plot_dataset(dataset) IndexError: index 2 is out of bounds for axis 0 with size 2 I'm still missing some understanding I guess |
Beta Was this translation helpful? Give feedback.
0 replies
-
Picked up working with Qcodes again. If anybody does know a better option I would welcome the input. Thank you, import qcodes as qc
from qcodes.dataset import (
Measurement,
experiments,
initialise_or_create_database_at,
load_by_run_spec,
load_or_create_experiment,
)
## Integrated plotting module
from qcodes.dataset.plotting import plot_dataset
from MultipleSweeps import MultipleSweeps
from DummyNetworkAnalyzer import DummyNetworkAnalyzer
dna = DummyNetworkAnalyzer('dna')
station = qc.Station()
station.add_component(dna)
initialise_or_create_database_at("~/experiments_test.db")
tutorial_exp = load_or_create_experiment(
experiment_name="tutorial_exp",
sample_name="synthetic data"
)
context_meas = Measurement(exp=tutorial_exp, station=station, name='example')
ms = MultipleSweeps('ms', dna)
context_meas.register_parameter(ms.parameter_point)
context_meas.register_parameter(ms.trace_point, setpoints=(ms.parameter_point,))
ms.sweep_ranges([(100, 20000, 2), (30000, 40000, 5)])
with context_meas.run() as datasaver:
for sweep in ms.sweep_ranges_instrument():
ms.run_sweep(sweep, datasaver)
dataset = datasaver.dataset
print(ms.sweep_ranges_instrument())
plot_dataset(dataset) With this MultipleSweeps.py: from qcodes import Instrument, Parameter
import numpy as np
class MultipleSweeps(Instrument):
def __init__(self,
name,
sweep_instrument,
sweep_parameter_name='sweep_parameter',
sweep_trace_name='sweep_trace',
start_name='start',
stop_name='stop',
n_points_name='n_points', **kwargs):
super().__init__(name, **kwargs)
# Set parameters from the sweep_instrument object.
self.sweep_parameter = getattr(sweep_instrument, sweep_parameter_name)
self.sweep_trace = getattr(sweep_instrument, sweep_trace_name)
self.start = getattr(sweep_instrument, start_name)
self.stop = getattr(sweep_instrument, stop_name)
self.n_points = getattr(sweep_instrument, n_points_name)
# Create parameter_point and trace_point Parameters
self.add_parameter('parameter_point',
unit=self.sweep_parameter.unit,
get_cmd=None,
set_cmd=None)
self.add_parameter('trace_point',
unit=self.sweep_trace.unit,
get_cmd=None)
# Create the sweep_ranges Parameter
self.add_parameter('sweep_ranges',
parameter_class=Parameter,
label='Sweep Ranges',
docstring='List of tuples.'
' Each tuple contains start, stop, step',
set_cmd=self._update_sweep_ranges_instrument)
# Create the sweep_ranges_instrument Parameter
self.add_parameter('sweep_ranges_instrument',
initial_value=[],
parameter_class=Parameter,
label='Sweep Ranges Instrument',
docstring='List of tuples. Each tuple contains:'
' start, stop, n_points',
set_cmd=None,
get_cmd=self._get_sweep_ranges_instrument)
self._sweep_ranges_instrument = []
def _update_sweep_ranges_instrument(self, sweep_ranges):
self._sweep_ranges_instrument = []
# get max and min number of points from sweep_instrument
n_points_max = self.n_points.vals._max_value
n_points_min = self.n_points.vals._min_value
for (start, stop, step) in sweep_ranges:
# Check if the stop can be reached with the step size
if (stop - start) % step != 0:
stop = ((stop - start) // step + 1) * step + start
# actual number of steps to reach the desired step size
n_steps = np.ceil((stop - start) / step).astype(int) + 1
# number of sweeps we need to perform to cover all steps
n_sweeps = np.ceil(n_steps / n_points_max).astype(int)
# sweep_ranges_instrument (sweep_instrument limitations)
use_n_points_min = False
for i in range(n_sweeps):
si_start = start + i * n_points_max * step
si_stop = si_start + (n_points_max - 1) * step
if i == n_sweeps - 2: # This is the penultimate sweep
# Calculate the remaining points for the last sweep
remaining_points = n_steps - i * n_points_max
if remaining_points < (n_points_max + n_points_min):
# Shorten the penultimate sweep so that the last sweep
# has at least n_points_min points
si_n_points = remaining_points - n_points_min
si_stop = si_start + (si_n_points - 1) * step
use_n_points_min = True
else:
# Otherwise, max number of points for penultimate sweep
si_n_points = n_points_max
elif i == n_sweeps - 1: # This is the last sweep
if use_n_points_min:
si_n_points = n_points_min
else:
si_n_points = n_steps - i * n_points_max
si_stop = stop
else:
# For all other sweeps, we use the maximum number of points
si_n_points = n_points_max
self._sweep_ranges_instrument.append(
(si_start, si_stop, si_n_points))
def _get_sweep_ranges_instrument(self):
return self._sweep_ranges_instrument
def run_sweep(self, sweep_range, datasaver):
start, stop, n_points_scan = sweep_range
# Set the network analyzer parameters for the current scan range
self.start(start)
self.stop(stop)
self.n_points(n_points_scan)
# Perform the measurement and retrieve the results
sweep_param_values = self.sweep_parameter()
sweep_trace_values = self.sweep_trace()
# Add the data directly as a result
for i in range(len(sweep_param_values)):
datasaver.add_result(
(self.parameter_point.full_name, sweep_param_values[i]),
(self.trace_point.full_name, sweep_trace_values[i])
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
the instrument I'm using has the ability to perform a sweep. Unfortunately it doesn't have enough points to allow the sweep I want to perform.
Therefore I have to perform multiple sweeps back to back. I think I know how to do it inside of the intrument driver, but I think it would better be done outside of it?
Can someone point me in a direction to implement this - or is it already possible and I missed it?
Thank you,
David
Beta Was this translation helpful? Give feedback.
All reactions