Skip to content

Feature: Add clear and remove_device to ElementHolder #408

Open

Description

@TeresiaOlsson

Description, motivation and use case
Add a clear() and remove_device method to ElementHolder to allow to remove elements that have been added using fill_device.

Proposed solution

In one of the tutorials we currently have:

simulator._MAGNETS.pop("QF_001", None)
simulator._ALL.pop("QF_001", None)

to be able to remove a magnet that has been attached.

It would be good to have a clear() and a remove_device method to have an easier syntax to remove a specific or all elements from the ElementHolder.

Checklist

  • I've assigned this issue to a project
  • I've @-mentioned relevant people

Activity

  1. gubaidulinvadim commented on Oct 15, 2026

    @gubaidulinvadim
    Member

    I would like to close this issue. I've tried to look into the implementation and I do not like so much dynamically removing elements. This raises several issues:

    • You need to rebuilt arrays containing removed element, tuning tools using said arrays, etc.
    • Removing childs of a combined function magnet
    • You can have a reference to an element already created somewhere.
    bpm = sr.design.diagnostic.bpm['BPM_001']
    sr.remove('BPM_001')
    # What happens with bpm?
    # What happens with orbit correction using said BPM?
    # What is we are sending some command to a bpm and remove it "accidentally"
    

    I propose to close this issue as not planned. @TeresiaOlsson what do you think? Either way I personally will not be implementing this.

  2. TeresiaOlsson commented on Oct 15, 2026

    @TeresiaOlsson
    MemberAuthor

    Why is it not planned? Without this the procedure to create an Accelerator by building the Python objects directly is not nice. It fails if you try to create an Accelerator by giving it a Simulator or ControlSystem which already have Elements attached. Without any form of clear or remove element you either need to call private methods or make a new Simulator or ControlSystem object for it to work.

    The tutorials currently include an ugly workaround to make it less obvious to the users that it's not working well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions