feat: bind Info results tree and complete Config reprs (A-4)#32
Open
dhanavanthesh wants to merge 1 commit into
Open
feat: bind Info results tree and complete Config reprs (A-4)#32dhanavanthesh wants to merge 1 commit into
dhanavanthesh wants to merge 1 commit into
Conversation
Add opentrim.Info, a read-only view over the mcinfo results tree, and finish the Config introspection surface started in A-2. - info_bind.cpp: one generic mcinfo node binding exposes the whole tree - keys(), __getitem__, type, description, info_spec(), and a structural __repr__. any key added to mcinfo.cpp later appears in Python with no binding change - tally nodes return (values, sem) numpy tuples normalized per ion; all arrays are copies, never views into C++ memory - Info keeps its Driver alive (keep_alive + reference_internal) since mcinfo holds a raw mcdriver* and reads through it on every access - guards: Info before init() raises (the mcinfo constructor dereferences getSim()); a missing key raises KeyError instead of operator[] silently inserting a node - config_bind.cpp: __repr__ on the nine remaining sub-structs (CoordSys, UserTallyBins, SimulationParams, TransportParams, EnergyDistribution, SpatialDistribution, AngularDistribution, IonBeamParams, TargetParams) - bindings.cpp, CMakeLists.txt, __init__.py: register and export Info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Delivers A-4 from the GSoC2026 Feature-A Python bindings plan.
What this adds
opentrim.Infowrapping themcinforesults tree - one generic node binding, so every key in mcinfo.cpp is reachable from Python (keys(),info["..."],.type,.description,Info.info_spec())(values, sem)numpy tuples normalized per ion; arrays are copies, never views into C++ memoryInfokeeps itsDriveralive viakeep_alive+reference_internal(mcinfo holds a rawconst mcdriver*and reads through it on every access)Info(driver)beforeinit()raises (the mcinfo constructor dereferencesgetSim()); a missing key raisesKeyErrorinstead ofmcinfo::operator[]silently inserting a node__repr__prints the full key tree without evaluating getters, so it stays safe to call mid-run__repr__on the nine remaining Config sub-structs sorepr(config.Simulation)etc. read cleanly in notebooks (mcdriver.h / mccore.cpp / mcinfo.h untouched)Tested
Ubuntu 24.04, Python 3.12 - built and exercised locally: full key-tree walk, tally
(data, sem)shapes[Natoms, Nx, Ny, Nz]and totals[18, Natoms], grid/atoms/materials reads, single-element list fields stay lists, scalar strings stay str, KeyError on bad key, and the Info-before-init guard.__repr_html__and the formal pytest suite arrive in A-5.