Skip to content

Feature switch element - #526

Merged
gubaidulinvadim merged 7 commits into
mainfrom
feature-switch-element
Dec 2, 2026
Merged

gubaidulinvadim merged 7 commits into
mainfrom
feature-switch-element

Conversation

@gubaidulinvadim

Copy link
Copy Markdown
Member

This PR should allow to have a simple "switch" element, such as boolean flag of various feedbacks being on or off. This is useful for many measurements to set the feedbacks to OFF before the measurement and ON after the measurement.

Resolves #413. Related to #509, which requires a switch element.

def _fill_tool(self, tool: TuningTool | MeasurementTool) -> None:
self.add_tool(tool.attach(self))

def _fill_switch_element(self, element: SwitchElement) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a shame that we need to keep adding new "_fill" functions every time we need to define a new element. Maybe we could categorize this as a "tool" and use _fill_tool?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't like it so much because it does not share a type with TuningTool or MeasurementTool, and the functionality is closer to an element. But maybe typing it as TuningTool is ok. But I agree that these fill* methods need to be revised somehow.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then maybe it could use _fill_unbound_element if it is left uncategorized?

@gubaidulinvadim gubaidulinvadim Nov 26, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't like it either... It reduces the number of functions, but the lines of code are roughly the same. In fact, I don't like this unbound element so much.

Comment thread pyaml/lattice/abstract_impl.py Resolved
@gubaidulinvadim
gubaidulinvadim marked this pull request as ready for review November 26, 2026 15:52
Comment thread pyaml/common/switch_element.py Resolved
Comment thread pyaml/control/abstract_impl.py Resolved
Comment thread pyaml/control/controlsystem.py Resolved
…olean channel in control system (simulator only).
@gubaidulinvadim

Copy link
Copy Markdown
Member Author

@kparasch Do you mind merging with ugly _fill_switch_element()?

return self.enabled.get()

def _fill_device(self, holder: "ElementHolder") -> None:
holder._fill_switch_element(self)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about an if statement here that does the _fill_switch_element itself based on the type of the element holder?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's what would've needed to be done in _fill_unbound_element. I don't see much difference between another def() and another if(). Same number of lines of code. But it could be done.

@kparasch kparasch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't mind merging now, but I think this is the perfect PR to experiment with trying to do the _fill_device better, as this element is quite simple and contained. If you disagree though, we can merge without any hard feelings.

@gubaidulinvadim

Copy link
Copy Markdown
Member Author

@kparasch We can make an issue about fill*. I need this PR to continue working on IDs.

@gubaidulinvadim
gubaidulinvadim merged commit 40beddb into main Dec 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: simple enable/disable elements

3 participants