Skip to content

pygen: use add_METADATA and keep parameter units - #3129

Merged
willend merged 1 commit into
mainfrom
pygen-metadata-units
Nov 18, 2026
Merged

willend merged 1 commit into
mainfrom
pygen-metadata-units

Conversation

@willend

@willend willend commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Free-form text area

Two fixes to mcstas-pygen/mcxtrace-pygen (mccode/src/pygen.c.in):

  • Component-instance METADATA was written as append_METADATA(...), which McStasScript has never had, so the generated make() stopped with an AttributeError. It is now written as add_METADATA(name=..., type=..., value=...) (McStasScript >= 0.0.93).
  • Instrument parameters with a unit (name/"unit"=default) lost it. The unit is now passed to add_parameter(..., unit='...'). Parameters without a unit are written as before.

No grammar change. ADR: docs/GRAMMAR/ADR-records/ADR_20261118_PYGEN_METADATA_UNITS.md.

Found with the ESS BIFROST model (from niess), which has METADATA blocks and parameter units: it failed the model checks of mcstas-ess-instr-citool, which run pygen.


Declaration of use of AI-tools

  • Please add a checkmark here if you used AI-tools during the work for this contribution
  • Claude Code (Claude Opus 5.5) found the problem in a trial of the BIFROST model with mcstas-ess-instr-citool, and wrote the fix, the ADR and the tests below, reviewed by the author.

Development OS / boundary conditions

macOS arm64, McStas built from this branch, McStasScript 0.0.96.

  • BIFROST (niess v0.17.1, in the citool layout): mcstas-ess-instr-citool -a runci passes with the new mcstas-pygen (model checks and two %Example tests). With the old one, the model checks fail on append_METADATA.
  • Small test instrument: lmin/"angstrom"=0.75 gives add_parameter('double', 'lmin', value=0.75, unit='angstrom', ...).
  • mcxtrace-pygen built with -Wall -Wextra, no warnings on the changed lines. Not run.
  • Not tested on Linux or Windows.

PR Checklist for contributing to McStas/McXtrace

  • My work touches the code-generator in mccode/src

    • I have added reasoning and documentation for the change through an ADR record in our GRAMMAR section
    • I am attaching test output in the comments

🤖 Generated with Claude Code

Instance METADATA was written as append_METADATA, which McStasScript
does not have; use add_METADATA(name, type, value). Pass the unit of
name/"unit"=default parameters to add_parameter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@willend
willend merged commit 78a7b87 into main Nov 18, 2026
28 checks passed
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