While implementing the "sweep module", a new SweepMeasurement class has been implemented (see in PR 1107 or in qcodes/sweep/measurement.py once #1107 is merged).
The class is implemented by simply subclassing from Measurement class, and adding a register_sweep method.
Problem
The implementation is lacking design for the following reasons.
1
Thanks to the direct inheritance, register_parameter methods can be called on SweepMeasurement objects. But this is NOT desirable. The whole point of the SweepMeasurement is to get away from register_parameter, and use a sweep object for both "measurement definition" and "measurement execution". So, SweepMeasurement objects should not have register_parameter-like methods. If there is a need to add or remove parameters, that should be done through the sweep object.
2
Since SweepMeasurement make sense only for once sweep, what is the need for an explicit register_sweep method? Why not pass the sweep object directly to the constructor of the SweepMeasurement?
Compare two lines
Thanks to the sweep object infrastructure, the measurement execution code itself becomes very concise, and more importantly generic. For example:
with sweep_measurement.run() as data_saver:
for data_point in total_sweep_object:
data_saver.add_results(*data_point.items())
Why not implement a method on SweepMeasurement class that does that since SweepMeasurement objects are created based on a sweep object and they can contain it inside?
Since the run method is considered, it is also worth noting that the run method of a Measurement object does not actually "run" anything - it just initiates a data set and returns a context manager from within which measurement results can be saved (e.g. added to the data set). On the other hand, a run method of the SweepMeasurement class can indeed "run" the experiment, because the experiment definition is already known from the sweep object.
Proposed solution
Make a private base class _MeasurementBase (or _MeasurementWithDataSetBase).
Make Measurement class inherit from '_MeasurementBase, and implement only the register parameter methods in it (likeregister_parameter`).
Make SweepMeasurement class inherit from _MeasurementBase. Instead of implementing a register_sweep method, make the sweep object be an argument for its constructor.
Implement a run method of the SweepMeasurement such that it actually "run" the measurement. This might also require renaming of the run method of the Measurement class.
I fully agree. The run part has come up in discussions before, and it does seem a bit pointless to not just let the sweep do its thing with a single method.
Scope
While implementing the "sweep module", a new
SweepMeasurement
class has been implemented (see in PR 1107 or in qcodes/sweep/measurement.py once #1107 is merged).The class is implemented by simply subclassing from
Measurement
class, and adding aregister_sweep
method.Problem
The implementation is lacking design for the following reasons.
1
Thanks to the direct inheritance,
register_parameter
methods can be called onSweepMeasurement
objects. But this is NOT desirable. The whole point of theSweepMeasurement
is to get away fromregister_parameter
, and use a sweep object for both "measurement definition" and "measurement execution". So,SweepMeasurement
objects should not haveregister_parameter
-like methods. If there is a need to add or remove parameters, that should be done through the sweep object.2
Since
SweepMeasurement
make sense only for once sweep, what is the need for an explicitregister_sweep
method? Why not pass the sweep object directly to the constructor of theSweepMeasurement
? Compare two lineswith one line
3
Thanks to the sweep object infrastructure, the measurement execution code itself becomes very concise, and more importantly generic. For example:
Why not implement a method on
SweepMeasurement
class that does that sinceSweepMeasurement
objects are created based on a sweep object and they can contain it inside?Since the
run
method is considered, it is also worth noting that therun
method of aMeasurement
object does not actually "run" anything - it just initiates a data set and returns a context manager from within which measurement results can be saved (e.g. added to the data set). On the other hand, arun
method of theSweepMeasurement
class can indeed "run" the experiment, because the experiment definition is already known from the sweep object.Proposed solution
_MeasurementBase
(or_MeasurementWithDataSetBase
).Measurement
class inherit from '_MeasurementBase, and implement only the register parameter methods in it (like
register_parameter`).SweepMeasurement
class inherit from_MeasurementBase
. Instead of implementing aregister_sweep
method, make the sweep object be an argument for its constructor.run
method of theSweepMeasurement
such that it actually "run" the measurement. This might also require renaming of therun
method of theMeasurement
class.@sohailc @WilliamHPNielsen @jenshnielsen @Dominik-Vogel