Skip to content

Commit

Permalink
Merge pull request #382 from MilesCranmer/allow-other-stdin
Browse files Browse the repository at this point in the history
feat: allow user-specified `stdin`
  • Loading branch information
MilesCranmer authored Dec 9, 2024
2 parents b415686 + 4da6aa3 commit 1fc4611
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -926,6 +929,7 @@ $(OPTION_DESCRIPTIONS)
Val(deprecated_return_state),
timeout_in_seconds,
max_evals,
input_stream,
skip_mutation_failures,
_nested_constraints,
deterministic,
Expand Down
1 change: 1 addition & 0 deletions src/OptionsStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ struct Options{
return_state::Val{_return_state}
timeout_in_seconds::Union{Float64,Nothing}
max_evals::Union{Int,Nothing}
input_stream::IO
skip_mutation_failures::Bool
nested_constraints::Union{Vector{Tuple{Int,Int,Vector{Tuple{Int,Int,Int}}}},Nothing}
deterministic::Bool
Expand Down
2 changes: 1 addition & 1 deletion src/SymbolicRegression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit 1fc4611

Please sign in to comment.