-
Notifications
You must be signed in to change notification settings - Fork 64
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
Update displayed device specs #763
base: develop
Are you sure you want to change the base?
Conversation
In this way, _specs and print_specs can also be called for virtual devices.
I don't understand how to make the |
mypy continues to fail, but in a file I did not modify. Should I try to fix it nonetheless? |
Yeah, I saw this pop-up too in another PR. Please just copy this line and it goes away:
|
Concerning the test coverage, which is now needed for |
I'm afraid I don't see a way around it, no. I would maybe use a string with some format fields so that you can change some parameters (using @pytest.mark.parametrize) and check that the string always matches what you expect. |
I have added a test for three devices. At the end, I did not use |
To give an example of what has been implemented in the PR, here is the output of
and after:
Also, we can invoke this method for
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this @HaroldErbin , very nice work! I have some questions and suggestions, I'd be happy to hear your thoughts.
One change is to use a string instead of joining elements of a list to get the final string. The reason is that lists were cumbersome to use when there were conditional statements.
I have updated the codes with your suggestions, leaving only two conversations open for further discussions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes! Can you please share a print of how this is looking right now?
Create one _specs method for each sections (register, layout, device, channels). The layout section is defined only in Device, such that it is not displayed for VirtualDevice. This commit also goes back to using lists for storing the lines.
I have implemented the changes suggested by @HGSilveri:
Here are the results:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nice work @HaroldErbin , thanks a lot! I have a final proposition for the return types of these new methods that I think can make them slightly more flexible. Consider all the comments below together, they are related
" - Maximum sequence duration: " | ||
f"{self.max_sequence_duration} ns" | ||
) | ||
return "\n".join(line for line in register_lines if line != "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we return list[str]
instead? This (and the other similar methods) could change to
return "\n".join(line for line in register_lines if line != "") | |
return [line for line in register_lines if line != ""] |
return "\n".join( | ||
[ | ||
self._register_lines(), | ||
self._device_lines(), | ||
self._channel_lines(for_docs=for_docs), | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would then become
return "\n".join( | |
[ | |
self._register_lines(), | |
self._device_lines(), | |
self._channel_lines(for_docs=for_docs), | |
] | |
) | |
return "\n".join( | |
self._register_lines() | |
+ self._device_lines() | |
+ self._channel_lines(for_docs=for_docs) | |
) |
def _layout_lines(self) -> str: | ||
|
||
layout_lines = [ | ||
"\nLayout parameters:", | ||
f" - Requires layout: {self._param_yes_no(self.requires_layout)}", | ||
" - Accepts new layout: " | ||
+ self._param_yes_no(self.accepts_new_layouts), | ||
f" - Minimal number of traps: {self.min_layout_traps}", | ||
self._param_check_none(self.max_layout_traps)( | ||
" - Maximal number of traps: {}" | ||
), | ||
f" - Maximum layout filling fraction: {self.max_layout_filling}", | ||
] | ||
|
||
return "\n".join(line for line in layout_lines if line != "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had something slightly different in mind for the layout parameters. I think the ones that are in VirtualDevice
should also appear in its specs, so this method could be moved to BaseDevice
expect for the accepts_new_layout
line. That one, we could add it like this:
def _layout_lines(self) -> str: | |
layout_lines = [ | |
"\nLayout parameters:", | |
f" - Requires layout: {self._param_yes_no(self.requires_layout)}", | |
" - Accepts new layout: " | |
+ self._param_yes_no(self.accepts_new_layouts), | |
f" - Minimal number of traps: {self.min_layout_traps}", | |
self._param_check_none(self.max_layout_traps)( | |
" - Maximal number of traps: {}" | |
), | |
f" - Maximum layout filling fraction: {self.max_layout_filling}", | |
] | |
return "\n".join(line for line in layout_lines if line != "") | |
def _layout_lines(self) -> list[str]: | |
layout_lines = super()._layout_lines() | |
layout_lines.insert(2, f" - Accepts new layout: {self._param_yes_no(self.accepts_new_layouts)}" | |
return layout_lines |
def _specs(self, for_docs: bool = False) -> str: | ||
|
||
return "\n".join( | ||
[ | ||
self._register_lines(), | ||
self._layout_lines(), | ||
self._device_lines(), | ||
self._channel_lines(for_docs=for_docs), | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (or rather its new version) would then be in BaseDevice
and we don't need to redefine it here
Add more information to
_specs()
and move the method toBaseDevice
.A public property
specs
has been added.See issue #756.