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

Use default td.ModeSpec in mode monitors #2058

Open
wants to merge 2 commits into
base: pre/2.8
Choose a base branch
from

Conversation

yaugenst-flex
Copy link
Contributor

@yaugenst-flex yaugenst-flex commented Nov 6, 2024

How do we feel about this? 😄

@yaugenst-flex yaugenst-flex self-assigned this Nov 6, 2024
@momchil-flex momchil-flex changed the base branch from develop to pre/2.8 November 7, 2024 09:46
@momchil-flex
Copy link
Collaborator

I'm ok with this but would rather put it in 2.8. But simply changing the base makes a mess, could you try cherry-picking your commit?

@momchil-flex momchil-flex added the 2.8 will go into version 2.8.* label Nov 7, 2024
@yaugenst-flex
Copy link
Contributor Author

Sure yeah, should be fine now.

Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

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

i'm fine with it in 2.8 too. do we want to also add a mode_index: int = None and direction : str = None options? basically it would mean that we pre-select certain quantities from the data on the backend? and would make it more similar to ModeSource. If left None we just include all.

We could do this separately as well.

@@ -279,7 +279,7 @@ class AbstractModeMonitor(PlanarMonitor, FreqMonitor):
""":class:`Monitor` that records mode-related data."""

mode_spec: ModeSpec = pydantic.Field(
...,
default_factory=ModeSpec,
Copy link
Collaborator

@tylerflex tylerflex Nov 6, 2024

Choose a reason for hiding this comment

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

generally we just do ModeSpec() (no default factory). not sure if there's a substantial difference here, but i just dont know how the docs will handle default factories

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I change it or do we want to check how the docs look? Generally I would've thought that it's best to instantiate defaults (if they are classes) only on instantiation of the class, otherwise 1. you get object creation on import, which slows imports down and 2. it leads to shared state between different mode monitor instances. All new mode monitors will share the same default instance of mode_spec, and if you happen to make a change that modifies this default instance (let's say you write something into attrs), then this change will affect all other mode monitors too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i guess we could see how the docs looks, just might require some modification of this method that sets the docstring, we'd need to add handling for defaultfactory. Also cc'ing @daquinteroflex just so he knows since he's working on a sphinx plugin related to this.

Copy link
Contributor Author

@yaugenst-flex yaugenst-flex Nov 11, 2024

Choose a reason for hiding this comment

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

I took a stab at this in 1eafd9d which I think would correctly handle cases where we just use a class as a default factory. It wouldn't handle lambdas nicely, although if necessary I can also add support for that (by just printing the lambda definition).

@yaugenst-flex
Copy link
Contributor Author

do we want to also add a mode_index: int = None and direction : str = None options? basically it would mean that we pre-select certain quantities from the data on the backend? and would make it more similar to ModeSource. If left None we just include all.

i would suggest we do this separately if we decide to go for it. should probably avoid rushing that change, i'm also not so sure about it anymore...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.8 will go into version 2.8.*
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants