Skip to content

Use one accessor per element family with get/get_array (#531) - #535

Open
gupichon-soleil wants to merge 1 commit into
improvement/468-simplify-elementholder-api-one-accessor-per-element-family-merge-magnetmagnets-bpmbpmsfrom
531-elementholder-one-accessor-per-family
Open

gupichon-soleil wants to merge 1 commit into
improvement/468-simplify-elementholder-api-one-accessor-per-element-family-merge-magnetmagnets-bpmbpmsfrom
531-elementholder-one-accessor-per-family

Conversation

@gupichon-soleil

Copy link
Copy Markdown
Contributor

Description

Each element family now has one accessor, named in the singular, and the method decides what comes back: get(name) returns one element, get_array(name) (or attribute access) returns a configured array, get_array() returns every element of the family. The same rule applies at the root of the holder and on rf, tool and diagnostic.

sr.design.magnet.get("QF1E-C04")        # Magnet
sr.design.magnet.get_array("QForTune")  # MagnetArray
sr.design.magnet.QForTune               # same
sr.design.magnet.get_array()            # every magnet
sr.design.magnet["QF1E-C04"]            # Magnet
sr.design.magnet["QF1*"]                # typed array
sr.design.get("QF1E-C04")               # Element
sr.design.get_array("CELL08")           # any array type
sr.design.get_array()                   # every element

Related Issue

Features/issues described there are:

  • One accessor per family: GenericElementHolder and GenericArrayHolder are merged into GenericHolder (pyaml/common/holders/generic_holder.py), and each XHolder/XsHolder pair in sub_holders.py is merged into one class.
  • get / get_array / attribute / [key] on every family holder. Element names and array names stay in separate namespaces.
  • Root ElementHolder.get(name) returns one element, get_array(name=None) is public (it replaces _get_array, also used by YellowPages).
  • rf, rf.transmitter, tool and diagnostic gain get_array(), and their get requires a name.

Changes to existing functionality

This is a breaking change, no deprecated alias is kept.

  • Removed: magnets, combined_function_magnets, serialized_magnets, diagnostic.bpms, .all(), magnets.get_cfm().
  • Adding a configured array is now holder.<family>.add_array(name, element_names), adding an element stays add(element).
  • sr.design.get("ArrayName") becomes sr.design.get_array("ArrayName"), sr.design.get() becomes sr.design.get_array(). Same for tool.get() and diagnostic.get() without a name.
  • magnet keeps its scope: get, [] and get_array() see individual magnets. Serialized family names are still accepted in configured magnet arrays, and a family is obtained with serialized_magnet.get(name). serialized_magnet.get_array(name) shares the magnet arrays.
  • YellowPages overview: groups are now diagnostic.bpm, magnet, combined_function_magnet, and the printed access line uses get_array("<name>") for arrays.
  • Tuning tools, pySC_interface, examples (scripts and notebooks) and docstrings are migrated.

Testing

The following tests (compatible with pytest) were added or adapted:

  • test_get_returns_one_element_and_get_array_returns_a_configured_array
  • test_element_names_and_array_names_live_in_separate_namespaces
  • test_get_array_without_name_returns_every_element_of_the_family
  • test_serialized_magnet_holder_shares_the_magnet_arrays
  • test_get_returns_one_element_whatever_its_family (root holder)
  • test_rf_holders_get_array_return_every_plant_and_transmitter
  • get_array() and get() without a name on tool and diagnostic
  • Existing navigation tests moved from the plural accessors to the single ones

Verify that your checklist complies with the project

  • New and existing unit tests pass locally (698 passed, test_tuning_orm fails on Windows only, PermissionError on a temp file, same as on the base branch)
  • Tests were added to prove that all features/changes are effective
  • The code is commented where appropriate
  • Any existing features are not broken (unless there is an explicit change to an existing functionality): breaking API change, see above

🤖 Generated with Claude Code

Plural holders, .all() and get_cfm() are removed, get returns one element and get_array an array everywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@GamelinAl GamelinAl 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.

It looks good to me, just two minor points:

  1. serialized_magnet.add_array skips the series checks that magnet.add_array makes, but saves into the same array list.
magnet.add_array("X4", ["QF1A", "~QF1A-C05"])            -> PyAMLException: QF1A-C05 cannot be excluded, it is driven by QF1A ...
serialized_magnet.add_array("X3", ["QF1A", "~QF1A-C05"]) -> accepted without error
serialized_magnet.add_array("X1", ["QF1E-C04"])          -> "Serialized magnet QF1E-C04 not defined"

I think they should have the same behaviour.

  1. The root holder still uses fill_element_array(arrayName, elementNames), while every family now uses add_array(array_name, element_names). Maybe just rename it?

This branch has not been deployed

No deployments
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.

ElementHolder API: one accessor per element family (merge magnet/magnets, bpm/bpms, ...)

2 participants