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

Add Bmad interface #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add Bmad interface #51

wants to merge 2 commits into from

Conversation

ChristopherMayes
Copy link
Collaborator

@ChristopherMayes ChristopherMayes commented Nov 2, 2024

This adds methods to create LUME-Genesis objects from Bmad via PyTao's Tao object

  • Lattice.from_tao
  • MainInput.from_tao to create basic input. This:
    • Sets the reference gamma0
    • Sets Beam twiss and orbit parameters
  • Genesis4.from_tao which simply calls these for convenience.

@@ -377,6 +378,11 @@ def to_file(
filename,
)

@classmethod
def from_tao(cls, tao):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs a docstring

@@ -1004,6 +1006,14 @@ def from_elements(
filename=pathlib.Path(filename) if filename else None,
)

@classmethod
def from_tao(cls, tao):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs a docstring

def from_tao(cls, tao):
elements, line_labels = genesis4_elements_and_line_from_tao(tao)

line_label = tao.branch1(1, 0)["name"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

ix_uni and ix_branch should be arguments to from_tao

pytao.Tao.branch1(
    self,
    ix_uni,
    ix_branch,
    ...
 )

@@ -0,0 +1,317 @@
from ..input._lattice import Quadrupole, Corrector, Drift, Marker, Undulator
Copy link
Collaborator

Choose a reason for hiding this comment

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

All input-related classes should come from genesis.version4.input

https://github.com/slaclab/lume-genesis/blob/edd9a89b6a15e5ad2a8c93a022cca683768511cd/genesis/version4/input/__init__.py

So
from ..input import xyz

This applies to the line below as well

"""
name = bmad_name.upper()
label = name.split("\\")[-1] # Extracts text after backslash, if any
return label.replace(".", "_").replace("#", "_")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can't be right

This would take bmad names:

X\1
X\2

and give 1 and 2

y_offset = info.get("Y_OFFSET", 0)

if key == "beginning_ele":
eles = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

This either should be [] or the annotation for the function needs updating to say returns list or None

if y_offset != 0:
raise NotImplementedError(f"y_offset not zero: {y_offset}")

# aw calc
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be nice for this to be a utility function and not baked into this large function

return eles


def genesis4_elements_and_line_from_tao(tao, match="*"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should accept ix_uni and ix_branch

Could this also have a track_start and track_end?

# shotnoise=False,
)

# TODO: Generalize
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could these just be parameters to the function for starters?


# Handle Tao universe @ branch >> sytax
if ">>" not in ele_start:
ele_start = f"{universe}@{branch}>>{ele_start}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could also be passed in as 1@ele - there are many variations for element naming in Tao

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.

2 participants