feat: support direct R function models in fzd()#3
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fzd()now accepts an R function asmodel, letting adaptive design-of-experiments algorithms drive an R function directly instead of a file-based model (input_path = NULL,output_expressionoptional,calculatorsaccepted for API compatibility but currently without effect — see below).fz_install()gains apackagesargument (default"funz-fz") so the latestmainbranch offzcan 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 PythonThreadPoolExecutor, which always runs tasks in a worker thread — even with a single worker — and crashed the R session. #73 makesfzalways call function models sequentially, one call at a time in the calling thread, regardless ofcalculators.fzd()here now warns ifcalculators != 1Lis passed with an R functionmodel, since it has no effect on execution.Test plan
devtools::test()— full suite passes (2 pre-existing, unrelated failures intest-modelica-examples.R, present before this change too — environment-specificsh://calculator issue)fzmain + fix: run fzd function-model calls sequentially, never via a thread pool fz#73: an R closure (rosenbrock) passed asmodeltofzd()runs correctly withcalculators = NULL,1L, and4Lcalculators = 4Lwith an R function model emits the expected warning and no warning is emitted forcalculators = NULL/1L🤖 Generated with Claude Code