From 457c9cc8ec3506beff38c871b5de4e98b9735cfe Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Mon, 9 Dec 2024 02:10:27 +0000 Subject: [PATCH 1/2] feat: allow user-specified `stdin` --- src/Options.jl | 5 +++++ src/OptionsStruct.jl | 2 ++ src/SymbolicRegression.jl | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Options.jl b/src/Options.jl index eeb4cdee0..c87fb805a 100644 --- a/src/Options.jl +++ b/src/Options.jl @@ -419,6 +419,8 @@ const OPTION_DESCRIPTIONS = """- `defaults`: What set of defaults to use for `Op Function - a function taking (loss, complexity) as arguments and returning true or false. - `timeout_in_seconds`: Float64 - the time in seconds after which to exit (as an alternative to the number of iterations). - `max_evals`: Int (or Nothing) - the maximum number of evaluations of expressions to perform. +- `input_stream`: the stream to read user input from. By default, this is `stdin`. If you encounter issues + with reading from `stdin`, like a hang, you can simply pass `devnull` to this argument. - `skip_mutation_failures`: Whether to simply skip over mutations that fail or are rejected, rather than to replace the mutated expression with the original expression and proceed normally. - `nested_constraints`: Specifies how many times a combination of operators can be nested. For example, @@ -574,6 +576,7 @@ $(OPTION_DESCRIPTIONS) ## 10. Stopping Criteria: timeout_in_seconds::Union{Nothing,Real}=nothing, max_evals::Union{Nothing,Integer}=nothing, + input_stream::IO=stdin, ## 11. Performance and Parallelization: turbo::Bool=false, bumper::Bool=false, @@ -865,6 +868,7 @@ $(OPTION_DESCRIPTIONS) deprecated_return_state::Union{Bool,Nothing}, typeof(_autodiff_backend), print_precision, + typeof(input_stream), }( operators, _bin_constraints, @@ -926,6 +930,7 @@ $(OPTION_DESCRIPTIONS) Val(deprecated_return_state), timeout_in_seconds, max_evals, + input_stream, skip_mutation_failures, _nested_constraints, deterministic, diff --git a/src/OptionsStruct.jl b/src/OptionsStruct.jl index 22871606d..e0fcfa868 100644 --- a/src/OptionsStruct.jl +++ b/src/OptionsStruct.jl @@ -189,6 +189,7 @@ struct Options{ _return_state, AD, print_precision, + ST, } <: AbstractOptions operators::OP bin_constraints::Vector{Tuple{Int,Int}} @@ -250,6 +251,7 @@ struct Options{ return_state::Val{_return_state} timeout_in_seconds::Union{Float64,Nothing} max_evals::Union{Int,Nothing} + input_stream::ST skip_mutation_failures::Bool nested_constraints::Union{Vector{Tuple{Int,Int,Vector{Tuple{Int,Int,Int}}}},Nothing} deterministic::Bool diff --git a/src/SymbolicRegression.jl b/src/SymbolicRegression.jl index b7b2e2deb..72363276f 100644 --- a/src/SymbolicRegression.jl +++ b/src/SymbolicRegression.jl @@ -578,7 +578,7 @@ end @stable default_mode = "disable" function _create_workers( datasets::Vector{D}, ropt::AbstractRuntimeOptions, options::AbstractOptions ) where {T,L,D<:Dataset{T,L}} - stdin_reader = watch_stream(stdin) + stdin_reader = watch_stream(options.input_stream) record = RecordType() @recorder record["options"] = "$(options)" From 4da6aa3163771a4369e5c4d3997e2868027368ac Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Mon, 9 Dec 2024 02:13:29 +0000 Subject: [PATCH 2/2] refactor: remove specialization on input stream --- src/Options.jl | 1 - src/OptionsStruct.jl | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Options.jl b/src/Options.jl index c87fb805a..d7fc61cf8 100644 --- a/src/Options.jl +++ b/src/Options.jl @@ -868,7 +868,6 @@ $(OPTION_DESCRIPTIONS) deprecated_return_state::Union{Bool,Nothing}, typeof(_autodiff_backend), print_precision, - typeof(input_stream), }( operators, _bin_constraints, diff --git a/src/OptionsStruct.jl b/src/OptionsStruct.jl index e0fcfa868..169b30574 100644 --- a/src/OptionsStruct.jl +++ b/src/OptionsStruct.jl @@ -189,7 +189,6 @@ struct Options{ _return_state, AD, print_precision, - ST, } <: AbstractOptions operators::OP bin_constraints::Vector{Tuple{Int,Int}} @@ -251,7 +250,7 @@ struct Options{ return_state::Val{_return_state} timeout_in_seconds::Union{Float64,Nothing} max_evals::Union{Int,Nothing} - input_stream::ST + input_stream::IO skip_mutation_failures::Bool nested_constraints::Union{Vector{Tuple{Int,Int,Vector{Tuple{Int,Int,Int}}}},Nothing} deterministic::Bool