Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ jobs:
extra-packages: any::rcmdcheck
needs: check

- uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install fz Python package
run: pip install funz-fz

- name: Point reticulate at the CI Python
run: echo "RETICULATE_PYTHON=$(python3 -c 'import sys; print(sys.executable)')" >> "$GITHUB_ENV"

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
3 changes: 3 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
YEAR: 2025
ORGANIZATION: Funz
COPYRIGHT HOLDER: Funz
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
regardless of `calculators`.
* `fz_install()` gains a `packages` argument (default `"funz-fz"`) so the
latest `main` branch can be installed instead of the PyPI release.
* Fixed `fzd()`'s own `algorithm_options` example/documentation, which used
a `"key=val;key2=val2"` string that `funz-fz` has never actually accepted
(only a named list, JSON string, or path to a JSON file) — replaced with
a named list. CI never caught this because it was silently exercising the
wrong Python module (see CI fixes below).
* Restored the `LICENSE` file (the templated file R's packaging convention
requires alongside `License: BSD_3_clause + file LICENSE`), which had been
mistakenly deleted, and fixed `R-CMD-check` CI to install `funz-fz` and
point `reticulate` at it via `RETICULATE_PYTHON` — without this,
`reticulate`'s automatic environment provisioning was silently resolving
to an unrelated PyPI package literally named `fz` (not `funz-fz`).

# fz 1.1

Expand Down
37 changes: 32 additions & 5 deletions R/core-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ fzl <- function(models = "*", calculators = "*", check = FALSE) {
#' \code{model} is a function, this must be a single integer (default
#' \code{1L}), accepted for API compatibility (see "Direct function model"
#' below) — calls are always run sequentially regardless of its value.
#' @param algorithm_options Algorithm options as a named list or
#' semicolon-separated string, e.g. \code{"batch_sample_size=10;seed=42"}.
#' Default \code{NULL}.
#' @param algorithm_options Algorithm options as a named list, a JSON string,
#' or a path to a JSON file. Default \code{NULL}.
#' @param analysis_dir Analysis directory. Default \code{"analysis"}.
#'
#' @section Direct function model:
Expand Down Expand Up @@ -253,13 +252,41 @@ fzl <- function(models = "*", calculators = "*", check = FALSE) {
#' output = list(z = "grep z output.txt | cut -d= -f2")
#' )
#'
#' # A minimal self-contained random-sampling algorithm (see
#' # https://github.com/Funz/fz for ready-made algorithms to install)
#' algo <- tempfile(fileext = ".py")
#' writeLines(c(
#' "import random",
#' "class RandomSampler:",
#' " def __init__(self, **options):",
#' " self.batch = int(options.get('batch_sample_size', 5))",
#' " self.max_iterations = int(options.get('max_iterations', 3))",
#' " self.iteration = 0",
#' " self.input_vars = {}",
#' " def get_initial_design(self, input_vars, output_vars):",
#' " self.input_vars = input_vars",
#' " self.iteration = 1",
#' " return [{k: random.uniform(*v) for k, v in input_vars.items()}",
#' " for _ in range(self.batch)]",
#' " def get_next_design(self, previous_input_vars, previous_output_values):",
#' " self.iteration += 1",
#' " if self.iteration > self.max_iterations:",
#' " return []",
#' " return [{k: random.uniform(*v) for k, v in self.input_vars.items()}",
#' " for _ in range(self.batch)]",
#' " def get_analysis(self, input_vars, output_values):",
#' " valid = [v for v in output_values if v is not None]",
#' " mean = sum(valid) / len(valid) if valid else None",
#' " return {'text': f'mean={mean}', 'data': {'mean': mean}}"
#' ), algo)
#'
#' result <- fzd(
#' tf,
#' list(x = "[0;1]", y = "[-5;5]"),
#' model,
#' output_expression = "z",
#' algorithm = "algorithms/montecarlo_uniform.py",
#' algorithm_options = "batch_sample_size=10;max_iterations=3"
#' algorithm = algo,
#' algorithm_options = list(batch_sample_size = 10, max_iterations = 3)
#' )
#' }
#' }
Expand Down
24 changes: 12 additions & 12 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ fz_available <- function() {
#' @export
#'
#' @examples
#' \donttest{
#' if (fz_available()) {
#' install_model("Funz/Model-PerfectGas")
#' }
#' \dontrun{
#' # Requires the named GitHub repository to exist and network access;
#' # not run automatically since neither is guaranteed in all environments.
#' install_model("Funz/Model-PerfectGas")
#' }
install_model <- function(source, global = FALSE) {
fz_module <- get_fz()
Expand All @@ -97,10 +97,10 @@ install_model <- function(source, global = FALSE) {
#' @export
#'
#' @examples
#' \donttest{
#' if (fz_available()) {
#' install_algorithm("Funz/Algorithm-MonteCarlo")
#' }
#' \dontrun{
#' # Requires the named GitHub repository to exist and network access;
#' # not run automatically since neither is guaranteed in all environments.
#' install_algorithm("Funz/Algorithm-MonteCarlo")
#' }
install_algorithm <- function(source, global = FALSE) {
fz_module <- get_fz()
Expand Down Expand Up @@ -219,10 +219,10 @@ list_models <- function(global = FALSE) {
#' @export
#'
#' @examples
#' \donttest{
#' if (fz_available()) {
#' install("Funz/Model-PerfectGas")
#' }
#' \dontrun{
#' # Requires the named GitHub repository to exist and network access;
#' # not run automatically since neither is guaranteed in all environments.
#' install("Funz/Model-PerfectGas")
#' }
install <- function(source, global = FALSE) {
install_model(source, global)
Expand Down
2 changes: 1 addition & 1 deletion inst/doc/modelica-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ knitr::opts_chunk$set(
# model,
# output_expression = "pressure",
# algorithm = "algorithms/montecarlo_uniform.py",
# algorithm_options = "batch_sample_size=10;max_iterations=5;seed=42"
# algorithm_options = list(batch_sample_size = 10, max_iterations = 5, seed = 42)
# )

## ----fzl----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion inst/doc/modelica-examples.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ result <- fzd(
model,
output_expression = "pressure",
algorithm = "algorithms/montecarlo_uniform.py",
algorithm_options = "batch_sample_size=10;max_iterations=5;seed=42"
algorithm_options = list(batch_sample_size = 10, max_iterations = 5, seed = 42)
)
```

Expand Down
2 changes: 1 addition & 1 deletion inst/doc/modelica-examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ <h2>Algorithm-driven design of experiments</h2>
<span id="cb11-4"><a href="#cb11-4" tabindex="-1"></a> model,</span>
<span id="cb11-5"><a href="#cb11-5" tabindex="-1"></a> <span class="at">output_expression =</span> <span class="st">&quot;pressure&quot;</span>,</span>
<span id="cb11-6"><a href="#cb11-6" tabindex="-1"></a> <span class="at">algorithm =</span> <span class="st">&quot;algorithms/montecarlo_uniform.py&quot;</span>,</span>
<span id="cb11-7"><a href="#cb11-7" tabindex="-1"></a> <span class="at">algorithm_options =</span> <span class="st">&quot;batch_sample_size=10;max_iterations=5;seed=42&quot;</span></span>
<span id="cb11-7"><a href="#cb11-7" tabindex="-1"></a> <span class="at">algorithm_options =</span> <span class="fu">list</span>(<span class="at">batch_sample_size =</span> <span class="dv">10</span>, <span class="at">max_iterations =</span> <span class="dv">5</span>, <span class="at">seed =</span> <span class="dv">42</span>)</span>
<span id="cb11-8"><a href="#cb11-8" tabindex="-1"></a>)</span></code></pre></div>
<p>/home/richet/Sync/Open/Funz/github/fz.R/vignettes/modelica-examples.R</p>
<p>Algorithms are Python files; <code>fz</code> ships several in
Expand Down
37 changes: 32 additions & 5 deletions man/fzd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/install.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/install_algorithm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/install_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/modelica-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ knitr::opts_chunk$set(
# model,
# output_expression = "pressure",
# algorithm = "algorithms/montecarlo_uniform.py",
# algorithm_options = "batch_sample_size=10;max_iterations=5;seed=42"
# algorithm_options = list(batch_sample_size = 10, max_iterations = 5, seed = 42)
# )

## ----fzl----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion vignettes/modelica-examples.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ result <- fzd(
model,
output_expression = "pressure",
algorithm = "algorithms/montecarlo_uniform.py",
algorithm_options = "batch_sample_size=10;max_iterations=5;seed=42"
algorithm_options = list(batch_sample_size = 10, max_iterations = 5, seed = 42)
)
```

Expand Down
Loading