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

chore(api): allow specifying module models to sim #15104

Merged
merged 5 commits into from
May 8, 2024

Conversation

sfoster1
Copy link
Member

@sfoster1 sfoster1 commented May 6, 2024

The simulator setup files let you specify modules, but you can only do it by specifying their types (i.e. magdeck, tempdeck) and not their modules (i.e. magneticModuleV1, temperatureModuleV2). This hasn't really mattered up til now because nothing cares, but RSQ-6 will have both desktop and ODD looking pretty hard at which generation of module is present on a flex, so we need a way to specify.

This adds a model key to the module section of the simulator setup (and sets the test-flex.json and test.json up with it) so that you can specify module models.

Also, while I was at it, improve the type checking of the init function of the threadmanager.

Closes RSQ-6

The simulator setup files let you specify modules, but you can only do
it by specifying their types (i.e. magdeck, tempdeck) and not their
modules (i.e. magneticModuleV1, temperatureModuleV2). This hasn't really
mattered up til now because nothing cares, but RSQ-6 will have both
desktop and ODD looking pretty hard at which generation of module is
present on a flex, so we need a way to specify.

This adds a model key to the module section of the simulator setup (and
sets the test-flex.json and test.json up with it) so that you can
specify module models.

Closes RSQ-6
@sfoster1 sfoster1 requested a review from TamarZanzouri May 6, 2024 20:52
@sfoster1 sfoster1 requested review from a team as code owners May 6, 2024 20:52
Copy link
Contributor

@TamarZanzouri TamarZanzouri left a comment

Choose a reason for hiding this comment

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

Overall looks good! The only thing I don't like is the list of tuples.

@@ -255,7 +257,7 @@ async def build_hardware_simulator(
attached_instruments: Optional[
Dict[top_types.Mount, Dict[str, Optional[str]]]
] = None,
attached_modules: Optional[Dict[str, List[str]]] = None,
attached_modules: Optional[Dict[str, List[Tuple[str, Optional[str]]]]] = None,
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 the proper data structure for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

well, no. i guess this is the point where the dataclasses should get persisted through.

sfoster1 added 3 commits May 7, 2024 09:50
This was getting a bit unwieldy; prior commits had made it a dict of
lists of strings, and now this needed it to be a dict of lists of tuples
of two strings, and all of this was terrible. Instead now it's a dict of
lists of a specific dataclass, much nicer.

While I was doing that I noticed that I didn't get any type errors, and
that's because ThreadManager's constructor was erasing the types of
parameters that you gave it, so I made it use a ParamSpec.
Unfortunately, you can't alter wrapped function named arguments using
type machinery right now, so I also had to change the way we specify
nonblocking thread manager construction to use a wrapper function that
sets an attr, but now that's type safe too.
@@ -255,7 +257,7 @@ async def build_hardware_simulator(
attached_instruments: Optional[
Dict[top_types.Mount, Dict[str, Optional[str]]]
] = None,
attached_modules: Optional[Dict[str, List[str]]] = None,
attached_modules: Optional[Dict[str, List[modules.SimulatingModule]]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Much better 😀

`'tempdeck'` or `'magdeck'`) representing
:param attached_modules: A map of module type names (e.g.
`'tempdeck'` or `'magdeck'`) to lists of (serial, model)
tuples representing
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not tuples anymore

@@ -114,8 +114,6 @@ def synchronizer(*args: Any, **kwargs: Any) -> Any:
def build_thread_manager() -> ThreadManager[Union[API, OT3API]]:
return ThreadManager(
API.build_hardware_controller,
use_usb_bus=ff.rear_panel_integration(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Mmm is this removal ok?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup! This was revealed by ThreadManager.__init__ actually forwarding the types. This code is building an OT2 hardware controller, it doesn't have that argument this code would have crashed (I don't think anybody uses this repl on the OT-2 or indeed the flex anymore, it was made during flex development)

@@ -38,7 +38,8 @@
]
HardwareControlAPI = Union[OT2HardwareControlAPI, OT3HardwareControlAPI]

ThreadManagedHardware = ThreadManager[HardwareControlAPI]
# this type ignore is because of https://github.com/python/mypy/issues/13437
ThreadManagedHardware = ThreadManager[HardwareControlAPI] # type: ignore[misc]
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for me why do we need this type: ignore now? Looks like the code is the same?

Copy link
Member Author

@sfoster1 sfoster1 May 7, 2024

Choose a reason for hiding this comment

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

It's this bug in mypy where if you have

  • a class that is Generic
  • and an __init__ method that takes a typevar

then you get an error when you try to bind to it.

Copy link
Contributor

@TamarZanzouri TamarZanzouri left a comment

Choose a reason for hiding this comment

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

Amazing! Looks great! A few comments but love this

@sfoster1 sfoster1 merged commit 3f430a1 into edge May 8, 2024
21 checks passed
@sfoster1 sfoster1 deleted the add-module-model-setting branch May 8, 2024 13:35
Carlos-fernandez pushed a commit that referenced this pull request May 20, 2024
The simulator setup files let you specify modules, but you can only do
it by specifying their types (i.e. magdeck, tempdeck) and not their
modules (i.e. magneticModuleV1, temperatureModuleV2). This hasn't really
mattered up til now because nothing cares, but RSQ-6 will have both
desktop and ODD looking pretty hard at which generation of module is
present on a flex, so we need a way to specify.

This adds a model key to the module section of the simulator setup (and
sets the test-flex.json and test.json up with it) so that you can
specify module models.

Also, while I was at it, improve the type checking of the init function
of the threadmanager.

Closes RSQ-6
Carlos-fernandez pushed a commit that referenced this pull request Jun 3, 2024
The simulator setup files let you specify modules, but you can only do
it by specifying their types (i.e. magdeck, tempdeck) and not their
modules (i.e. magneticModuleV1, temperatureModuleV2). This hasn't really
mattered up til now because nothing cares, but RSQ-6 will have both
desktop and ODD looking pretty hard at which generation of module is
present on a flex, so we need a way to specify.

This adds a model key to the module section of the simulator setup (and
sets the test-flex.json and test.json up with it) so that you can
specify module models.

Also, while I was at it, improve the type checking of the init function
of the threadmanager.

Closes RSQ-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants