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

Dataset support multiparameter #1249

Merged
merged 41 commits into from
Sep 4, 2018

Conversation

jenshnielsen
Copy link
Collaborator

@jenshnielsen jenshnielsen commented Aug 27, 2018

Fixes parts of #1200

  • Add support to Measurement to register and add results from multiparamters.
  • A good deal of refactoring of the logic of add_result and register_parameter to make this possible
  • Some new convenience functions for setpoint names
  • The setpoint_full_names functions etc should really have individual tests.
  • Examples of this would be good

@codecov
Copy link

codecov bot commented Aug 28, 2018

Codecov Report

Merging #1249 into master will increase coverage by 0.15%.
The diff coverage is 92.39%.

@@            Coverage Diff             @@
##           master    #1249      +/-   ##
==========================================
+ Coverage   70.49%   70.64%   +0.15%     
==========================================
  Files          74       74              
  Lines        8094     8160      +66     
==========================================
+ Hits         5706     5765      +59     
- Misses       2388     2395       +7

@@ -29,7 +30,7 @@ def empty_temp_db():
# create a temp database for testing
with tempfile.TemporaryDirectory() as tmpdirname:
qc.config["core"]["db_location"] = os.path.join(tmpdirname, 'temp.db')
qc.config["core"]["db_debug"] = True
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not have been commited

Copy link
Contributor

@astafan8 astafan8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Especially thanks for the refactoring effort.

Regarding examples - we generally want to get rid of arrayparameter and multiparameter, right? so, we should not encourage our users to use them. on the other hand removing them will take some time for use, especially removing multiparameter from all the drivers. hence, the example notebooks should include registering a multiparameter but with a note that those are to be removed or smth.

f' Values only given for {params}.')
f' Values only given for'
f' {found_parameters}.')

if inserting_unrolled_array and inserting_as_arrays:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inserting_as_arrays and inserting_unrolled_array don't seem to be changed in the code above. are they not needed at all (also, why are tests passing?:) )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inserting_as_arrays is updated in line 162 and inserting_unrolled_array is updated in line 169
I think this is correct and added a test for mixing numeric and array types that raises here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, i didn't look into the folded part so fthe code, sorry. Great!

self._unbundle_arrayparameter(parameter,
res,
found_parameters)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice! looks much cleaner now!

def _append_results(self, res: Sequence[res_type],
input_size: int) -> None:
"""
A private method to add the date to actual queue of data to be written.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: date

setpoint_axes = []
setpoint_meta = []
if setpoints is None:
raise RuntimeError(f"Got an {type(parameter)} without "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps, also add the name of the parameter to the message for clarity?


def _unbundle_setpoints_from_param(self, parameter,
sp_names, fallback_sp_name,
setpoints, found_parameters, res):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried that this method changes the given res. I do not think that it is a good pattern. Could you at least mention explicitly that this method (and so far as i see) some other methods are changing the contents of res?

self.parameters.pop(name)

self.parameters[name] = parspec
self._register_individual_parameter(name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great refactoring!

if inst_name:
return tuple(inst_name + '_' + spname for spname in
self.setpoint_names)
except AttributeError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see that this code is almost copy-pasted from full_names, nevertheless, could you make this cleaner please? are you checking for the _instrument or full_name?

assert datasaver.points_written == 15
ds = load_by_id(datasaver.run_id)

assert ds.get_data('dummy_channel_inst_ChanA_this_setpoint') == [[5],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what a crap of a function is get_data as it returns a list of single-element lists ....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed


Raises:
ValueError: if a parameter name not registered in the parent
Measurement object is encountered.
ParameterTypeError: if a parameter is given a value not matching
its type.
"""
res = list(res_tuple) # ArrayParameters cause us to mutate the results
# ArrayParameters and MultiParameters cause us to mutate
# the results.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment still relevant? you don't seem to mutate results, instead a new "list of resutls" is created now, right? also, does this change impact performance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the comment.
My preliminary benchmarks indicate that the difference is small as long as the number of tuples added is small. I therefore think this is worth the performance trade off. The alternative would involve removing paramter tuples from the list for multiparameters. That does not seem like a good idea

@@ -296,7 +398,8 @@ def __init__(
self.parameters = parameters
# here we use 5 s as a sane default, but that value should perhaps
# be read from some config file
self.write_period = write_period if write_period is not None else 5
self.write_period = float(write_period) \
if write_period is not None else 5.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this int/float business needed for write_period? also, if it is needed, just keep it in the write_period.setter only, there is no reason for other methods to care about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing logic was wrong and only worked because nothing was actually checked by mypy. You cannot use the Number ABC as a type. So I opted for making it float internally. The alternative is just make everything a union[float, int] I don't really care either which way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. now, the solution is fine, it's just that i'd rather have float(..) calls in one place.

@jenshnielsen jenshnielsen changed the title [wip] Dataset support multiparameter Dataset support multiparameter Aug 30, 2018
@jenshnielsen
Copy link
Collaborator Author

I think this addresses @astafan8 comments and now has an example and some more tests. @WilliamHPNielsen and @Dominik-Vogel any opinions.

@nataliejpg I think this should solve your Multi Parameter issue

Copy link
Contributor

@astafan8 astafan8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@astafan8 astafan8 mentioned this pull request Aug 30, 2018
11 tasks
@nataliejpg
Copy link
Contributor

solves multiparameter issue so I am a big fan and very pro merge

@@ -90,31 +103,56 @@ def add_result(self,
are not unraveled but stored directly for improved performance.

Args:
res: a dictionary with keys that are parameter names and items
that are the corresponding values at this measurement point.
res_tuple: a tuple with the first element being the parameter name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should adjust the doctring to say that one can also pass the parameter itself.

Copy link
Contributor

@Dominik-Vogel Dominik-Vogel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a very thorough and high quality PR.

@Dominik-Vogel Dominik-Vogel merged commit 8a8919b into microsoft:master Sep 4, 2018
giulioungaretti pushed a commit that referenced this pull request Sep 4, 2018
Merge: 53cbbaa 83a838d
Author: Dominik Vogel <30660470+Dominik-Vogel@users.noreply.github.com>

    Merge pull request #1249 from jenshnielsen/dataset_multiparameter
@jenshnielsen jenshnielsen deleted the dataset_multiparameter branch September 5, 2018 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants