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

Skip DM command discretization if dac_bit_depth is set to none #138

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

ivalaginja
Copy link
Collaborator

@ivalaginja ivalaginja commented Nov 8, 2023

Fixes #137.

@ivalaginja ivalaginja added enhancement New feature or request simulator labels Nov 8, 2023
@ivalaginja ivalaginja self-assigned this Nov 8, 2023
@ivalaginja
Copy link
Collaborator Author

ivalaginja commented Nov 9, 2023

@ehpor I don't know how to parse a none from a yml file, but this works in the current form if dac_bit_depth is simply left empty, since it turns it into a NoneType. Is that ok?

@ivalaginja
Copy link
Collaborator Author

This works in the THD2 sims as expected. @steigersg do you want to take this for a spin in HiCAT simulations before merging?

@ivalaginja ivalaginja marked this pull request as ready for review November 9, 2023 10:33
@ehpor
Copy link
Collaborator

ehpor commented Nov 9, 2023

@ivalaginja the YAML syntax for the Python None is either null or leaving it empty. So this is good.

discretized_surface = total_surface

if dac_bit_depth is not None:
voltages = np.clip(voltages, 0, 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be inside the if statement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was added in #108 which introduced the discretization, but it's true that it has nothing to do with it a priori. Should I move it out?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd take it out of the if-statement. It's unrelated. Otherwise, this looks fine to me, but we'll wait for @steigersg to give this a once-over.

@ivalaginja ivalaginja requested a review from ehpor November 9, 2023 14:23
@steigersg
Copy link
Contributor

This works in the THD2 sims as expected. @steigersg do you want to take this for a spin in HiCAT simulations before merging?

Confirmed works on HiCAT simulations. Tried both not giving anything to dac_bit_depth in the yaml and setting it to null

discretized_voltages = voltages
discretized_surface = total_surface

if dac_bit_depth is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Think this can just be shortened to

if dac_bit_depth:

but that's more stylistic - otherwise it looks good to me!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I will keep it as it is simply because in this case here it doesn't seem to make a difference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not in general. In this case, as we are expecting dac_bit_depth to be either a positive non-zero integer or None, this would work. However, for dac_bit_depth = 0, this would unexpectedly not take the if-statement. Additionally, other types will do unexpected things as well. I like being explicit in these cases.

See the second bullet point of PEP8 programming recommendations for a more official reference.

steigersg
steigersg previously approved these changes Nov 9, 2023
Copy link
Contributor

@steigersg steigersg left a comment

Choose a reason for hiding this comment

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

looks good to me!

Copy link
Collaborator

@ehpor ehpor left a comment

Choose a reason for hiding this comment

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

Actually, shouldn't this be done on the actual boston service as well? @ivalaginja Blocking this for now.

@ivalaginja
Copy link
Collaborator Author

@ehpor I thought no, since the hardware discretizes in any case? Do we want to have software-imposed discretization before the command gets sent off to hardware?

@ehpor
Copy link
Collaborator

ehpor commented Nov 9, 2023

@ivalaginja The way we have it now, is that the voltages sent to the DM are never discretized. However, the voltages that are put on the total_voltages channel are (to mimic the actual voltages that are on the DM itself, so that we can see bit-depth issues from hardware data only (as opposed to doing sims like we are doing now).

Furthermore, diverging behaviour from sim vs hardware service is unwanted in general. Furthermore, I see turning off bit depth as a kinda "default" case, when you don't know the bit depth of your DM yet. Not that that last point has any impact on this specific implementation.

@ivalaginja
Copy link
Collaborator Author

Understood, working on it.

@ivalaginja
Copy link
Collaborator Author

Which means I will need a hardware test. I can do that in a couple of hours.

@ivalaginja
Copy link
Collaborator Author

Ok I will need to defer the testing to tomorrow after all 😬

@ivalaginja
Copy link
Collaborator Author

I just tested this on hardware and the Boston service accepts an empty value ok. I also tested with values 14 and 1 which worked ok (with 1 making any sensible control impossible).

Copy link
Collaborator

@ehpor ehpor left a comment

Choose a reason for hiding this comment

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

LGTM after the hardware test (which imo would not have been necessary). Does @RemiSoummer need to look at this as well? (I'm next to him, so I might ask him regardless.)

@ivalaginja ivalaginja merged commit 56d231c into develop Nov 13, 2023
6 checks passed
@ivalaginja ivalaginja deleted the feature/no_dm_distretization branch November 13, 2023 21:39
@ivalaginja
Copy link
Collaborator Author

Def ask him. I'm glad I tested on hardware, the DMs are critical enough that I'm fine doing potentially useless tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request simulator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a no discretization option to DM commands
3 participants