Skip to content

feat: bind Info results tree and complete Config reprs (A-4)#32

Open
dhanavanthesh wants to merge 1 commit into
ir2-lab:GSoC2026from
dhanavanthesh:feat/A-4-info-results
Open

feat: bind Info results tree and complete Config reprs (A-4)#32
dhanavanthesh wants to merge 1 commit into
ir2-lab:GSoC2026from
dhanavanthesh:feat/A-4-info-results

Conversation

@dhanavanthesh

Copy link
Copy Markdown
Contributor

Delivers A-4 from the GSoC2026 Feature-A Python bindings plan.

What this adds

  • opentrim.Info wrapping the mcinfo results tree - one generic node binding, so every key in mcinfo.cpp is reachable from Python (keys(), info["..."], .type, .description, Info.info_spec())
  • tally nodes return (values, sem) numpy tuples normalized per ion; arrays are copies, never views into C++ memory
  • Info keeps its Driver alive via keep_alive + reference_internal (mcinfo holds a raw const mcdriver* and reads through it on every access)
  • guards: Info(driver) before init() raises (the mcinfo constructor dereferences getSim()); a missing key raises KeyError instead of mcinfo::operator[] silently inserting a node
  • structural __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 so repr(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.

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
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.

1 participant