Skip to content

Commit c82bdbf

Browse files
committed
[Draft] TODOs for Better sim.lattice
1 parent 786a2e9 commit c82bdbf

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/ImpactX.H

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,18 @@ namespace impactx
142142
*/
143143
void ResizeMesh ();
144144

145-
/** these are elements defining the accelerator lattice */
145+
/** Elements defining the accelerator lattice (stored by value).
146+
*
147+
* Python exposes this as sim.lattice; pybind append/extend copy C++ lattice elements
148+
* into this list — not Python reference identity. See KnownElementsList in elements.cpp.
149+
*
150+
* TODO: own std::shared_ptr<SimulationLifetime> here (create in ImpactX ctor, i.e.
151+
* before init_grids()) so elements created early from Python can safely hold
152+
* std::weak_ptr to it.
153+
* TODO: track readiness on the token (e.g. amrex_ready=false until init_grids(),
154+
* then true) for clear host-vs-GPU usage errors.
155+
* TODO: invalidate/reset token in finalize() for use-after-finalize checks.
156+
*/
146157
std::list<elements::KnownElements> m_lattice;
147158

148159
/** Was init_grids already called?

src/python/elements.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,20 @@ void init_elements(py::module& m)
26642664

26652665

26662666
// all-element type list
2667+
//
2668+
// Ref semantics (Python vs this binding): a Python list keeps references to mutable
2669+
// objects, but here each append/extend materializes a C++ KnownElements value in this
2670+
// list (copy or move). The original Python handle is a separate object unless we
2671+
// intentionally bind shared ownership (e.g. std::shared_ptr element types later).
2672+
//
2673+
// TODO: register GPU-heavy element types with py::class_<T, std::shared_ptr<T>> and
2674+
// store std::shared_ptr in KnownElements (or a thin wrapper) so append/extend
2675+
// match Python mutable-object reference semantics.
2676+
// TODO: optional weak_ptr to a SimulationLifetime/session object on elements for
2677+
// clear errors on use after sim.finalize() (coordinate with pyAMReX session work).
2678+
// The shared token should be created with ImpactX construction (not init_grids),
2679+
// and expose readiness (amrex_ready) so pre-init objects can exist but reject
2680+
// GPU use until sim.init_grids() makes AMReX ready.
26672681
using KnownElementsList = std::list<KnownElements>;
26682682
py::class_<KnownElementsList> kel(me, "KnownElementsList");
26692683
kel

0 commit comments

Comments
 (0)