Skip to content

Conversation

yannrichet-asnr
Copy link
Member

Summary

Implements an automated plugin import system that generates model aliases, calculator aliases, and wrapper scripts from Funz plugin repositories. Successfully integrated MORET and MCNP nuclear calculation plugins as initial examples.

Features

Plugin Import Script (scripts/import_plugin.py)

  • Clones Funz plugin repositories from GitHub
  • Parses .ioplugin configuration files
  • Extracts variable syntax (varprefix, delim, formulaprefix, commentline)
  • Converts Funz output patterns to shell extraction commands (grep/sed)
  • Creates model alias JSON files in .fz/models/
  • Generates calculator wrapper scripts in scripts/
  • Creates calculator aliases in .fz/calculators/
  • Copies sample files to examples/ for testing

MORET Plugin Support

  • Model alias: .fz/models/moret.json
    • Variable prefix: $
    • Delimiters: ()
    • Comment: *
    • Output extraction from .listing files
  • Calculator: moret.sh wrapper script
    • Checks /opt/MORET/scripts/moret.py or moret in PATH
    • Clear error messages if not found
  • Sample: examples/moret/godiva.m5
  • Tests: tests/test_moret_plugin.py

MCNP Plugin Support

  • Model alias: .fz/models/mcnp.json
    • Variable prefix: %
    • Delimiters: ()
    • Comment: C
    • Output extraction from outp files
  • Calculator: mcnp.sh wrapper script
    • Checks MCNP_PATH env var, /Applications/MCNP6, or mcnp6 in PATH
    • Handles MCNP-specific setup (DATAPATH, ulimit, PID tracking)
  • Sample: examples/mcnp/godiva
  • Tests: tests/test_mcnp_plugin.py

CI/CD

Added .github/workflows/plugin-imports.yml workflow that:

  • Tests on Linux, macOS, and Windows
  • Tests Python 3.9, 3.10, 3.11, 3.12
  • Imports both MORET and MCNP plugins
  • Verifies model and calculator aliases are created
  • Runs all plugin tests

Test Results

✅ All 4 tests pass:

  • test_moret_model_extraction - Variable extraction and output parsing
  • test_moret_sample_file - Sample file validation
  • test_mcnp_model_extraction - Variable extraction and output parsing
  • test_mcnp_sample_file - Sample file validation

Usage

Import a plugin:

python scripts/import_plugin.py moret
python scripts/import_plugin.py mcnp

Use in code:

import fz

# Using MORET
results = fz.fzr("input.m5", "moret", 
                 var_values={"radius": 8.741},
                 calculators="moret://")

# Using MCNP
results = fz.fzr("input.mcnp", "mcnp",
                 var_values={"n_particles": 1000},
                 calculators="mcnp://")

Files Changed

New files:

  • scripts/import_plugin.py - Plugin import automation
  • scripts/moret.sh - MORET calculator wrapper
  • scripts/mcnp.sh - MCNP calculator wrapper
  • tests/test_moret_plugin.py - MORET tests
  • tests/test_mcnp_plugin.py - MCNP tests
  • examples/moret/godiva.m5 - MORET sample
  • examples/mcnp/godiva - MCNP sample
  • .github/workflows/plugin-imports.yml - CI workflow

Modified:

  • .gitignore - Allow tests/** and scripts/**

Generated (not tracked):

  • .fz/models/moret.json - MORET model alias
  • .fz/models/mcnp.json - MCNP model alias
  • .fz/calculators/moret.json - MORET calculator alias
  • .fz/calculators/mcnp.json - MCNP calculator alias

Notes

  • Calculator scripts assume local installation of MORET/MCNP
  • Users can customize paths by editing scripts/moret.sh and scripts/mcnp.sh
  • The import script can be extended to support additional Funz plugins

🤖 Generated with Claude Code

yannrichet and others added 4 commits October 4, 2025 04:42
- Create plugin import script to automate Funz plugin integration
- Parse .ioplugin files to extract model configuration
- Convert Funz output patterns to shell extraction commands
- Import MORET nuclear calculation plugin as first example
- Add tests for MORET model variable extraction and output parsing
- Add CI workflow to test plugin import and model validation
- Update .gitignore to allow tests directory tracking

The import script:
- Clones Funz plugin repositories
- Parses variable syntax (varprefix, delim, formulaprefix)
- Extracts output parsing patterns
- Creates model alias JSON files
- Copies sample files for testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Update import script to handle MCNP output patterns
- Parse MCNP keff output from "final estimated combined" line
- Extract keff value and standard deviation using sed
- Add MCNP plugin tests for variable extraction and output parsing
- Update CI workflow to test both MORET and MCNP plugins
- Rename workflow from plugin-moret.yml to plugin-imports.yml

MCNP specifics:
- Variable prefix: % (instead of $ for MORET)
- Comment character: C (instead of * for MORET)
- Output file: outp (instead of .listing for MORET)
- Output format: "keff = X.XXXXX with an estimated standard deviation of X.XXXXX"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Copy calculator scripts from plugin repositories
- Create calculator aliases in .fz/calculators/
- Support both .sh and .bat scripts from plugins
- Add script name detection (lowercase, capitalized, uppercase)
- Store scripts in scripts/calculators/ directory

Created for MORET and MCNP:
- .fz/calculators/moret.json - references Moret.sh
- .fz/calculators/mcnp.json - references MCNP.sh
- scripts/calculators/Moret.sh - calls /opt/MORET/scripts/moret.py
- scripts/calculators/MCNP.sh - calls mcnp6 with proper env setup
- scripts/calculators/MCNP.bat - Windows batch version

Updated CI to verify calculator aliases are created

Note: These scripts assume local installation of MORET and MCNP codes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Replace scripts/calculators/ with direct scripts/moret.sh and mcnp.sh
- Calculator aliases now reference "sh://bash moret.sh" instead of full paths
- Created self-contained wrapper scripts inspired by plugin originals
- Added fallback logic to check multiple installation paths

Changes:
- moret.sh: Checks /opt/MORET/scripts/moret.py or moret in PATH
- mcnp.sh: Checks MCNP_PATH env var, /Applications/MCNP6, or mcnp6 in PATH
- Both scripts provide clear error messages if calculators not found

Calculator aliases:
- .fz/calculators/moret.json: "sh://bash moret.sh"
- .fz/calculators/mcnp.json: "sh://bash mcnp.sh"

This simplifies the structure and makes scripts easier to customize

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@Copilot Copilot AI review requested due to automatic review settings October 4, 2025 06:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements an automated plugin import system that integrates Funz plugins (specifically MORET and MCNP nuclear calculation tools) by parsing their configurations, creating model aliases, and generating wrapper scripts for seamless execution.

  • Automated plugin import script that clones Funz repositories and extracts configuration
  • Integration of MORET and MCNP plugins with model aliases, calculator wrappers, and sample files
  • CI/CD workflow for testing plugin imports across multiple platforms and Python versions

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
scripts/import_plugin.py Core automation script that parses Funz .ioplugin files and generates fz-compatible aliases
scripts/moret.sh MORET calculator wrapper script with installation path detection
scripts/mcnp.sh MCNP calculator wrapper script with environment setup and process management
tests/test_moret_plugin.py Test suite for MORET plugin functionality including variable extraction and output parsing
tests/test_mcnp_plugin.py Test suite for MCNP plugin functionality including variable extraction and output parsing
examples/moret/godiva.m5 MORET sample input file for testing
examples/mcnp/godiva MCNP sample input file for testing
.github/workflows/plugin-imports.yml CI workflow for testing plugin imports across platforms

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +263 to +270
script_content = f"""#!/bin/bash
# {plugin_name.upper()} calculator wrapper
# TODO: Configure the path to {plugin_name.upper()} executable

echo "ERROR: {plugin_name.upper()} calculator not configured yet."
echo "Please edit this script to set the correct path to {plugin_name.upper()}."
exit 1
"""
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generic error message includes unnecessary escape sequences. Consider using a triple-quoted string without f-string formatting or proper escaping to avoid potential issues with plugin names containing special characters.

Suggested change
script_content = f"""#!/bin/bash
# {plugin_name.upper()} calculator wrapper
# TODO: Configure the path to {plugin_name.upper()} executable
echo "ERROR: {plugin_name.upper()} calculator not configured yet."
echo "Please edit this script to set the correct path to {plugin_name.upper()}."
exit 1
"""
script_content = """#!/bin/bash
# {plugin} calculator wrapper
# TODO: Configure the path to {plugin} executable
echo "ERROR: {plugin} calculator not configured yet."
echo "Please edit this script to set the correct path to {plugin}."
exit 1
""".format(plugin=plugin_name.upper())

Copilot uses AI. Check for mistakes.

Comment on lines +15 to +20
$MCNP_PATH/MCNP_CODE/bin/mcnp6 inp="$@" &
PID_MCNP=$!
echo $PID_MCNP >> PID
wait $PID_MCNP
elif command -v mcnp6 &> /dev/null; then
mcnp6 inp="$@" &
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command line argument handling is incorrect. MCNP expects the input filename as a positional argument, not as 'inp="$@"'. This should be just '$MCNP_PATH/MCNP_CODE/bin/mcnp6 "$@"' or if the inp= syntax is required, it should be 'inp="$1"' for a single input file.

Suggested change
$MCNP_PATH/MCNP_CODE/bin/mcnp6 inp="$@" &
PID_MCNP=$!
echo $PID_MCNP >> PID
wait $PID_MCNP
elif command -v mcnp6 &> /dev/null; then
mcnp6 inp="$@" &
$MCNP_PATH/MCNP_CODE/bin/mcnp6 "$1" &
PID_MCNP=$!
echo $PID_MCNP >> PID
wait $PID_MCNP
elif command -v mcnp6 &> /dev/null; then
mcnp6 "$1" &

Copilot uses AI. Check for mistakes.

Comment on lines +15 to +20
$MCNP_PATH/MCNP_CODE/bin/mcnp6 inp="$@" &
PID_MCNP=$!
echo $PID_MCNP >> PID
wait $PID_MCNP
elif command -v mcnp6 &> /dev/null; then
mcnp6 inp="$@" &
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above - the command line argument handling is incorrect. This should be 'mcnp6 "$@"' or 'mcnp6 inp="$1"' if the inp= syntax is specifically required by MCNP.

Suggested change
$MCNP_PATH/MCNP_CODE/bin/mcnp6 inp="$@" &
PID_MCNP=$!
echo $PID_MCNP >> PID
wait $PID_MCNP
elif command -v mcnp6 &> /dev/null; then
mcnp6 inp="$@" &
$MCNP_PATH/MCNP_CODE/bin/mcnp6 inp="$1" &
PID_MCNP=$!
echo $PID_MCNP >> PID
wait $PID_MCNP
elif command -v mcnp6 &> /dev/null; then
mcnp6 inp="$1" &

Copilot uses AI. Check for mistakes.

Comment on lines +28 to +49
input_file.write_text("""MORET_BEGIN
TITLE TEST

TERM
CYCL
ACTI $(n_cycles)
PASS 3
KEFF
SIGM 0.001
ENDT

* Geometry modelling
GEOM
MODU 0
TYPE 1 SPHE $(radius)
VOLU Ext0 0 1 1 0.0 0.0 0.0
ENDM
ENDG

ENDD
MORET_END
""")
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multi-line string contains inconsistent indentation. The MORET input format appears to require specific spacing, but the Python indentation makes this unclear. Consider using textwrap.dedent() or adjusting the string formatting to make the actual MORET input structure more apparent.

Copilot uses AI. Check for mistakes.

Comment on lines +28 to +38
input_file.write_text("""Godiva-type critical reactor
c kcode example with %(n_particles) neutrons
1 1 -18.74 -1 imp:n=1 $ enriched uranium sphere
2 0 1 imp:n=0 $ all space outside

1 so %(radius) $ radius of sphere

kcode %(n_particles) 1.0 10 110
ksrc 0 0 0
m1 92235 -93.71 92238 -5.27 92234 -1.02
""")
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the MORET test, the multi-line string has inconsistent indentation that may not reflect the actual MCNP input format requirements. Consider using textwrap.dedent() to clarify the intended structure.

Copilot uses AI. Check for mistakes.

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