Skip to content

feat: support direct R function models in fzd()#3

Merged
yannrichet-asnr merged 1 commit into
mainfrom
feat/fzd-function-model
Jul 12, 2026
Merged

feat: support direct R function models in fzd()#3
yannrichet-asnr merged 1 commit into
mainfrom
feat/fzd-function-model

Conversation

@yannrichet-asnr

Copy link
Copy Markdown
Member

Summary

  • fzd() now accepts an R function as model, letting adaptive design-of-experiments algorithms drive an R function directly instead of a file-based model (input_path = NULL, output_expression optional, calculators accepted for API compatibility but currently without effect — see below).
  • fz_install() gains a packages argument (default "funz-fz") so the latest main branch of fz can be installed from GitHub instead of the PyPI release: fz_install(packages = "git+https://github.com/Funz/fz.git").

This requires Funz/fz#73 (not yet merged/released to PyPI): R closures are bridged into Python via reticulate, which is only safe to call from the main thread. fz's function-model support originally dispatched calls through a Python ThreadPoolExecutor, which always runs tasks in a worker thread — even with a single worker — and crashed the R session. #73 makes fz always call function models sequentially, one call at a time in the calling thread, regardless of calculators. fzd() here now warns if calculators != 1L is passed with an R function model, since it has no effect on execution.

Test plan

  • devtools::test() — full suite passes (2 pre-existing, unrelated failures in test-modelica-examples.R, present before this change too — environment-specific sh:// calculator issue)
  • Verified end-to-end against a local build of fz main + fix: run fzd function-model calls sequentially, never via a thread pool fz#73: an R closure (rosenbrock) passed as model to fzd() runs correctly with calculators = NULL, 1L, and 4L
  • Verified calculators = 4L with an R function model emits the expected warning and no warning is emitted for calculators = NULL/1L

🤖 Generated with Claude Code

fzd() now accepts an R function as model, letting adaptive
design-of-experiments algorithms drive an R function directly instead of
a file-based model. In this mode input_path must be NULL, output_expression
is optional (defaults to the function's first output), and calculators is
accepted for API compatibility but has no effect: fz always evaluates
function models sequentially, one call at a time in the calling thread,
since R closures bridged in via reticulate are only safe to call from the
main thread. Passing calculators != 1L now warns that it has no effect.

Requires the fz main branch on GitHub (fz_install(packages =
"git+https://github.com/Funz/fz.git")) and Funz/fz#73, which makes fz's
function-model support call sequentially instead of via a Python thread
pool (even a single-worker pool always dispatches to a worker thread, never
the calling thread, which crashed the R session).

fz_install() gains a packages argument (default "funz-fz") to select the
install source, enabling the GitHub main branch as an alternative to PyPI.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@yannrichet-asnr
yannrichet-asnr merged commit 17de482 into main Jul 12, 2026
3 of 5 checks passed
@yannrichet-asnr
yannrichet-asnr deleted the feat/fzd-function-model branch July 12, 2026 13:13
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