Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/params #403

Merged
merged 18 commits into from
Jan 19, 2017
Merged
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
453 changes: 453 additions & 0 deletions docs/examples/Creating Instrument Drivers.ipynb

Large diffs are not rendered by default.

554 changes: 554 additions & 0 deletions docs/examples/Parameters.ipynb

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion qcodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@
from qcodes.instrument.mock import MockInstrument, MockModel

from qcodes.instrument.function import Function
from qcodes.instrument.parameter import Parameter, StandardParameter, combine, CombinedParameter
from qcodes.instrument.parameter import (
Parameter,
ArrayParameter,
MultiParameter,
StandardParameter,
ManualParameter,
combine,
CombinedParameter)
from qcodes.instrument.sweep_values import SweepFixedValues, SweepValues

from qcodes.utils import validators
Expand Down
25 changes: 18 additions & 7 deletions qcodes/data/data_array.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import collections

from qcodes.utils.helpers import DelegateAttributes, full_class
from qcodes.utils.helpers import DelegateAttributes, full_class, warn_units


class DataArray(DelegateAttributes):
Expand Down Expand Up @@ -29,7 +29,7 @@ class DataArray(DelegateAttributes):
Args:
parameter (Optional[Parameter]): The parameter whose values will
populate this array, if any. Will copy ``name``, ``full_name``,
``label``, ``units``, and ``snapshot`` from here unless you
``label``, ``unit``, and ``snapshot`` from here unless you
provide them explicitly.

name (Optional[str]): The short name of this array.
Expand Down Expand Up @@ -68,7 +68,9 @@ class DataArray(DelegateAttributes):
handle converting this to array_id internally (maybe it
already does?)

units (Optional[str]): The units of the values stored in this array.
unit (Optional[str]): The unit of the values stored in this array.

units (Optional[str]): DEPRECATED, redirects to ``unit``.

is_setpoint (bool): True if this is a setpoint array, False if it
is measured. Default False.
Expand All @@ -84,7 +86,7 @@ class DataArray(DelegateAttributes):
'array_id',
'name',
'shape',
'units',
'unit',
'label',
'action_indices',
'is_setpoint')
Expand All @@ -94,7 +96,7 @@ class DataArray(DelegateAttributes):
COPY_ATTRS_FROM_INPUT = (
'name',
'label',
'units')
'unit')

# keys in the parameter snapshot to omit from our snapshot
SNAP_OMIT_KEYS = (
Expand All @@ -108,13 +110,17 @@ class DataArray(DelegateAttributes):

def __init__(self, parameter=None, name=None, full_name=None, label=None,
snapshot=None, array_id=None, set_arrays=(), shape=None,
action_indices=(), units=None, is_setpoint=False,
action_indices=(), unit=None, units=None, is_setpoint=False,
preset_data=None):
self.name = name
self.full_name = full_name or name
self.label = label
self.shape = shape
self.units = units
if units is not None:
warn_units('DataArray', self)
if unit is None:
unit = units
self.unit = unit
self.array_id = array_id
self.is_setpoint = is_setpoint
self.action_indices = action_indices
Expand Down Expand Up @@ -518,3 +524,8 @@ def fraction_complete(self):
last_index = max(last_index, self.synced_index)

return (last_index + 1) / self.ndarray.size

@property
def units(self):
warn_units('DataArray', self)
return self.unit
17 changes: 16 additions & 1 deletion qcodes/data/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def __init__(self, location=None, mode=DataMode.LOCAL, arrays=None,

self.metadata = {}

self.arrays = {}
self.arrays = _PrettyPrintDict()
if arrays:
self.action_id_map = self._clean_array_ids(arrays)
for array in arrays:
Expand Down Expand Up @@ -864,3 +864,18 @@ def __repr__(self):
out += out_template.format(info=arr_info_i, lens=column_lengths)

return out


class _PrettyPrintDict(dict):
"""
simple wrapper for a dict to repr its items on separate lines
with a bit of indentation
"""
def __repr__(self):
body = '\n '.join([repr(k) + ': ' + self._indent(repr(v))
for k, v in self.items()])
return '{\n ' + body + '\n}'

def _indent(self, s):
lines = s.split('\n')
return '\n '.join(lines)
30 changes: 14 additions & 16 deletions qcodes/data/hdf5_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ def read(self, data_set, location=None):
# write ensures these attributes always exist
name = dat_arr.attrs['name'].decode()
label = dat_arr.attrs['label'].decode()
units = dat_arr.attrs['units'].decode()

# get unit from units if no unit field, for backward compatibility
if 'unit' in dat_arr.attrs:
unit = dat_arr.attrs['unit'].decode()
else:
unit = dat_arr.attrs['units'].decode()

is_setpoint = str_to_bool(dat_arr.attrs['is_setpoint'].decode())
# if not is_setpoint:
set_arrays = dat_arr.attrs['set_arrays']
Expand All @@ -75,15 +81,15 @@ def read(self, data_set, location=None):
if array_id not in data_set.arrays.keys(): # create new array
d_array = DataArray(
name=name, array_id=array_id, label=label, parameter=None,
units=units,
unit=unit,
is_setpoint=is_setpoint, set_arrays=(),
preset_data=vals)
data_set.add_array(d_array)
else: # update existing array with extracted values
d_array = data_set.arrays[array_id]
d_array.name = name
d_array.label = label
d_array.units = units
d_array.unit = unit
d_array.is_setpoint = is_setpoint
d_array.ndarray = vals
d_array.shape = dat_arr.attrs['shape']
Expand Down Expand Up @@ -196,34 +202,26 @@ def _create_dataarray_dset(self, array, group):
group: group in the hdf5 file where the dset will be created

creates a hdf5 datasaset that represents the data array.

note that the attribute "units" is used for shape determination
in the case of tuple-like variables.
'''
# Check for empty meta attributes, use array_id if name and/or label
# is not specified
if array.label is not None:
label = array.label
else:
label = array.array_id

if array.name is not None:
name = array.name
else:
name = array.array_id
if array.units is None:
array.units = [''] # used for shape determination
units = array.units

# Create the hdf5 dataset
if isinstance(units, str):
n_cols = 1
else:
n_cols = len(array.units)
dset = group.create_dataset(
array.array_id, (0, n_cols),
maxshape=(None, n_cols))
array.array_id, (0, 1),
maxshape=(None, 1))
dset.attrs['label'] = _encode_to_utf8(str(label))
dset.attrs['name'] = _encode_to_utf8(str(name))
dset.attrs['units'] = _encode_to_utf8(str(units))
dset.attrs['unit'] = _encode_to_utf8(str(array.unit or ''))
dset.attrs['is_setpoint'] = _encode_to_utf8(str(array.is_setpoint))

set_arrays = []
Expand Down
15 changes: 7 additions & 8 deletions qcodes/instrument/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime

from .base import Instrument
from .parameter import Parameter
from .parameter import MultiParameter
from qcodes import Loop
from qcodes.data.data_array import DataArray
from qcodes.process.server import ServerManager, BaseServer
Expand Down Expand Up @@ -283,22 +283,21 @@ def _delattr(self, attr):
"""
self.ask('method_call', 'delattr', attr)

class ArrayGetter(Parameter):
class ArrayGetter(MultiParameter):
"""
Example parameter that just returns a single array

TODO: in theory you can make this same Parameter with
TODO: in theory you can make this an ArrayParameter with
name, label & shape (instead of names, labels & shapes) and altered
setpoints (not wrapped in an extra tuple) and this mostly works,
but when run in a loop it doesn't propagate setpoints to the
DataSet. We could track down this bug, but perhaps a better solution
would be to only support the simplest and the most complex Parameter
forms (ie cases 1 and 5 in the Parameter docstring) and do away with
the intermediate forms that make everything more confusing.
DataSet. This is a bug
"""
def __init__(self, measured_param, sweep_values, delay):
name = measured_param.name
super().__init__(names=(name,))
super().__init__(names=(name,),
shapes=((len(sweep_values),),),
name=name)
self._instrument = getattr(measured_param, '_instrument', None)
self.measured_param = measured_param
self.sweep_values = sweep_values
Expand Down
Loading