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

Translating MAD lattice to Ocelot #199

Open
jonasbjorklundsvensson opened this issue Oct 19, 2023 · 2 comments
Open

Translating MAD lattice to Ocelot #199

jonasbjorklundsvensson opened this issue Oct 19, 2023 · 2 comments

Comments

@jonasbjorklundsvensson
Copy link

Hi,

I need to translate a MAD lattice, presumably MAD-X, into Ocelot, but I can't get the built-in converter to work.

I'm trying to use the madx2ocelot() function, where I input the path to a lattice file (if that's what they're called in MAD) as the filename_seq parameter. I then get the error NameError: name 'lattice' is not defined from line 260 in madx.py, pasted below. It looks like the lattice that's being passed to madx_seq2ocelot_seq(), near the bottom of what I've pasted, is never defined.

def madx_seq2ocelot_seq(list_elem_pos, tot_length, exclude_elems = []):
    seq = []
    azimuth = 0.
    for i, term in enumerate(list_elem_pos):
        if term[1] in exclude_elems:
            continue
        element = term[0]
        #print element
        element.id = term[1]
        pos = term[2]
        drift = Drift(l = pos - element.l/2. - azimuth, eid = "drift_" + str(i))
        azimuth = pos + element.l/2.
        seq.append(drift)
        seq.append(element)
        #print elem[0].l, elem[1], elem[2]
    len_last_drift = tot_length - list_elem_pos[-1][-1] - list_elem_pos[-1][0].l/2.
    drift = Drift(l = len_last_drift, eid = "drift_last")
    seq.append(drift)
    return seq

def madx2ocelot(file_seq, exclude_elems):
    lines = lattice_str_from_madx(filename_seq=file_seq)
    #print lines
    file = "\n"
    exec(file.join(lines))
    seq = madx_seq2ocelot_seq(lattice, tot_length = ring.l, exclude_elems=exclude_elems)
    return seq

I guess it's a somewhat niche use case, but I really need to translate this lattice, as other methods we've tried produce a plethora of bugs, requiring lots of manual fixing, and also require the involvement of other people which is usually a bottleneck.

Best regards,
Jonas

@sergey-tomin
Copy link
Collaborator

hi,

Yes, this is indeed a niche case, and unfortunately, I doubt any of the main developers would dedicate time to translating your specific lattice to Ocelot format. The concept behind Ocelot is that users contribute to its development by creating and sharing useful functions or methods. If you develop something that could benefit other accelerator physicists, for example generalize madx2ocleot adaptor, you can submit a pull request with your contribution.

Cheers,
Sergey.

@st-walker
Copy link
Collaborator

I wrote tfs adaptor back in 2021 (which is for output from madx). Maybe it will work better for you.

To be honest, translating lattices is generally relatively simple, even if an adaptor does not exist. It is just a one to one mapping of standard components 99% of the time.

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

No branches or pull requests

3 participants