Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: widen type constraints for TemplateExpression evaluation #371

Merged
merged 2 commits into from
Nov 24, 2024
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymbolicRegression"
uuid = "8254be44-1295-4e6a-a16d-46603ac705cb"
authors = ["MilesCranmer <[email protected]>"]
version = "1.0.1"
version = "1.0.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
6 changes: 3 additions & 3 deletions src/TemplateExpression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ end
default_union_limit = 2,
begin
function DE.eval_tree_array(
tree::TemplateExpression{T},
cX::AbstractMatrix{T},
tree::TemplateExpression,
cX::AbstractMatrix,
operators::Union{AbstractOperatorEnum,Nothing}=nothing;
kws...,
) where {T}
)
raw_contents = get_contents(tree)
if has_invalid_variables(tree)
return (nothing, false)
Expand Down
57 changes: 28 additions & 29 deletions test/test_logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,40 @@

include("test_params.jl")

mktempdir() do dir
buf = IOBuffer()
simple_logger = SimpleLogger(buf)
tb_logger = TBLogger(dir, TensorBoardLogger.tb_overwrite)
dir = mktempdir()
buf = IOBuffer()
simple_logger = SimpleLogger(buf)
tb_logger = TBLogger(dir, TensorBoardLogger.tb_overwrite)

logger = SRLogger(; logger=TeeLogger(simple_logger, tb_logger), log_interval=2)
logger = SRLogger(; logger=TeeLogger(simple_logger, tb_logger), log_interval=2)

niterations = 4
populations = 36
model = SRRegressor(;
binary_operators=[+, -, *, mod],
unary_operators=[],
maxsize=40,
niterations,
populations,
logger,
)
niterations = 4
populations = 36
model = SRRegressor(;
binary_operators=[+, -, *, mod],
unary_operators=[],
maxsize=40,
niterations,
populations,
logger,
)

X = (a=rand(500), b=rand(500))
y = @. 2 * cos(X.a * 23.5) - X.b^2
mach = machine(model, X, y)
X = (a=rand(500), b=rand(500))
y = @. 2 * cos(X.a * 23.5) - X.b^2
mach = machine(model, X, y)

fit!(mach)
fit!(mach)

# Check TensorBoardLogger
b = TensorBoardLogger.steps(tb_logger)
@test length(b) == (niterations * populations//2) + 1
files_and_dirs = readdir(dir)
@test length(files_and_dirs) == 1
@test occursin(r"events\.out\.tfevents", only(files_and_dirs))
# Check TensorBoardLogger
b = TensorBoardLogger.steps(tb_logger)
@test length(b) == (niterations * populations//2) + 1
files_and_dirs = readdir(dir)
@test length(files_and_dirs) == 1
@test occursin(r"events\.out\.tfevents", only(files_and_dirs))

# Check SimpleLogger
s = String(take!(buf))
@test occursin(r"search\s*\n\s*│\s*data\s*=\s*", s)
end
# Check SimpleLogger
s = String(take!(buf))
@test occursin(r"search\s*\n\s*│\s*data\s*=\s*", s)
end
@testitem "Test convex hull calculation" tags = [:part1] begin
using SymbolicRegression.LoggingModule: convex_hull, convex_hull_area
Expand Down
Loading