labscript-suite-temp / labscript

The labscript Python library provides a translation from simple Python code to complex hardware instructions. The library is used to construct a "connection table" containing information about what hardware is being used and how it is interconnected. Devices described in this connection table can then have their outputs set by using a range of functions, including arbitrary ramps.
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Additional column in the connection table #9

Closed philipstarkey closed 9 years ago

philipstarkey commented 10 years ago

Original report (archived issue) by Philip Starkey (Bitbucket: pstarkey, GitHub: pstarkey).


We need an additional column in the connection table for comparing parameters/configurations of specific devices/channels. I propose we have a column for generic "other" data that is stored as the repr of a dictionary.

Current examples of where this is needed:

This could possibly be merged in with the BLACS_connection column, however for backwards compatibility I would probably suggest we add a new column in addition to the existing BLACS_connection column.

philipstarkey commented 10 years ago

Original comment by Philip Starkey (Bitbucket: pstarkey, GitHub: pstarkey).


Further thoughts,

We add some methods to the Device class of labscript which allow you to set arbitrary key/value pairs for "Device Properties" that will be stored in the connection table and compared as part of the usual connection table comparisons. This dict is put through repr and stored in a new "device_properties" column of the connection table.

Alternatively, we could just have an attribute containing a dictionary that people directly access, but I'm growing fond of explicit methods to set information like this (so that we can build in type checking, overwriting checking, etc, into those functions)

philipstarkey commented 10 years ago

Original comment by Chris Billington (Bitbucket: cbillington, GitHub: chrisjbillington).


Copying from the email thread for the record:

This seems totally fine to me, it makes sense that we want a spot to put arbitrary data that if changed should invalidate the connection table. And a generic getter and setter and the device class seems like a good way to implement it.

You could define __setitem__ and __getitem__ to make the device objects behave like a dictionary with the getting and setting of these properties, but that's a bit magical, an explicit get_property(name) and set_property(name, value) would be more obvious and non-magical as to what was going on.

philipstarkey commented 9 years ago

Original comment by Philip Starkey (Bitbucket: pstarkey, GitHub: pstarkey).


This was implemented in changeset: 2fa4b17e169adc4fa1a4e8763f25e15e507608e4

The Device class now has get_property(name, [default]) and set_property(name, value, overwrite = False) methods.

set_property is fairly self explanatory. If a property with identifier name is already set, you must explicitly specify the overwrite flag as True.

The implementation of get_property is a little more complex (to allow teh default value to be specified as None). However, the API interface is simple. If you don't specify a default value, and the property you request has not been set, an exception will be raised. If you do specify a default value, that will be returned if the property has not been set.

Properties can be accessed in BLACS through the connection table objects. These objects have a properties attribute which contains a dictionary keyed by the identifiers (name) specified in the labscript calls.

philipstarkey commented 9 years ago

Original comment by Philip Starkey (Bitbucket: pstarkey, GitHub: pstarkey).