CLI Reference¶
mccode-antlr installs eight command-line programs.
Instrument translation¶
Translate a McCode .instr file to C source code.
| Flag | Default | Description |
|---|---|---|
INSTR_FILE |
(required) | .instr file to translate |
-o FILE, --output-file FILE |
<stem>.c |
Output C file |
-I DIR, --search-dir DIR |
— | Extra component search directory (repeatable) |
-t / --trace / --no-trace |
off | Enable trace mode for instrument display |
-p / --portable / --no-portable |
off | Generate portable output for cross-platform compatibility |
--source / --no-source |
off | Embed the instrument source code in the generated C |
--main / --no-main |
on | Emit a main() entry point (--no-main for external embedding) |
--runtime / --no-runtime |
on | Embed McCode run-time libraries in the generated C |
--verbose / --no-verbose |
off | Verbose output during translation |
-g, --debug / --no-debug |
off | Emit debugging information in the generated C: #line directives and absolute source paths in SIG_MESSAGE. Without it, source locations are named relative to the registry that supplied them, so the output does not depend on this machine |
-L / --line-directives / --no-line-directives |
— | Deprecated alias for -g/--debug |
--trust-local-registries / --no-trust-local-registries |
off | Trust local registries restored from a serialized (.json) instrument |
-v, --version |
— | Print the McCode version and exit |
Run commands¶
Compile and run an instrument simulation.
| Flag | Description |
|---|---|
INSTR_FILE |
.instr file to compile and run |
PARAM=VALUE(S) |
Instrument parameters — see Parameter syntax below |
-o FILE, --output-file FILE |
Output path for the compiled binary |
-d DIR, --directory DIR |
Output directory for simulation results (must not already exist) |
-I DIR, --search-dir DIR |
Extra component search directory (repeatable) |
-n N, --ncount N |
Number of rays to simulate |
-s N, --seed N |
Random number generator seed |
-t / --trace / --no-trace |
Trace particles through the instrument — compiles in trace support and enables it at runtime (default: off) |
--source / --no-source |
Embed the instrument source code in the binary |
--verbose / --no-verbose |
Verbose compiler and linker output |
--capture {no,yes,tee,tui} |
Where the simulation's own output goes (default: no, i.e. straight to your terminal) |
-g, --gravitation |
Enable gravitation for all trajectories |
-m, --mesh |
Treat multiple scanned parameters as a multidimensional grid scan |
--bufsiz N |
Monitor_nD list/buffer size |
--format FORMAT |
Output data format |
--dryrun |
Print scan commands without running any simulations |
--parallel / --no-parallel |
Use MPI multi-process parallelism. Unspecified: taken from the binary |
--gpu / --no-gpu |
Use GPU OpenACC parallelism. Unspecified: taken from the binary |
--mpi NB_CPU |
Number of MPI processes, or auto to let the launcher decide (default: auto). --process-count is an alias |
--build-info |
Print what a compiled binary was built from and with, then exit |
--copyright |
Print the McCode copyright statement and exit |
-v, --version |
Print the McCode version and exit |
Seeing the simulation's output¶
A running simulation writes its progress, detector summaries and any component
warnings to its own stdout. --capture decides where that goes:
| value | behaviour |
|---|---|
no (default) |
straight through to your terminal, as it is produced |
yes |
held back, and shown only if the run fails |
tee |
both: streamed, and saved as <output directory>/mccode.out |
tui |
saved as tee does, but summarised live instead of echoed |
tee writes one log per scan point, beside that point's mccode.sim. It is the
one to reach for under MPI, where the ranks' output interleaves on screen and is
easier to read afterwards than live.
--capture=no also keeps memory flat: yes and the old behaviour hold the whole
run's output in RAM until it finishes.
--capture=tui¶
tui pins a small live summary to the terminal — how many scan points are done,
how far the current one has got, its parameter values, the most recent detector
result, and any errors — and erases it when the scan ends, leaving you looking at
your own last command instead of at thousands of lines of output. The output
itself is not discarded; it is written per point exactly as tee writes it.
The per-point percentage comes from the Progress_bar component, which prints it
only when the instrument has one, and only every percent of the way (10 by
default, and coarser still for small -n). Without it the point bar stays
indeterminate rather than inventing progress; add Progress_bar(percent=1) to
the instrument for a smoother one.
tui falls back to tee wherever a live display would be useless or in the way:
a pipe, a CI log, a terminal that cannot handle it, or --dryrun. Since the log
is written either way, nothing is lost in the fallback.
Tracing¶
-t/--trace is off by default. It is a debugging aid: the binary reports every
particle's state at every component, which for a real instrument is kilobytes of
output per particle. Under MPI every rank's share of that is funnelled through the
launcher and captured by mcrun-antlr, which on a chopper instrument at
-n 3e5 costs around 90x the untraced runtime.
Because the flag also controls whether trace support is compiled in, switching it on for an instrument that was already built without it recompiles the binary.
Choosing a parallelism target¶
When mcrun-antlr is given an already-compiled binary, --parallel and --gpu
are three-valued. Left out, the binary's own build information decides — so
running an MPI binary launches it under mpirun without being told to. Given
explicitly, they are never silently overridden:
--parallelon a binary built without MPI is an error, rather than anmpiruninvocation that would start N independent full-ncountruns racing on one output directory.--no-parallelon an MPI binary warns and runs it as a single process.
When the binary carries no build information and none can be inferred, the flag as given is used.
--mpi decides how many processes to ask for. The default, auto, names no
number at all: mpirun — or the batch scheduler that started it — chooses, which
is what you want inside a job allocation. On Windows, where mpiexec has no
sensible default, auto resolves to the CPU count. Give an integer to pin it.
Parameter syntax¶
Each instrument parameter is given as PARAM=VALUE(S) after the filename.
The value determines whether this parameter is held constant or scanned:
| Syntax | Type | Example | Meaning |
|---|---|---|---|
PARAM=value |
Scalar | E_i=5.0 |
Single value; constant across all scan steps |
PARAM=start:stop |
Range (step=1) | angle=10:20 |
11 steps from 10 to 20 inclusive |
PARAM=start:step:stop |
Range (explicit step) | angle=10:2:20 |
6 steps: 10, 12, 14, 16, 18, 20 |
PARAM=v1,v2,v3,... |
Explicit list | E_i=1.0,2.5,5.0 |
Exactly those values, in order |
1-D scan (default): all ranged parameters must have the same number of points and are stepped together in lock-step. Scalar parameters keep their fixed value at every step.
N-D mesh scan (-m / --mesh): all ranged parameters are combined as a full Cartesian product. A scan with lengths [P, Q, R] runs P × Q × R simulations.
Compile-only commands¶
Compile a McCode instrument to a binary without running it.
Accepts .instr, .json, or pre-generated .c files.
| Flag | Default | Description |
|---|---|---|
FILENAME |
(required) | .instr / .json / .c file to compile |
-o OUTPUT, --output OUTPUT |
CWD | Output path for the compiled binary (file or directory) |
-I DIR, --search-dir DIR |
— | Extra component search directory (may be given more than once) |
-t / --trace / --no-trace |
on | Enable trace mode for instrument display |
--source / --no-source |
off | Embed the instrument source in the executable |
--verbose / --no-verbose |
off | Verbose compiler/linker output |
--parallel |
off | Use MPI multi-process parallelism; names the binary <instr>.mpi.out |
--gpu |
off | Use GPU OpenACC parallelism; names the binary <instr>.acc.out |
--nexus |
off | Enable NeXus output support (not part of the binary name) |
-c, --dump-source |
off | Keep the generated C source file alongside the binary |
-v, --version |
— | Print version and exit |
Format command¶
mcfmt¶
Format .instr and .comp McCode DSL source files in canonical style.
| Flag | Description |
|---|---|
FILE … |
One or more .instr or .comp files to format |
-i, --inplace |
Modify files in place instead of printing to stdout |
--check |
Exit non-zero if any file would be reformatted; writes nothing (useful as a CI gate) |
--diff |
Show a unified diff of proposed changes instead of formatted output |
--clang-format |
Also format C-code blocks (%{ … %}) using clang-format with the official McCode style (fetched via pooch) |
--clang-format-config PATH |
Format C-code blocks using clang-format with a given .clang-format config file |
--clang-format-style STYLE |
Format C-code blocks using clang-format with a named style (e.g. "LLVM", "Google", or an inline "{BasedOnStyle: …}" map) |
The output mode flags (-i, --check, --diff) are mutually exclusive; the default (none given) prints formatted output to stdout.
Management command¶
mccode-antlr¶
Top-level management utility for caches, configuration, and data files.
| Subcommand | Description |
|---|---|
cache |
Manage the component file cache |
config |
Manage the mccode-antlr configuration |
datafile |
Work with McCode data files (Bragg tables, SQW files, …) |
convert |
Convert instrument descriptions between .instr, .json, and Python assembler scripts |
extract |
Reconstitute a portable instrument (.instr or .json) into a directory |
mccode-antlr cache¶
| Sub-subcommand | Description |
|---|---|
list [name] |
List named caches or the versions of one cache (-l for long format) |
remove [name] [version] |
Remove a named cache or specific version (-f to skip confirmation) |
populate |
Bulk-populate pooch caches from a McCode git tag or local checkout |
register |
Mint a pooch registry file (path + sha256 hash per line) from a local directory tree |
ir-list |
List component IR cache files (*.comp.<build>.json) (-l for paths, sizes, stale status) |
ir-clean |
Delete component IR cache files (--stale for stale-only; -f to skip confirmation) |
build |
Pre-build the C typedef cache, and component IR cache files when enabled, for all known registries |
ir-build |
Deprecated spelling of build |
cache populate options:
| Flag | Description |
|---|---|
--tag TAG |
McCode version tag (e.g. v3.5.31); defaults to the configured version |
--from-path PATH |
Use an existing local McCode checkout instead of cloning |
--clone-url URL |
Git URL to clone (used when --from-path is not given) |
--flavor {mcstas,mcxtrace,both} |
Which flavor's registries to populate (default: both) |
--strict / --no-strict |
Treat a missing registry file as a fatal ERROR that exits non-zero (default). --no-strict reports it as a WARNING and exits 0 instead |
--check-hashes / --no-check-hashes |
Verify each copied file's sha256 hash against the registry (default: follows --strict/--no-strict — on when strict, off when lenient). A mismatch is reported the same way as a missing file |
--registry-dir DIR |
Directory of locally-minted <name>-registry.txt manifests (e.g. from cache register) to use instead of fetching from the configured registry source; seeds the cache so later cache populate/translation calls at the same tag also use them offline |
cache register options:
| Flag | Description |
|---|---|
ROOT |
Root path; registry entries are recorded relative to this |
DIR ... |
One or more directories under ROOT to walk (repeatable positional) |
--out FILE, -o FILE |
Registry output file path (default: pooch-registry.txt) |
--ext SUFFIX |
Only include files whose name ends with this suffix (repeatable); default includes every file |
--recursive / --no-recursive |
Recurse into subdirectories of each DIR (default) |
cache build options:
cache build parses only files already on disk; run cache populate first. It always warms the C typedef cache. It writes component IR sidecars (*.comp.<build>.json) only when the cache.component_ir configuration value is true, e.g. MCCODEANTLR_CACHE__COMPONENT_IR=true. They are off by default; turn them on for a prebuilt, shared or read-only cache.
| Flag | Description |
|---|---|
--tag TAG |
McCode version whose cached components to build (default: the configured version) |
--flavor {mcstas,mcxtrace,both,none} |
Which flavor's registries to build (default: both); none builds only --registry ones |
-j N, --jobs N |
Number of parallel workers (default: os.cpu_count()) |
--force |
Rebuild even if the IR sidecar is already up-to-date |
-R SPEC, --registry SPEC |
Extra registry to include (repeatable); same SPEC formats as registry_from_specification |
mccode-antlr config¶
| Sub-subcommand | Description |
|---|---|
list [regex] |
Print configuration values to stdout, optionally filtered by a regex on the key |
get [key] |
Retrieve one value by .-separated key (default: full config) |
set key value [path] |
Update or insert one configuration value |
unset key [path] |
Remove one configuration value |
save [path] |
Create or update the configuration file on disk |
mccode-antlr datafile¶
| Sub-subcommand | Description |
|---|---|
list |
List available data files for a flavor |
fetch |
Download a data file into the local Pooch cache (no copy to working directory) |
get |
Download a data file and copy it to a directory |
Run mccode-antlr SUBCOMMAND ACTION -h for the full option list of any individual action.
mccode-antlr convert¶
Convert between serialized instrument formats and generated Python assembler scripts.
mccode-antlr convert INPUT [-o OUTPUT] [--to {python,json,instr}] [--flavor {mcstas,mcxtrace}] [-I DIR ...]
| Flag | Description |
|---|---|
INPUT |
Input file (.instr or .json) |
-o, --output |
Output file path (if omitted, inferred from target/input) |
--to |
Target format (python, json, or instr) |
--flavor |
Flavor used when reading .instr input (mcstas default) |
-I, --search-dir |
Extra component search directory when reading .instr |
--optimize |
Enable conservative loop-compaction for repeated component sequences (only with --to python) |
--trust-local-registries |
Trust local registries restored from a serialized (.json) instrument |
mccode-antlr extract¶
Reconstitute a portable instrument into a directory: the .instr file (and any %include-d instruments, per the include hierarchy), every stashed/embedded local file, and the component (.comp) definitions it needs. Everything is written flat into one directory — no subfolders — so the result can be translated or compiled from inside that directory with no -I/--search-dir needed.
By default, only component definitions and dependency files not otherwise available from a remote registry are written (a component shipped with mcstas/mcxtrace, for example, is skipped since it's already fetchable by name elsewhere). Pass --include-remote for a fully self-contained bundle that also reconstructs those.
unzip-like selection is also available: pass one or more MEMBER glob patterns to extract only matching files (naming a remote-sourced file this way extracts it even without --include-remote, since asking for it by name is unambiguous), -x/--exclude to omit matches from whatever set would otherwise be written, and -l/--list to preview — without writing anything — exactly what a given invocation (same MEMBER/-x/--include-remote) would produce.
mccode-antlr extract INPUT [MEMBER ...] [-o OUTPUT_DIR] [--flavor {mcstas,mcxtrace}] [-I DIR ...] [--include-remote] [-x PATTERN ...] [-l]
| Flag | Description |
|---|---|
INPUT |
Input file (.instr or .json) |
MEMBER ... |
Only extract files matching these glob patterns (repeatable positional; default: extract everything) |
-o, --output |
Output directory (if omitted, inferred as <stem>.extracted); ignored with -l/--list |
--flavor |
Flavor used when reading .instr input (mcstas default) |
-I, --search-dir |
Extra component search directory when reading .instr |
--trust-local-registries |
Trust local registries restored from a serialized (.json) instrument |
--include-remote |
Also extract component definitions and dependency files available from a remote registry, for a fully self-contained bundle |
-x, --exclude PATTERN |
Glob pattern to omit from extraction (repeatable) |
-l, --list |
List the files this invocation would extract, with category and source, without writing anything |
Examples:
# See what a plain extract would produce, without writing anything
mccode-antlr extract my.instr --list
# Pull just one component definition out of a bundle
mccode-antlr extract my.instr Progress_bar.comp -o ./just-progress-bar
# Fully self-contained bundle, but skip the C source files
mccode-antlr extract my.instr --include-remote -x '*.c'