Skip to content

mcrun: only take values made of numbers as scan syntax - #2722

Open
tkittel wants to merge 1 commit into
mccode-dev:mainfrom
tkittel:mcrun-literal-string-values
Open

tkittel wants to merge 1 commit into
mccode-dev:mainfrom
tkittel:mcrun-literal-string-values

Conversation

@tkittel

@tkittel tkittel commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

After iterations with @willend, me and our coding slave Claude, this now fixes yet another place where one could not easily pass through NCrystal cfg-strings.

I did review the changes - and claude wrote the rest here

mcrun took every parameter value containing : or , as scan syntax. So NCrystal cfg-strings (and e.g. Windows paths) with such characters could not be given on the command line:

mcrun Ge.instr "cfg=Ge_sg227.ncmat;dir1=@crys_hkl:5,1,1@lab:0,0,1;dir2=@crys_hkl:0,-1,1@lab:0,1,0"
CRITICAL: Parameter "cfg" uses "a:delta:b" syntax but has 5 colon-separated part(s) ...

Values with :: (stdlib::...) skipped the colon check. But they then went to the comma parsing, where a value with commas was dropped (and the instrument ran with the default).

Now only values made of numbers separated by : or , are scan syntax. Other values are used as they are. This replaces the special case for ::. With -L, values are still lists separated by commas, as before. A comma within a list entry can now be escaped as \,, which is mentioned in the -L help:

mcrun -L ... x=1,2 "cfg=Ge_sg227.ncmat;dir1=@crys_hkl:5\,1\,1@lab:0\,0\,1;...,Ge_sg227.ncmat;dir1=@crys_hkl:5\,1\,1@lab:0\,1\,0;..."

Tested by comparing with the current mcrun on 44 command lines:

  • Identical results for all of these:
    • scans: -N ranges (also negative and exponent numbers), a:delta:b, -M (also with -N2,3 and mixed syntaxes), -L with lists of file names and cfg-strings (also with ::), -L with min:delta:max, --optimize, --seeds;
    • errors and empty values: x=1:2, x=1,2,, x=.
  • Now work:
    • NCrystal cfg-strings, e.g. dir1=@crys_hkl:5,1,1...;
    • Windows paths like C:\data\a.dat, also in -L lists;
    • -L entries with \,;
    • f=a.dat,b.dat without -L, which is now that literal string instead of being dropped.
  • Changed errors:
    • x=1:a:3 is now rejected by the instrument ("Invalid value '1:a:3' for floating point parameter x") instead of by mcrun;
    • x=1::3 is the other way round;
    • -N2 f=b.dat,c.dat now gives "No interval range specified" instead of a Python exception.
  • A trailing comma in a non-numeric value (f=a.dat,) is still ignored with a warning, as before.

🤖 Generated with Claude Code

Values which are not numbers separated by ":" or "," are now used as they
are, so NCrystal cfg-strings like
"Ge_sg227.ncmat;dir1=@crys_hkl:5,1,1@lab:0,0,1" (or Windows paths like
"C:\data\a.dat") can be given on the command line. With -L, values are
still lists separated by commas, where commas within an entry can now be
escaped as "\,".

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

willend commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Cool @tkittel, indeed great (but also busy) times with these new code-slaves. 🤖 🤣

I have a slurm batch somewhere that does a multi-dimensional scan with NCrystal strings, let me run that in addition to the PR tests - will merge if that also comes back healthy.

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