microsoft / Qcodes

Modular data acquisition framework
http://microsoft.github.io/Qcodes/
MIT License
322 stars 309 forks source link

SweepMeasurement: better design (employ the power of sweep objects) #1141

Open astafan8 opened 6 years ago

astafan8 commented 6 years ago

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 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

sweep_measurement = SweepMeasurement()
sweep_measurement.register_sweep(total_sweep_object)

with one line

sweep_measurement = SweepMeasurement(total_sweep_object)

3

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

@sohailc @WilliamHPNielsen @jenshnielsen @Dominik-Vogel

WilliamHPNielsen commented 6 years ago

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.