Skip to content

Create devices interactively #364

Description

@TeresiaOlsson

I have started to write drafts for the tutorials. In the first one I want to show the difference between creating devices interactively yourself or by loading a configuration file so the users understand the two approaches and better understand what they gain by creating the configuration file.

Problem is that I'm stuck on the correct way to create devices interactively. What I want to do at this point is just to create a single quadrupole using the simulator. This is what I thought I could do:

from pyaml.magnet.quadrupole import Quadrupole
from pyaml.lattice.simulator import Simulator

# First create the quadrupole
quad = Quadrupole(name='QF_001')

# Then create the simulator
simulator = Simulator(name="design", lattice=str(lattice_filepath))

# Attach the quadrupole to the simulator
quad.attach(simulator)

# Now you can read the strength
quad.strength.get()

It gave the error: Magnet.attach() missing 2 required positional arguments: 'strength' and 'hardware' so I change to quad.attach(simulator, strength=None, hardware=None) which instead gave me the error QF_001 is not attachedto a control system or the a simulator and I realised that this is not at all how attach works.

Instead I had to do:

from pyaml.magnet.quadrupole import Quadrupole
from pyaml.lattice.simulator import Simulator

# First create the quadrupole
quad = Quadrupole(name='QF_001')

# Then create the simulator
simulator = Simulator(name="design", lattice=str(lattice_filepath))

# Attach the quadrupole to the simulator
simulator.fill_device([quad])
quad = simulator.magnet.get("QF_001")

# Now you can read the strength
quad.strength.get()

but it still didn't work because 'NoneType' object has no attribute 'has_physics'. This I guess is a bug since it's allowed to create a magnet without a model? Or should it be mandatory to create a model?

In the end I could only get it to work by doing this:

from pyaml.magnet.identity_model import IdentityMagnetModel
from pyaml.magnet.quadrupole import Quadrupole
from pyaml.lattice.simulator import Simulator

# First create a model for the magnet
model = IdentityMagnetModel(physics='')

# Then create the quadrupole
quad = Quadrupole(name='QF_001', model=model)

# Then create the simulator
simulator = Simulator(name="design", lattice=str(lattice_filepath))

# Attach the quadrupole to the simulator
simulator.fill_device([quad])
quad = simulator.magnet.get("QF_001")

# Now you can read the strength
quad.strength.get()

What is the physics parameter and why do I need it if I'm just running the simulator? Looking at the config files it seemed to me like you only need it if using a control system? But the error messages tell me Invalid IdentityMagnetModel configuration,physics or powerconverter device required so I need to either give it or a power converter. So I just put an empty string and the simulator worked.

Is there something we can do to improve this interface before the hackathon because I think this is too complicated for the users?

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