From 6a5d253a627c2e06c42a4c90c50641cab1807c38 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 13:29:05 +0000 Subject: [PATCH 1/4] Initial plan From b7866c4251c81156b66997d710915dec17ef440c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 13:41:25 +0000 Subject: [PATCH 2/4] Refactor repository structure to match fz-Model template Co-authored-by: yannrichet-asnr <148193180+yannrichet-asnr@users.noreply.github.com> --- ...ocalhost_MCNP.json => localhost_MCNP.json} | 0 .gitignore | 43 +--- CONTRIBUTING.md | 2 +- MIGRATION.md | 14 +- QUICKSTART.md | 10 +- README.md | 32 +-- .../MCNP/example_godiva.py | 9 +- godiva.inp => examples/MCNP/godiva.inp | 0 tests/test_plugin.py | 202 ++++++++++++++++++ 9 files changed, 247 insertions(+), 65 deletions(-) rename .fz/calculators/{Localhost_MCNP.json => localhost_MCNP.json} (100%) rename example_godiva.py => examples/MCNP/example_godiva.py (92%) rename godiva.inp => examples/MCNP/godiva.inp (100%) create mode 100755 tests/test_plugin.py diff --git a/.fz/calculators/Localhost_MCNP.json b/.fz/calculators/localhost_MCNP.json similarity index 100% rename from .fz/calculators/Localhost_MCNP.json rename to .fz/calculators/localhost_MCNP.json diff --git a/.gitignore b/.gitignore index 04d0ed8..f66a2ed 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,12 @@ srctp *.s PID -# Results directories +# Results and temporary files results/ *_results/ +*.out +*.msg +*.html # Python __pycache__/ @@ -17,43 +20,19 @@ __pycache__/ *$py.class *.so .Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg - -# Virtual environments venv/ ENV/ -env/ +.venv -# IDE -.vscode/ -.idea/ -*.swp -*.swo -*~ +# fz temporary files +.fz/tmp/ # OS .DS_Store Thumbs.db -# Temporary files -.fz/tmp/ -*.tmp -*.bak -*.log +# Build artifacts +build/ +dist/ +*.egg-info/ -# Test outputs -test_results/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fd5a993..a672a03 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -92,7 +92,7 @@ When requesting a feature: # Validate JSON files python -m json.tool .fz/models/MCNP.json - python -m json.tool .fz/calculators/Localhost_MCNP.json + python -m json.tool .fz/calculators/localhost_MCNP.json # Check shell script syntax bash -n .fz/calculators/MCNP.sh diff --git a/MIGRATION.md b/MIGRATION.md index e5e8d0b..062b93d 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -24,7 +24,7 @@ fz-mcnp/ ├── .fz/ │ ├── calculators/ │ │ ├── MCNP.sh # Calculator script -│ │ └── Localhost_MCNP.json # Calculator configuration +│ │ └── localhost_MCNP.json # Calculator configuration │ └── models/ │ └── MCNP.json # Model definition ├── .gitignore @@ -111,7 +111,7 @@ if [ -f "PID" ]; then rm -f "PID"; fi } ``` -This allows using the calculator by name: `calculators="Localhost_MCNP"` +This allows using the calculator by name: `calculators="localhost_MCNP"` ## Feature Mapping @@ -172,7 +172,7 @@ results = fz.fzr( "godiva.inp", {"r": 8.741}, "MCNP", - calculators="Localhost_MCNP" + calculators="localhost_MCNP" ) keff = results['mean_keff'][0] ``` @@ -182,7 +182,7 @@ keff = results['mean_keff'][0] - [x] Port MCNP.ioplugin to MCNP.json model - [x] Convert output parsing to shell commands - [x] Enhance MCNP.sh calculator script -- [x] Create Localhost_MCNP.json calculator config +- [x] Create localhost_MCNP.json calculator config - [x] Migrate godiva sample file - [x] Create comprehensive README - [x] Add Python example script @@ -203,9 +203,9 @@ To test the migrated plugin: Expected output structure: ``` r mean_keff sigma_keff status calculator -0 8.5 0.9850 0.0012 done Localhost_MCNP -1 8.741 0.9995 0.0006 done Localhost_MCNP -2 9.0 1.0145 0.0008 done Localhost_MCNP +0 8.5 0.9850 0.0012 done localhost_MCNP +1 8.741 0.9995 0.0006 done localhost_MCNP +2 9.0 1.0145 0.0008 done localhost_MCNP ``` ## Future Enhancements diff --git a/QUICKSTART.md b/QUICKSTART.md index 9227239..c162bbc 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -68,9 +68,9 @@ Results: ============================================================ r mean_keff sigma_keff status calculator -0 8.5 0.9850 0.0012 done Localhost_MCNP -1 8.741 0.9995 0.0006 done Localhost_MCNP -2 9.0 1.0145 0.0008 done Localhost_MCNP +0 8.5 0.9850 0.0012 done localhost_MCNP +1 8.741 0.9995 0.0006 done localhost_MCNP +2 9.0 1.0145 0.0008 done localhost_MCNP ------------------------------------------------------------ Total calculations: 3 @@ -106,7 +106,7 @@ results = fz.fzr( "r": [8.0, 8.5, 9.0, 9.5] # Parameter values to study }, model="MCNP", # Use MCNP model - calculators="Localhost_MCNP", # Use local calculator + calculators="localhost_MCNP", # Use local calculator results_dir="my_results" # Where to store results ) @@ -169,7 +169,7 @@ results = fz.fzr( "cycles": [110, 510, 1010] # Total cycles }, "MCNP", - calculators="Localhost_MCNP", + calculators="localhost_MCNP", results_dir="multi_param_study" ) diff --git a/README.md b/README.md index e25a74e..7bcbcce 100644 --- a/README.md +++ b/README.md @@ -40,15 +40,15 @@ This plugin enables parametric studies with MCNP using the [fz framework](https: 3. The plugin is ready to use! The `.fz` directory contains: - `.fz/models/MCNP.json` - Model definition - `.fz/calculators/MCNP.sh` - Calculation script - - `.fz/calculators/Localhost_MCNP.json` - Calculator configuration + - `.fz/calculators/localhost_MCNP.json` - Calculator configuration ## Usage ### Example: Godiva Critical Reactor Study -The repository includes a sample input file `godiva.inp` demonstrating a parametric study of a Godiva-type critical reactor. +The repository includes example files in `examples/MCNP/` demonstrating a parametric study of a Godiva-type critical reactor. -**Input file (`godiva.inp`):** +**Input file (`examples/MCNP/godiva.inp`):** ``` Godiva-type critical reactor and kcode example c skip 10 and run a total of 110 keff cycles with 1000 neutrons per cycle @@ -62,7 +62,7 @@ c skip 10 and run a total of 110 keff cycles with 1000 neutrons per cycle m1 92235 -93.71 92238 -5.27 92234 -1.02 $ define u with weight fractions ``` -**Python script to run parametric study:** +**Python script to run parametric study (`examples/MCNP/example_godiva.py`):** ```python import fz import os @@ -77,10 +77,10 @@ input_variables = { # Run parametric study results = fz.fzr( - input_path="godiva.inp", + input_path="examples/MCNP/godiva.inp", input_variables=input_variables, model="MCNP", - calculators="Localhost_MCNP", + calculators="localhost_MCNP", results_dir="results" ) @@ -92,9 +92,9 @@ print(f"\nCompleted {len(results)} calculations") **Expected output:** ``` r mean_keff sigma_keff status calculator -0 8.5 0.9850 0.0012 done Localhost_MCNP -1 8.741 0.9995 0.0006 done Localhost_MCNP -2 9.0 1.0145 0.0008 done Localhost_MCNP +0 8.5 0.9850 0.0012 done localhost_MCNP +1 8.741 0.9995 0.0006 done localhost_MCNP +2 9.0 1.0145 0.0008 done localhost_MCNP Completed 3 calculations ``` @@ -144,7 +144,7 @@ Run MCNP on a remote server via SSH: import fz results = fz.fzr( - "godiva.inp", + "examples/MCNP/godiva.inp", {"r": [8.5, 8.741, 9.0]}, "MCNP", calculators="ssh://user@hpc.example.com/bash /path/to/fz-mcnp/.fz/calculators/MCNP.sh", @@ -159,21 +159,21 @@ import fz # First run results1 = fz.fzr( - "godiva.inp", + "examples/MCNP/godiva.inp", {"r": [8.5, 8.741, 9.0]}, "MCNP", - calculators="Localhost_MCNP", + calculators="localhost_MCNP", results_dir="run1" ) # Second run with additional values - reuses previous results results2 = fz.fzr( - "godiva.inp", + "examples/MCNP/godiva.inp", {"r": [8.5, 8.741, 9.0, 9.5, 10.0]}, # Added 9.5 and 10.0 "MCNP", calculators=[ "cache://run1", # Check cache first - "Localhost_MCNP" # Only run new cases + "localhost_MCNP" # Only run new cases ], results_dir="run2" ) @@ -188,10 +188,10 @@ import fz # Use multiple calculator instances for parallel execution results = fz.fzr( - "godiva.inp", + "examples/MCNP/godiva.inp", {"r": list(range(8, 11, 0.1))}, # Many parameter values "MCNP", - calculators=["Localhost_MCNP"] * 4, # 4 parallel workers + calculators=["localhost_MCNP"] * 4, # 4 parallel workers results_dir="parallel_results" ) ``` diff --git a/example_godiva.py b/examples/MCNP/example_godiva.py similarity index 92% rename from example_godiva.py rename to examples/MCNP/example_godiva.py index 20b7ad7..9aad2f8 100755 --- a/example_godiva.py +++ b/examples/MCNP/example_godiva.py @@ -30,13 +30,14 @@ def main(): os.environ['MCNP_PATH'] = '/Applications/MCNP6' print("(You will need to update this for actual calculations)\n") - # Define the input file - input_file = "godiva.inp" + # Define the input file (in the same directory as this script) + script_dir = os.path.dirname(os.path.abspath(__file__)) + input_file = os.path.join(script_dir, "godiva.inp") # Check if input file exists if not os.path.exists(input_file): print(f"Error: Input file '{input_file}' not found.") - print("Please run this script from the fz-mcnp directory.") + print("Please run this script from the examples/MCNP directory.") sys.exit(1) print("=" * 60) @@ -64,7 +65,7 @@ def main(): input_path=input_file, input_variables=input_variables, model="MCNP", - calculators="Localhost_MCNP", + calculators="localhost_MCNP", results_dir="results" ) diff --git a/godiva.inp b/examples/MCNP/godiva.inp similarity index 100% rename from godiva.inp rename to examples/MCNP/godiva.inp diff --git a/tests/test_plugin.py b/tests/test_plugin.py new file mode 100755 index 0000000..be6a189 --- /dev/null +++ b/tests/test_plugin.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python3 +""" +Basic test suite for fz-MCNP plugin. + +These tests verify the plugin structure. +They test: +- Model file validity +- Variable parsing +- Input file compilation +- Calculator configuration +""" + +import os +import json +import tempfile +import sys + + +def test_model_files(): + """Test that all model JSON files are valid and have required fields.""" + print("Testing model files...") + + models = [ + ".fz/models/MCNP.json" + ] + + required_fields = ["id", "varprefix", "delim", "commentline", "output"] + + for model_file in models: + print(f" Checking {model_file}...", end=" ") + + # Check file exists + assert os.path.exists(model_file), f"File not found: {model_file}" + + # Load and validate JSON + with open(model_file, 'r') as f: + model = json.load(f) + + # Check required fields + for field in required_fields: + assert field in model, f"Missing field '{field}' in {model_file}" + + # Check output section has at least one variable + assert len(model["output"]) > 0, f"No output variables in {model_file}" + + print("✓") + + print(" All model files valid!\n") + + +def test_calculator_files(): + """Test that calculator JSON files are valid.""" + print("Testing calculator configuration files...") + + calculators = [ + ".fz/calculators/localhost_MCNP.json" + ] + + for calc_file in calculators: + print(f" Checking {calc_file}...", end=" ") + + # Check file exists + assert os.path.exists(calc_file), f"File not found: {calc_file}" + + # Load and validate JSON + with open(calc_file, 'r') as f: + calc = json.load(f) + + # Check required fields + assert "uri" in calc, f"Missing 'uri' field in {calc_file}" + assert "models" in calc, f"Missing 'models' field in {calc_file}" + + print("✓") + + print(" All calculator files valid!\n") + + +def test_calculator_scripts(): + """Test that calculator shell scripts exist and are executable.""" + print("Testing calculator shell scripts...") + + scripts = [ + ".fz/calculators/MCNP.sh" + ] + + for script_file in scripts: + print(f" Checking {script_file}...", end=" ") + + # Check file exists + assert os.path.exists(script_file), f"File not found: {script_file}" + + # Check if executable + assert os.access(script_file, os.X_OK), f"Script not executable: {script_file}" + + print("✓") + + print(" All calculator scripts valid!\n") + + +def test_example_files(): + """Test that example files exist.""" + print("Testing example files...") + + examples = [ + "examples/MCNP/godiva.inp", + "examples/MCNP/example_godiva.py" + ] + + for example_file in examples: + print(f" Checking {example_file}...", end=" ") + assert os.path.exists(example_file), f"File not found: {example_file}" + print("✓") + + print(" All example files present!\n") + + +def test_with_fz(): + """Test integration with fz framework (if available).""" + print("Testing fz framework integration...") + + try: + import fz + print(" fz module found ✓") + + # Test parsing input file + print(" Testing fz.fzi() on godiva.inp...", end=" ") + variables = fz.fzi("examples/MCNP/godiva.inp", "MCNP") + assert "r" in variables, "Variable 'r' not found in parsed input" + print("✓") + + # Test compiling input file + print(" Testing fz.fzc() compilation...", end=" ") + with tempfile.TemporaryDirectory() as tmpdir: + fz.fzc( + "examples/MCNP/godiva.inp", + {"r": 8.741}, + "MCNP", + output_dir=tmpdir + ) + + # Check compiled file exists (it may be in a subdirectory) + compiled_file = None + for root, dirs, files in os.walk(tmpdir): + if "godiva.inp" in files: + compiled_file = os.path.join(root, "godiva.inp") + break + assert compiled_file is not None, "Compiled file not created" + + # Check variable was substituted + with open(compiled_file, 'r') as f: + content = f.read() + assert "8.741" in content, "Variable r not substituted" + assert "%(r)" not in content, "Variable marker %(r) still present" + print("✓") + + print(" fz integration tests passed!\n") + + except ImportError: + print(" fz module not installed - skipping integration tests") + print(" (Install with: pip install git+https://github.com/Funz/fz.git)\n") + + +def main(): + """Run all tests.""" + print("=" * 70) + print("fz-MCNP Plugin Test Suite") + print("=" * 70) + print() + + # Change to repository root if needed + if not os.path.exists(".fz"): + if os.path.exists("../fz-MCNP/.fz"): + os.chdir("../fz-MCNP") + else: + print("Error: Could not find .fz directory") + print("Please run this script from the fz-MCNP repository root") + return 1 + + try: + test_model_files() + test_calculator_files() + test_calculator_scripts() + test_example_files() + test_with_fz() + + print("=" * 70) + print("All tests passed! ✓") + print("=" * 70) + return 0 + + except AssertionError as e: + print(f"\n✗ Test failed: {e}") + return 1 + except Exception as e: + print(f"\n✗ Unexpected error: {e}") + import traceback + traceback.print_exc() + return 1 + + +if __name__ == "__main__": + sys.exit(main()) From c4fc844c19eb6afcbdd8e0e29d647091d2106697 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 13:59:33 +0000 Subject: [PATCH 3/4] Align with fz-Model template: remove extra docs, add CI, add notebook, flatten examples Co-authored-by: yannrichet-asnr <148193180+yannrichet-asnr@users.noreply.github.com> --- .github/workflows/ci.yml | 122 +++++++++ CONTRIBUTING.md | 297 --------------------- MIGRATION.md | 220 ---------------- QUICKSTART.md | 195 -------------- README.md | 16 +- example_usage.ipynb | 364 ++++++++++++++++++++++++++ examples/{MCNP => }/example_godiva.py | 2 +- examples/{MCNP => }/godiva.inp | 0 tests/test_plugin.py | 8 +- 9 files changed, 499 insertions(+), 725 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 CONTRIBUTING.md delete mode 100644 MIGRATION.md delete mode 100644 QUICKSTART.md create mode 100644 example_usage.ipynb rename examples/{MCNP => }/example_godiva.py (98%) rename examples/{MCNP => }/godiva.inp (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e38c611 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,122 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: + contents: read + +jobs: + test: + name: Test Plugin Structure + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install fz framework + run: | + pip install git+https://github.com/Funz/fz.git + + - name: Validate JSON files + run: | + echo "Validating model files..." + for f in .fz/models/*.json; do + echo " Checking $f" + python -m json.tool "$f" > /dev/null + done + echo "Validating calculator config files..." + for f in .fz/calculators/*.json; do + echo " Checking $f" + python -m json.tool "$f" > /dev/null + done + + - name: Check shell script syntax + run: | + echo "Checking shell scripts..." + for f in .fz/calculators/*.sh; do + echo " Checking $f" + bash -n "$f" + done + + - name: Test fzi (parse variables) + run: | + python -c " + import fz + variables = fz.fzi('examples/godiva.inp', 'MCNP') + print(f'Variables found: {list(variables.keys())}') + assert 'r' in variables, 'Variable r not found' + print('✓ fzi test passed') + " + + - name: Test fzc (compile input) + run: | + python -c " + import fz + import tempfile + import os + with tempfile.TemporaryDirectory() as tmpdir: + fz.fzc('examples/godiva.inp', {'r': 8.741}, 'MCNP', output_dir=tmpdir) + compiled = os.path.join(tmpdir, 'r=8.741', 'godiva.inp') + assert os.path.exists(compiled), 'Compiled file not created' + with open(compiled) as f: + content = f.read() + assert '8.741' in content, 'Variable not substituted' + print('✓ fzc test passed') + " + + - name: Run plugin tests + run: | + python tests/test_plugin.py + + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check shell scripts are executable + run: | + for f in .fz/calculators/*.sh; do + if [ ! -x "$f" ]; then + echo "Error: $f is not executable" + exit 1 + fi + done + + docs: + name: Check Documentation + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check required documentation files + run: | + for f in README.md LICENSE; do + if [ ! -f "$f" ]; then + echo "Error: Missing $f" + exit 1 + fi + echo "✓ $f exists" + done + + - name: Check example files + run: | + if [ ! -f "examples/godiva.inp" ]; then + echo "Error: Missing example input file" + exit 1 + fi + echo "✓ Example files present" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index a672a03..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,297 +0,0 @@ -# Contributing to fz-mcnp - -Thank you for your interest in contributing to fz-mcnp! This document provides guidelines for contributing to this project. - -## Getting Started - -1. Fork the repository on GitHub -2. Clone your fork locally -3. Set up your development environment (see below) -4. Create a feature branch for your changes -5. Make your changes and test them -6. Submit a pull request - -## Development Environment Setup - -### Prerequisites - -- MCNP6 installation (for testing) -- Python 3.7 or higher -- Git -- fz framework - -### Setup Steps - -```bash -# Clone your fork -git clone https://github.com/YOUR_USERNAME/fz-mcnp.git -cd fz-mcnp - -# Install fz framework -cd .. -git clone https://github.com/Funz/fz.git -cd fz -pip install -e . - -# Return to fz-mcnp -cd ../fz-mcnp - -# Set MCNP_PATH -export MCNP_PATH="/path/to/your/MCNP6" -``` - -## Types of Contributions - -### Bug Reports - -When filing a bug report, please include: - -- A clear, descriptive title -- Steps to reproduce the issue -- Expected behavior -- Actual behavior -- MCNP version -- Python version -- Operating system -- Relevant error messages or logs - -### Feature Requests - -When requesting a feature: - -- Explain the use case -- Describe the desired behavior -- Provide examples if possible -- Explain why this would benefit other users - -### Code Contributions - -#### Before You Start - -- Check existing issues and pull requests -- Discuss major changes in an issue first -- Follow the coding style of the project -- Write clear commit messages - -#### Making Changes - -1. **Create a feature branch:** - ```bash - git checkout -b feature/your-feature-name - ``` - -2. **Make your changes:** - - Keep changes focused and atomic - - Update documentation as needed - - Add examples if relevant - -3. **Test your changes:** - ```bash - # Test with example - python example_godiva.py - - # Validate JSON files - python -m json.tool .fz/models/MCNP.json - python -m json.tool .fz/calculators/localhost_MCNP.json - - # Check shell script syntax - bash -n .fz/calculators/MCNP.sh - - # Check Python syntax - python -m py_compile example_godiva.py - ``` - -4. **Commit your changes:** - ```bash - git add . - git commit -m "Add feature: brief description" - ``` - -5. **Push to your fork:** - ```bash - git push origin feature/your-feature-name - ``` - -6. **Open a Pull Request:** - - Go to the original repository on GitHub - - Click "New Pull Request" - - Select your feature branch - - Fill in the PR template - - Submit the PR - -## Coding Guidelines - -### Shell Scripts - -- Use `#!/bin/bash` shebang -- Add comments for complex logic -- Validate input parameters -- Provide clear error messages -- Use `set -e` for critical scripts - -Example: -```bash -#!/bin/bash - -# Check required environment variable -if [ -z "$MCNP_PATH" ]; then - echo "Error: MCNP_PATH is not set" - exit 1 -fi -``` - -### Python Scripts - -- Follow PEP 8 style guide -- Use meaningful variable names -- Add docstrings for functions -- Handle exceptions appropriately -- Keep functions focused - -Example: -```python -def run_mcnp_study(input_file, parameters): - """ - Run MCNP parametric study. - - Args: - input_file: Path to MCNP input file - parameters: Dict of parameter values - - Returns: - DataFrame with results - """ - # Implementation here -``` - -### JSON Configuration - -- Use 4-space indentation -- Keep structure consistent -- Validate JSON syntax -- Add comments in documentation - -Example: -```json -{ - "id": "MCNP", - "varprefix": "%", - "delim": "()", - "output": { - "mean_keff": "shell command here" - } -} -``` - -### Documentation - -- Use clear, concise language -- Provide examples -- Keep README up to date -- Document all options and parameters - -## Testing - -### Manual Testing - -Test your changes with: - -1. **Basic functionality:** - ```bash - python example_godiva.py - ``` - -2. **Different parameter values:** - ```python - import fz - results = fz.fzr("godiva.inp", {"r": [8.0, 9.0]}, "MCNP") - ``` - -3. **Edge cases:** - - Empty parameter lists - - Invalid MCNP paths - - Missing input files - - Malformed MCNP input - -### Test Coverage - -If adding new features, consider: - -- Normal operation -- Error conditions -- Edge cases -- Performance implications - -## Documentation Updates - -When making changes, update: - -- README.md (if user-facing) -- QUICKSTART.md (if affecting setup) -- MIGRATION.md (if changing compatibility) -- Code comments (always) -- Example scripts (if relevant) - -## Pull Request Process - -1. **PR Title:** Clear and descriptive (e.g., "Add support for MCNP5") -2. **PR Description:** Explain what, why, and how -3. **Testing:** Describe testing performed -4. **Breaking Changes:** Clearly mark if any -5. **Documentation:** Confirm docs are updated - -### PR Checklist - -- [ ] Code follows project style -- [ ] Tests pass (manual testing) -- [ ] Documentation updated -- [ ] Commit messages are clear -- [ ] No merge conflicts -- [ ] JSON files validated -- [ ] Shell scripts validated -- [ ] Python scripts validated - -## Versioning - -We use semantic versioning (MAJOR.MINOR.PATCH): - -- **MAJOR:** Breaking changes -- **MINOR:** New features (backward compatible) -- **PATCH:** Bug fixes - -## Code Review - -All submissions require review. We'll: - -- Review within a week -- Provide constructive feedback -- Request changes if needed -- Merge when approved - -Please be patient and responsive to feedback. - -## Community - -- Be respectful and professional -- Welcome newcomers -- Help others learn -- Share knowledge - -## Questions? - -- Open an issue for clarification -- Check existing documentation -- Review the fz framework docs - -## License - -By contributing, you agree that your contributions will be licensed under the BSD 3-Clause License. - -## Recognition - -Contributors are recognized in: -- Git history -- Release notes (for significant contributions) -- Special thanks section (as appropriate) - -Thank you for contributing to fz-mcnp! 🎉 diff --git a/MIGRATION.md b/MIGRATION.md deleted file mode 100644 index 062b93d..0000000 --- a/MIGRATION.md +++ /dev/null @@ -1,220 +0,0 @@ -# Migration from Old Plugin-MCNP to fz-mcnp - -This document describes how the old MCNP plugin was ported to the new fz framework. - -## Migration Overview - -### Old Structure (plugin-MCNP) -``` -plugin-MCNP/ -├── src/main/ -│ ├── io/ -│ │ └── MCNP.ioplugin # Old configuration format -│ ├── samples/ -│ │ └── godiva # Sample input file -│ └── scripts/ -│ ├── MCNP.sh # Shell script for Unix/Mac -│ └── MCNP.bat # Batch script for Windows -└── build.xml # Ant build file -``` - -### New Structure (fz-mcnp) -``` -fz-mcnp/ -├── .fz/ -│ ├── calculators/ -│ │ ├── MCNP.sh # Calculator script -│ │ └── localhost_MCNP.json # Calculator configuration -│ └── models/ -│ └── MCNP.json # Model definition -├── .gitignore -├── README.md -├── example_godiva.py # Python example -└── godiva.inp # Sample input file -``` - -## Key Changes - -### 1. Configuration Format - -**Old (.ioplugin format):** -``` -variableStartSymbol=% -variableLimit=(...) -formulaStartSymbol=@ -formulaLimit={...} -commentLineChar=C -output.mean_keff.get=grep("outp"," the final estimated combined") >> get(0) >> cut("keff = ",2) >> substring("ZZZ","with an estimated") >> asNumeric() -``` - -**New (JSON format):** -```json -{ - "id": "MCNP", - "varprefix": "%", - "formulaprefix": "@", - "delim": "()", - "commentline": "C ", - "output": { - "mean_keff": "grep 'the final estimated combined' outp | head -n 1 | awk '{match($0, /keff = ([0-9.]+)/, arr); print arr[1]}'" - } -} -``` - -### 2. Output Parsing - -**Old approach:** -- Custom parsing DSL with operators like `>>`, `cut()`, `substring()`, `asNumeric()` - -**New approach:** -- Standard shell commands (grep, awk, etc.) -- More flexible and Unix-standard -- Example: `grep 'pattern' file | awk '{print $N}'` - -### 3. Calculator Script - -**Old script:** -```bash -#!/bin/bash -export MCNP_PATH="/Applications/MCNP6" -export DATAPATH=$MCNP_PATH"/MCNP_DATA" -ulimit -s unlimited -echo $$ >> PID -$MCNP_PATH/MCNP_CODE/bin/mcnp6 inp=$* & -PID_MCNP=$! -echo $PID_MCNP >> PID -wait $PID_MCNP -if [ -f "PID" ]; then rm -f "PID"; fi -``` - -**New script:** -```bash -#!/bin/bash -# Enhanced with: -# - Environment variable validation -# - Better error handling -# - Support for directory and file inputs -# - Automatic input file detection -# - Comprehensive error messages -``` - -### 4. Calculator Configuration - -**New addition:** -```json -{ - "uri": "sh://", - "n": 1, - "models": { - "MCNP": "bash .fz/calculators/MCNP.sh" - } -} -``` - -This allows using the calculator by name: `calculators="localhost_MCNP"` - -## Feature Mapping - -| Old Feature | New Feature | Status | -|-------------|-------------|--------| -| Variable syntax `%(...)` | Variable syntax `%(...)` | ✅ Preserved | -| Formula syntax `@{...}` | Formula syntax `@{...}` | ✅ Preserved | -| Comment char `C ` | Comment char `C ` | ✅ Preserved | -| Output: mean_keff | Output: mean_keff | ✅ Implemented | -| Output: sigma_keff | Output: sigma_keff | ✅ Implemented | -| Dataset filtering | Not applicable | ➖ Simplified | -| Output functions | Native shell commands | ✅ Enhanced | -| Shell script | Enhanced shell script | ✅ Improved | - -## Improvements in New Version - -1. **Better Error Handling** - - Validates MCNP_PATH before execution - - Checks for MCNP executable existence - - Clear error messages - -2. **Flexible Input Handling** - - Accepts directory or file as input - - Auto-detects MCNP input files - - Supports multiple input patterns - -3. **Standard Tools** - - Uses standard Unix tools (grep, awk) - - No custom DSL to learn - - More maintainable and debuggable - -4. **Python Integration** - - Example Python script provided - - Easy integration with fz framework - - Pandas DataFrame output - -5. **Documentation** - - Comprehensive README - - Example usage - - Troubleshooting guide - -## Usage Comparison - -### Old Usage (Funz) -```java -// Java/Groovy code -Run r = new Run("MCNP", "godiva"); -r.setInputVariable("r", 8.741); -r.execute(); -Double keff = r.getOutputValue("mean_keff"); -``` - -### New Usage (fz) -```python -import fz - -results = fz.fzr( - "godiva.inp", - {"r": 8.741}, - "MCNP", - calculators="localhost_MCNP" -) -keff = results['mean_keff'][0] -``` - -## Migration Checklist - -- [x] Port MCNP.ioplugin to MCNP.json model -- [x] Convert output parsing to shell commands -- [x] Enhance MCNP.sh calculator script -- [x] Create localhost_MCNP.json calculator config -- [x] Migrate godiva sample file -- [x] Create comprehensive README -- [x] Add Python example script -- [x] Add .gitignore for MCNP outputs -- [x] Document migration process - -## Testing Notes - -To test the migrated plugin: - -1. Install MCNP and set MCNP_PATH -2. Install fz framework -3. Run the example: - ```bash - python example_godiva.py - ``` - -Expected output structure: -``` - r mean_keff sigma_keff status calculator -0 8.5 0.9850 0.0012 done localhost_MCNP -1 8.741 0.9995 0.0006 done localhost_MCNP -2 9.0 1.0145 0.0008 done localhost_MCNP -``` - -## Future Enhancements - -Potential improvements for future versions: - -- [ ] Support for additional MCNP output parameters -- [ ] Windows batch script calculator (MCNP.bat equivalent) -- [ ] Pre-configured remote HPC calculators -- [ ] Visualization examples for results -- [ ] Integration tests with mock MCNP outputs -- [ ] Support for MCNP5 in addition to MCNP6 diff --git a/QUICKSTART.md b/QUICKSTART.md deleted file mode 100644 index c162bbc..0000000 --- a/QUICKSTART.md +++ /dev/null @@ -1,195 +0,0 @@ -# Quick Start Guide - -Get started with fz-mcnp in 5 minutes! - -## Prerequisites - -1. **MCNP6** installed on your system -2. **Python 3.7+** installed -3. **fz framework** installed - -## Step 1: Install fz Framework - -```bash -git clone https://github.com/Funz/fz.git -cd fz -pip install -e . -``` - -## Step 2: Clone fz-mcnp - -```bash -cd .. -git clone https://github.com/Funz/fz-mcnp.git -cd fz-mcnp -``` - -## Step 3: Set MCNP Path - -```bash -# Linux/Mac: -export MCNP_PATH="/path/to/your/MCNP6" - -# Windows (PowerShell): -$env:MCNP_PATH="C:\path\to\your\MCNP6" - -# Windows (Command Prompt): -set MCNP_PATH=C:\path\to\your\MCNP6 -``` - -**Common MCNP paths:** -- Mac: `/Applications/MCNP6` -- Linux: `/opt/MCNP6` or `/usr/local/MCNP6` -- Windows: `C:\MCNP\MCNP6` - -## Step 4: Test the Installation - -Run the example script: - -```bash -python example_godiva.py -``` - -You should see output similar to: -``` -============================================================ -MCNP Parametric Study: Godiva Critical Reactor -============================================================ - -Parameters: - r: [8.5, 8.741, 9.0] - -Running calculations... ------------------------------------------------------------- -[... calculation progress ...] - -============================================================ -Results: -============================================================ - - r mean_keff sigma_keff status calculator -0 8.5 0.9850 0.0012 done localhost_MCNP -1 8.741 0.9995 0.0006 done localhost_MCNP -2 9.0 1.0145 0.0008 done localhost_MCNP - ------------------------------------------------------------- -Total calculations: 3 -Successful: 3 -Failed: 0 - -Critical Analysis: ------------------------------------------------------------- - r=8.500 cm: k_eff = 0.9850 ± 0.0012 (subcritical) - r=8.741 cm: k_eff = 0.9995 ± 0.0006 (critical) - r=9.000 cm: k_eff = 1.0145 ± 0.0008 (supercritical) - -============================================================ -Study completed successfully! -============================================================ -``` - -## Step 5: Create Your Own Study - -Create a new Python file `my_study.py`: - -```python -import fz -import os - -# Set MCNP path -os.environ['MCNP_PATH'] = '/path/to/your/MCNP6' - -# Run your parametric study -results = fz.fzr( - input_path="godiva.inp", # Your MCNP input file - input_variables={ - "r": [8.0, 8.5, 9.0, 9.5] # Parameter values to study - }, - model="MCNP", # Use MCNP model - calculators="localhost_MCNP", # Use local calculator - results_dir="my_results" # Where to store results -) - -# Analyze results -print(results) - -# Access specific values -for idx, row in results.iterrows(): - print(f"r={row['r']}: k_eff = {row['mean_keff']:.4f} ± {row['sigma_keff']:.4f}") -``` - -Run it: -```bash -python my_study.py -``` - -## Common Issues - -### Issue: "MCNP executable not found" - -**Solution:** Check your MCNP_PATH is correct: -```bash -echo $MCNP_PATH # Should show your MCNP directory -ls $MCNP_PATH/MCNP_CODE/bin/mcnp6 # Should exist -``` - -### Issue: "ModuleNotFoundError: No module named 'fz'" - -**Solution:** Install the fz framework: -```bash -pip install -e /path/to/fz -``` - -### Issue: "Permission denied" when running MCNP - -**Solution:** Make sure the script is executable: -```bash -chmod +x .fz/calculators/MCNP.sh -``` - -## Next Steps - -1. **Modify the input file**: Edit `godiva.inp` to change the MCNP model -2. **Add more parameters**: Use `%(param)` syntax in your input file -3. **Run in parallel**: Use multiple calculators for faster execution -4. **Use remote HPC**: Set up SSH calculator for cluster execution -5. **Explore caching**: Reuse previous results to save computation time - -## Example: Multi-Parameter Study - -```python -import fz - -# Study multiple parameters -results = fz.fzr( - "godiva.inp", - { - "r": [8.5, 8.741, 9.0], # Sphere radius - "neutrons": [1000, 5000, 10000], # Neutrons per cycle - "cycles": [110, 510, 1010] # Total cycles - }, - "MCNP", - calculators="localhost_MCNP", - results_dir="multi_param_study" -) - -# This will run 3 × 3 × 3 = 27 calculations -print(f"Completed {len(results)} calculations") -``` - -## Need Help? - -- Read the full [README.md](README.md) -- Check the [MIGRATION.md](MIGRATION.md) for details on porting from old plugin -- Visit the [fz framework documentation](https://github.com/Funz/fz) -- Open an issue on [GitHub](https://github.com/Funz/fz-mcnp/issues) - -## Tips - -- **Start small**: Test with a few parameter values first -- **Use caching**: Avoid re-running expensive calculations -- **Monitor resources**: MCNP can be memory-intensive -- **Check logs**: Look in results directories for detailed execution logs -- **Validate results**: Always verify MCNP completed successfully - -Happy computing! 🚀 diff --git a/README.md b/README.md index 7bcbcce..cd2fb6d 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,9 @@ This plugin enables parametric studies with MCNP using the [fz framework](https: ### Example: Godiva Critical Reactor Study -The repository includes example files in `examples/MCNP/` demonstrating a parametric study of a Godiva-type critical reactor. +The repository includes example files in `examples/` demonstrating a parametric study of a Godiva-type critical reactor. -**Input file (`examples/MCNP/godiva.inp`):** +**Input file (`examples/godiva.inp`):** ``` Godiva-type critical reactor and kcode example c skip 10 and run a total of 110 keff cycles with 1000 neutrons per cycle @@ -62,7 +62,7 @@ c skip 10 and run a total of 110 keff cycles with 1000 neutrons per cycle m1 92235 -93.71 92238 -5.27 92234 -1.02 $ define u with weight fractions ``` -**Python script to run parametric study (`examples/MCNP/example_godiva.py`):** +**Python script to run parametric study (`examples/example_godiva.py`):** ```python import fz import os @@ -77,7 +77,7 @@ input_variables = { # Run parametric study results = fz.fzr( - input_path="examples/MCNP/godiva.inp", + input_path="examples/godiva.inp", input_variables=input_variables, model="MCNP", calculators="localhost_MCNP", @@ -144,7 +144,7 @@ Run MCNP on a remote server via SSH: import fz results = fz.fzr( - "examples/MCNP/godiva.inp", + "examples/godiva.inp", {"r": [8.5, 8.741, 9.0]}, "MCNP", calculators="ssh://user@hpc.example.com/bash /path/to/fz-mcnp/.fz/calculators/MCNP.sh", @@ -159,7 +159,7 @@ import fz # First run results1 = fz.fzr( - "examples/MCNP/godiva.inp", + "examples/godiva.inp", {"r": [8.5, 8.741, 9.0]}, "MCNP", calculators="localhost_MCNP", @@ -168,7 +168,7 @@ results1 = fz.fzr( # Second run with additional values - reuses previous results results2 = fz.fzr( - "examples/MCNP/godiva.inp", + "examples/godiva.inp", {"r": [8.5, 8.741, 9.0, 9.5, 10.0]}, # Added 9.5 and 10.0 "MCNP", calculators=[ @@ -188,7 +188,7 @@ import fz # Use multiple calculator instances for parallel execution results = fz.fzr( - "examples/MCNP/godiva.inp", + "examples/godiva.inp", {"r": list(range(8, 11, 0.1))}, # Many parameter values "MCNP", calculators=["localhost_MCNP"] * 4, # 4 parallel workers diff --git a/example_usage.ipynb b/example_usage.ipynb new file mode 100644 index 0000000..e627046 --- /dev/null +++ b/example_usage.ipynb @@ -0,0 +1,364 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# fz-MCNP Plugin Example Usage\n", + "\n", + "This notebook demonstrates how to use the fz-MCNP plugin for parametric MCNP calculations.\n", + "\n", + "The examples cover:\n", + "1. Installing dependencies (fz framework and fz-MCNP plugin)\n", + "2. Downloading example input files\n", + "3. Parsing input files to identify variables\n", + "4. Compiling input files with specific parameter values\n", + "5. Running calculations with MCNP\n", + "6. Performing parametric studies\n", + "\n", + "**Note:** You must have MCNP installed and the MCNP_PATH environment variable set to use this plugin." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup: Install Dependencies\n", + "\n", + "First, install the Funz framework and the fz-MCNP plugin." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Install fz framework from GitHub\n", + "%pip install -q git+https://github.com/Funz/fz.git\n", + "\n", + "# Install fz-MCNP plugin\n", + "import fz\n", + "fz.install(\"MCNP\")\n", + "\n", + "print(\"✓ Dependencies installed successfully!\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup: Download Example Files\n", + "\n", + "Download the example input files from the GitHub repository." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import urllib.request\n", + "\n", + "# Create directory for examples\n", + "os.makedirs(\"MCNP\", exist_ok=True)\n", + "\n", + "# Base URL for raw GitHub content\n", + "base_url = \"https://raw.githubusercontent.com/Funz/fz-MCNP/main/examples\"\n", + "\n", + "# Download example files\n", + "files_to_download = [\n", + " (\"MCNP/godiva.inp\", f\"{base_url}/godiva.inp\"),\n", + "]\n", + "\n", + "print(\"Downloading example files...\")\n", + "for local_path, url in files_to_download:\n", + " try:\n", + " urllib.request.urlretrieve(url, local_path)\n", + " print(f\" ✓ Downloaded: {local_path}\")\n", + " except Exception as e:\n", + " print(f\" ✗ Failed to download {local_path}: {e}\")\n", + "\n", + "print(\"\\n✓ Example files ready!\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup: Configure MCNP Path\n", + "\n", + "Set the MCNP_PATH environment variable to point to your MCNP installation." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "# Set MCNP_PATH - adjust this path for your system\n", + "os.environ['MCNP_PATH'] = '/Applications/MCNP6' # Example path\n", + "\n", + "print(f\"MCNP_PATH set to: {os.environ['MCNP_PATH']}\")\n", + "print(\"Note: Adjust this path to match your MCNP installation\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Import Required Libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import fz\n", + "import os\n", + "import tempfile\n", + "\n", + "print(f\"fz version: {fz.__version__ if hasattr(fz, '__version__') else 'unknown'}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1: Parse Input File for Variables\n", + "\n", + "Use `fz.fzi()` to identify variables in an MCNP input file." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Parse the input file to find variables\n", + "variables = fz.fzi(\n", + " \"MCNP/godiva.inp\",\n", + " \"MCNP\"\n", + ")\n", + "\n", + "print(f\"Variables found in godiva.inp: {list(variables.keys())}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2: Compile Input Files\n", + "\n", + "Use `fz.fzc()` to compile input files with specific parameter values. This substitutes variables with actual values." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Create temporary directory for compiled files\n", + "with tempfile.TemporaryDirectory() as tmpdir:\n", + " # Compile input with specific value for radius\n", + " fz.fzc(\n", + " \"MCNP/godiva.inp\",\n", + " {\"r\": 8.741}, # Critical radius\n", + " \"MCNP\",\n", + " output_dir=tmpdir\n", + " )\n", + " \n", + " # Show compiled file\n", + " # Find the compiled file (it may be in a subdirectory)\n", + " for root, dirs, files in os.walk(tmpdir):\n", + " for f in files:\n", + " if f == \"godiva.inp\":\n", + " compiled_file = os.path.join(root, f)\n", + " print(f\"Compiled file content (r=8.741):\")\n", + " print(\"=\" * 70)\n", + " with open(compiled_file, 'r') as file:\n", + " print(file.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3: Run a Basic MCNP Calculation\n", + "\n", + "Run a simple MCNP calculation with a single parameter value.\n", + "\n", + "**Note:** This requires MCNP to be installed and properly configured." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Define parameter value\n", + "input_variables = {\n", + " \"r\": [8.741] # Critical radius\n", + "}\n", + "\n", + "try:\n", + " # Run MCNP calculation\n", + " results = fz.fzr(\n", + " input_path=\"MCNP/godiva.inp\",\n", + " input_variables=input_variables,\n", + " model=\"MCNP\",\n", + " calculators=\"localhost_MCNP\",\n", + " results_dir=\"results/basic_study\"\n", + " )\n", + " \n", + " # Display results\n", + " print(\"\\nResults:\")\n", + " print(\"=\" * 70)\n", + " print(results[['r', 'mean_keff', 'sigma_keff', 'status']])\n", + " \n", + "except Exception as e:\n", + " print(f\"\\nError running calculation: {e}\")\n", + " print(\"Note: Make sure MCNP is installed and MCNP_PATH is set correctly.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4: Parametric Study of Godiva Criticality\n", + "\n", + "Demonstrate a parametric study with multiple sphere radii to study criticality." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "\n", + "# Define multiple radius values around the critical radius\n", + "input_variables = {\n", + " \"r\": [8.5, 8.741, 9.0] # Subcritical, critical, supercritical\n", + "}\n", + "\n", + "print(f\"Running parametric study...\")\n", + "print(f\" r values: {input_variables['r']}\")\n", + "\n", + "try:\n", + " # Run parametric calculation\n", + " results = fz.fzr(\n", + " input_path=\"MCNP/godiva.inp\",\n", + " input_variables=input_variables,\n", + " model=\"MCNP\",\n", + " calculators=\"localhost_MCNP\",\n", + " results_dir=\"results/parametric_study\"\n", + " )\n", + " \n", + " # Display results\n", + " print(\"\\nResults:\")\n", + " print(\"=\" * 70)\n", + " print(results)\n", + " \n", + " # Analyze criticality\n", + " print(\"\\nCriticality Analysis:\")\n", + " print(\"=\" * 70)\n", + " for idx, row in results.iterrows():\n", + " r = row['r']\n", + " keff = row.get('mean_keff', None)\n", + " sigma = row.get('sigma_keff', None)\n", + " if keff is not None and keff != '':\n", + " try:\n", + " keff_val = float(keff)\n", + " sigma_val = float(sigma)\n", + " status = \"supercritical\" if keff_val > 1.0 else \"subcritical\" if keff_val < 1.0 else \"critical\"\n", + " print(f\" r={r:.3f} cm: k_eff = {keff_val:.4f} ± {sigma_val:.4f} ({status})\")\n", + " except:\n", + " print(f\" r={r:.3f} cm: Calculation incomplete\")\n", + " \n", + "except Exception as e:\n", + " print(f\"\\nError running parametric study: {e}\")\n", + " print(\"Note: Make sure MCNP is installed and MCNP_PATH is set correctly.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5: Visualization\n", + "\n", + "If you have results, you can visualize them using matplotlib." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "# Example visualization (using mock data if real results aren't available)\n", + "try:\n", + " # Use actual results if available\n", + " if 'results' in dir() and results is not None:\n", + " r_values = results['r'].values\n", + " keff_values = results['mean_keff'].values.astype(float)\n", + " sigma_values = results['sigma_keff'].values.astype(float)\n", + " else:\n", + " # Use mock data for demonstration\n", + " r_values = [8.5, 8.741, 9.0]\n", + " keff_values = [0.9850, 0.9995, 1.0145] # Example values\n", + " sigma_values = [0.0012, 0.0006, 0.0008]\n", + " \n", + " plt.figure(figsize=(10, 6))\n", + " plt.errorbar(r_values, keff_values, yerr=sigma_values, \n", + " fmt='o-', linewidth=2, markersize=8, capsize=5)\n", + " plt.axhline(y=1.0, color='r', linestyle='--', label='Critical (k_eff=1.0)')\n", + " plt.xlabel('Sphere Radius (cm)', fontsize=12)\n", + " plt.ylabel('k_effective', fontsize=12)\n", + " plt.title('Godiva Critical Reactor: k_eff vs Radius', fontsize=14, fontweight='bold')\n", + " plt.grid(True, alpha=0.3)\n", + " plt.legend()\n", + " plt.tight_layout()\n", + " plt.show()\n", + " \n", + "except Exception as e:\n", + " print(f\"Visualization error: {e}\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/MCNP/example_godiva.py b/examples/example_godiva.py similarity index 98% rename from examples/MCNP/example_godiva.py rename to examples/example_godiva.py index 9aad2f8..0666940 100755 --- a/examples/MCNP/example_godiva.py +++ b/examples/example_godiva.py @@ -37,7 +37,7 @@ def main(): # Check if input file exists if not os.path.exists(input_file): print(f"Error: Input file '{input_file}' not found.") - print("Please run this script from the examples/MCNP directory.") + print("Please run this script from the examples directory.") sys.exit(1) print("=" * 60) diff --git a/examples/MCNP/godiva.inp b/examples/godiva.inp similarity index 100% rename from examples/MCNP/godiva.inp rename to examples/godiva.inp diff --git a/tests/test_plugin.py b/tests/test_plugin.py index be6a189..5adcc8e 100755 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -102,8 +102,8 @@ def test_example_files(): print("Testing example files...") examples = [ - "examples/MCNP/godiva.inp", - "examples/MCNP/example_godiva.py" + "examples/godiva.inp", + "examples/example_godiva.py" ] for example_file in examples: @@ -124,7 +124,7 @@ def test_with_fz(): # Test parsing input file print(" Testing fz.fzi() on godiva.inp...", end=" ") - variables = fz.fzi("examples/MCNP/godiva.inp", "MCNP") + variables = fz.fzi("examples/godiva.inp", "MCNP") assert "r" in variables, "Variable 'r' not found in parsed input" print("✓") @@ -132,7 +132,7 @@ def test_with_fz(): print(" Testing fz.fzc() compilation...", end=" ") with tempfile.TemporaryDirectory() as tmpdir: fz.fzc( - "examples/MCNP/godiva.inp", + "examples/godiva.inp", {"r": 8.741}, "MCNP", output_dir=tmpdir From 4d2b5398af97e48576c3215c321d7fbc7d3268d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:01:16 +0000 Subject: [PATCH 4/4] Fix notebook paths to match flattened structure Co-authored-by: yannrichet-asnr <148193180+yannrichet-asnr@users.noreply.github.com> --- example_usage.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/example_usage.ipynb b/example_usage.ipynb index e627046..79acfb0 100644 --- a/example_usage.ipynb +++ b/example_usage.ipynb @@ -70,7 +70,7 @@ "\n", "# Download example files\n", "files_to_download = [\n", - " (\"MCNP/godiva.inp\", f\"{base_url}/godiva.inp\"),\n", + " (\"godiva.inp\", f\"{base_url}/godiva.inp\"),\n", "]\n", "\n", "print(\"Downloading example files...\")\n", @@ -145,7 +145,7 @@ "source": [ "# Parse the input file to find variables\n", "variables = fz.fzi(\n", - " \"MCNP/godiva.inp\",\n", + " \"godiva.inp\",\n", " \"MCNP\"\n", ")\n", "\n", @@ -171,7 +171,7 @@ "with tempfile.TemporaryDirectory() as tmpdir:\n", " # Compile input with specific value for radius\n", " fz.fzc(\n", - " \"MCNP/godiva.inp\",\n", + " \"godiva.inp\",\n", " {\"r\": 8.741}, # Critical radius\n", " \"MCNP\",\n", " output_dir=tmpdir\n", @@ -214,7 +214,7 @@ "try:\n", " # Run MCNP calculation\n", " results = fz.fzr(\n", - " input_path=\"MCNP/godiva.inp\",\n", + " input_path=\"godiva.inp\",\n", " input_variables=input_variables,\n", " model=\"MCNP\",\n", " calculators=\"localhost_MCNP\",\n", @@ -259,7 +259,7 @@ "try:\n", " # Run parametric calculation\n", " results = fz.fzr(\n", - " input_path=\"MCNP/godiva.inp\",\n", + " input_path=\"godiva.inp\",\n", " input_variables=input_variables,\n", " model=\"MCNP\",\n", " calculators=\"localhost_MCNP\",\n",