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

Ref._to_buffer does not cascade the moving of elements #126

Open
freddieknets opened this issue Feb 2, 2024 · 0 comments
Open

Ref._to_buffer does not cascade the moving of elements #126

freddieknets opened this issue Feb 2, 2024 · 0 comments

Comments

@freddieknets
Copy link
Contributor

When moving a Ref (that itself points to an array of Refs) to another buffer, the original elements are not copied to that buffer.

I don't know if that is intentional, but as it is now I do not have a way to move the original elements to the new buffer.

This is blocking the development of xboinc.

MWE:

import xobjects as xo
import xtrack as xt

class ElementRefClass(xo.UnionRef):
    _reftypes = [xt.Drift._XoStruct, xt.Multipole._XoStruct]

class ElementRefData(xo.Struct):
    elements = ElementRefClass[:]

class MyStruct(xo.Struct):
    refdata = xo.Ref(ElementRefData)

thisref = ElementRefData(elements=[xt.Drift(length=1.7)._xobject, xt.Multipole(knl=[0,1.2])._xobject])

newstruct = MyStruct()
newstruct.refdata = thisref

newstruct.refdata.elements[0]
newstruct.refdata.elements[1]

will throw an error. What happens is that the MyStruct is created on a different buffer, and when assigning the field newstruct.refdata = thisref the ElementRefData is moved to the new buffer, but the Drift and Multipole elements themselves are not moved (this, or they are moved but their offsets are not correctly updated - I don't know which is the underlying issue).

I know this can be avoided by creating the ElementRefData in the same buffer as the MyStruct, but this cannot be done in my use case, because in practice the creation of ElementRefData is rather wastefull and creates a buffer that is several times larger than needed (which is an issue for xboinc).

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

1 participant