Skip to content

Don't refuse files without a version in simulation/program; Read() takes mcstas_version - #50

Draft
willend wants to merge 1 commit into
mainfrom
version-fallback
Draft

willend wants to merge 1 commit into
mainfrom
version-fallback

Conversation

@willend

@willend willend commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

_read_mcstas_version raised when entry1/simulation/program contained no X.Y.Z. mccode-antlr up to 0.36 writes just "McStas" there (fixed in mccode-dev/mccode-antlr#404), so its NeXus output couldn't be loaded at all:

ValueError: Could not find version in file, found 'McStas'. Hardcode the version as an argument to the class.

The error advised hardcoding the version as an argument, but Read() didn't accept one.

Changes

  • No version found: warn and assume the newest file layout in the settings registry, which current McStas and mccode-antlr write, instead of raising.
  • Read(..., mcstas_version=(major, minor, patch)): passed through to McStasNeXus, which already supported it, to override the version from the file.

The fallback is the judgement call here. It's right for anything written recently, but it would misread a genuinely old file that also lacks a version string; the warning says what was assumed and how to override it. If strictness is preferred, the Read(..., mcstas_version=...) part alone still helps.

Testing

  • New tests/version_test.py: version parsing for McStas, development-build (" 3.99.99, git") and mccode-antlr ("McStas 3.10.0 (mccode-antlr 0.36.0)") strings; the no-version fallback warns; Read() passes mcstas_version through. The two new behaviours fail without this change.
  • On a real mccode-antlr 0.36 NeXus scan (templateSANS_Mantid), export_scipp now loads 130,277 events with the warning, where it previously raised.

🤖 Generated with Claude Code

…kes mcstas_version

_read_mcstas_version raised when entry1/simulation/program held no
X.Y.Z. mccode-antlr up to 0.36 writes just "McStas" there, so its NeXus
output could not be loaded; the error advised passing the version, but
Read() did not accept it.

- No version found: warn and assume the newest file layout in the
  settings registry (as written by current McStas and mccode-antlr)
- Read(..., mcstas_version=(major, minor, patch)) is passed through to
  McStasNeXus, which already supported it

New tests/version_test.py covers McStas, development-build and
mccode-antlr version strings, the fallback warning and the passthrough.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@willend

willend commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Note: this overlaps with #49 (entry= argument).

Both change the Data.__init__ signature in LoadFile.py and the McStasNeXus(...) call in it:

Whichever merges second gets a small conflict there. The resolution keeps both:

def __init__(self, data_folder, filename="mccode.h5", entry="entry1", mcstas_version=None):
    ...
    self.file_object = McStasNeXus(self.file, entry=entry, mcstas_version=mcstas_version)

Also, _read_mcstas_version reads f["entry1"] on main, and #49 changes that to f[self.entry]. The fallback added here sits after that lookup, so it applies unchanged with either version.

@mads-bertelsen

Copy link
Copy Markdown
Contributor

That's a great catch, thanks! Sensible fallback to use the newest

This branch has not been deployed

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

2 participants