Skip to content

R package fz wrapper — full implementation up to v1.1#1

Merged
yannrichet-asnr merged 13 commits into
mainfrom
claude/r-package-fz-wrapper-0137pbLvie79Ppp1NejzNyah
Jun 17, 2026
Merged

R package fz wrapper — full implementation up to v1.1#1
yannrichet-asnr merged 13 commits into
mainfrom
claude/r-package-fz-wrapper-0137pbLvie79Ppp1NejzNyah

Conversation

@yannrichet-asnr

Copy link
Copy Markdown
Member

Summary

  • Implements an R package wrapping the fz Python CLI (Funz), providing fzi(), fzc(), fzo(), fzr(), fzl(), and fzd() functions
  • Aligns API and version (1.1) with the funz-fz Python release
  • Includes vignette, tests, NEWS.md, and CRAN-submission prep (BSD-3-Clause license, ORCID, spelling wordlist)

Test plan

  • R CMD check passes locally
  • Vignette renders without errors
  • fzi() / fzc() / fzo() / fzr() / fzl() / fzd() all return expected output against a sample model

🤖 Generated with Claude Code

claude and others added 13 commits November 22, 2025 22:06
Implemented R wrapper functions for the five main fz Python functions:
- fz(): Main fz function
- fzi(): fzi function
- fzc(): fzc function
- fzo(): fzo function
- fzd(): fzd function

Changes:
- Added R/core-functions.R with wrapper implementations
- Updated NAMESPACE to export new functions
- Added comprehensive tests in tests/testthat/test-core-functions.R
- Updated README.md with usage examples for core functions
- Updated NEWS.md to document new functionality

All wrapper functions use the get_fz() helper for delayed module loading
and pass all arguments through to their Python counterparts using ...,
maintaining API compatibility with the original fz Python package.
This commit adds extensive practical examples and tests demonstrating
real-world usage of the fz package with Modelica models.

New test files:
- tests/testthat/test-modelica-examples.R: Integration tests covering:
  * Design of Experiments (DoE) workflows
  * Optimization scenarios
  * Parameter studies
  * Uncertainty quantification
  * Complete workflow examples

- tests/testthat/helper-modelica.R: Test helpers including:
  * Mock model configurations (bouncing ball, spring-mass-damper, heat exchanger)
  * DoE and optimization configuration builders
  * Result validation utilities
  * Example model descriptions with inputs, outputs, and ranges

New vignette:
- vignettes/modelica-examples.Rmd: Comprehensive tutorial covering:
  * Basic workflow (initialize, configure, execute, analyze)
  * Bouncing ball DoE example
  * Spring-mass-damper optimization example
  * Heat exchanger parameter study
  * Uncertainty quantification examples
  * Advanced usage (custom algorithms, parallel execution)
  * Best practices and troubleshooting

Documentation updates:
- README.md: Added practical examples section with code snippets
- NEWS.md: Documented new test suite and vignette features

These examples mirror common use cases from the Python fz package and
provide R users with clear templates for applying fz to their Modelica
models for design space exploration, optimization, and uncertainty analysis.
This commit updates the test suite to use actual Modelica model files
and demonstrates realistic usage patterns matching the Python fz package.

New Modelica Models (tests/testthat/models/):
- BouncingBall.mo: Simple physics simulation with gravity and bouncing
  * Inputs: h0 (height), v0 (velocity), e (restitution)
  * Outputs: h_max, t_ground, bounces

- SpringMassDamper.mo: Oscillator system for optimization examples
  * Inputs: m (mass), k (stiffness), c (damping), F0 (force)
  * Outputs: x_max, settling_time, overshoot

- Branin.mo: Standard optimization benchmark function
  * Inputs: x1, x2
  * Output: y (objective value, global minimum ≈ 0.397887)

Updated Tests (test-modelica-examples.R):
All tests now use actual Modelica files with realistic examples:

1. BouncingBall DoE: Latin Hypercube sampling (n=20)
   - Python equivalent: fz.Run(model='BouncingBall.mo', ...)
   - Tests input/output ranges and result structure

2. Branin Optimization: Minimize benchmark function
   - Python equivalent: fz.RunOptimization(...)
   - Tests gradient descent with known optimal solution

3. BouncingBall Parameter Sweep: Full factorial design (6 runs)
   - Tests discrete parameter combinations
   - Validates physical expectations in results

4. SpringMassDamper Multi-objective: Pareto optimization
   - Minimize settling_time AND overshoot
   - Tests NSGA2 algorithm for trade-off analysis

5. Complete Workflow: Step-by-step fzi → fzc → fzd
   - Demonstrates project initialization and configuration
   - Mirrors typical Python fz usage pattern

6. DoE Design Comparison: Random, LHS, Sobol, Full Factorial
   - Tests different sampling strategies
   - Compares space-filling properties

7. Result Format Validation: Checks data.frame structure
   - Validates column names (inputs + outputs)
   - Ensures compatibility with Python fz results

8. Model File Validation: Verifies Modelica syntax
   - Checks files exist and contain valid model declarations

Each test includes:
- Python fz equivalent command in comments
- Expected result structure based on Python fz behavior
- Physical/mathematical validation where applicable
- Graceful failure handling when fz not configured

These examples provide users with concrete templates for:
- Design of experiments workflows
- Optimization problem setup
- Result interpretation and validation
Corrected the API usage in tests and vignettes - the fzo() function
(optimization) does not accept an 'algorithm' parameter. Only fzd()
(design of experiments) accepts the 'design' parameter to specify
the sampling/design algorithm.

Changes:
- tests/testthat/test-modelica-examples.R:
  * Removed algorithm="GradientDescent" from Branin optimization test
  * Removed algorithm="NSGA2" from SpringMassDamper multi-objective test
  * Added clarifying comments that fzo does not take algorithm parameter

- vignettes/modelica-examples.Rmd:
  * Removed incorrect "Optimization Algorithms" section showing fzo with algorithm
  * Kept "Custom Design Algorithms" section showing correct fzd usage
  * Removed duplicate content

Correct API usage:
- fzo(objective, objective_var, ...) - optimization, no algorithm param
- fzd(design, n, ...) - design of experiments, takes design parameter
- Fix PyPI package name: "fz" → "funz-fz" in DESCRIPTION and install.R
- Remove broken fz() wrapper (no such function in Python module)
- Add fzr(), fzl() wrappers; give all core functions explicit typed signatures
- Add install_model/algorithm, uninstall_model/algorithm, list_installed_models/algorithms,
  list_models, install, uninstall aliases (R/install.R)
- Add R/config.R: get/set_interpreter, get/set_log_level, get/print/reload_config
- Update NAMESPACE exports accordingly
- Rewrite tests to use correct file-based stateless API with temp files
- Rewrite README and vignette: fix all wrong fzi/fzc/fzo/fzd call signatures,
  remove non-existent fz() usage, document real workflow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add .claude to .Rbuildignore so it is excluded from the build tarball
- Replace full MIT text in LICENSE with the DCF stub (YEAR/COPYRIGHT HOLDER)
  required by "MIT + file LICENSE"; full text is already in LICENSE.md
- Remove deprecated @doctype package block from fz-package.R; the "_PACKAGE"
  sentinel on line 2 already registers the package documentation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
DESCRIPTION:
- Fill in real author name and email
- Expand Title and Description to meet CRAN standards
- Remove LazyData (no data in package)
- Add SystemRequirements: Python (>= 3.8), funz-fz
- Add Language: en-US

Spelling:
- Fix optimisation → optimization, optimises → optimizes (en-US)
- Add inst/WORDLIST for technical terms (fzc, fzd, conda, Modelica, …)

Admin:
- Add cran-comments.md explaining residual qpdf warning
- Add cran-comments.md to .Rbuildignore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- skip_on_cran() on all Python-dependent tests; CRAN machines skip them entirely
- tests/testthat/setup.R: set FZ_MAX_RETRIES=1 before Python import to cut
  retry overhead on test machines that have fz installed
- Tests restructured to avoid redundancy between test-core-functions and
  test-modelica-examples (fzr/fzc/fzi tests consolidated)
- man/fz-package.Rd: add ORCID link

Reduces local check duration from ~2 min to ~50 s.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yannrichet-asnr yannrichet-asnr merged commit 1cd18e5 into main Jun 17, 2026
9 checks passed
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.

3 participants