|
28 | 28 |
|
29 | 29 | Base.eltype(::ComplexityMapping{T}) where {T} = T |
30 | 30 |
|
| 31 | +function Base.:(==)(a::ComplexityMapping, b::ComplexityMapping) |
| 32 | + return a.use == b.use && |
| 33 | + a.op_complexities == b.op_complexities && |
| 34 | + a.variable_complexity == b.variable_complexity && |
| 35 | + a.constant_complexity == b.constant_complexity |
| 36 | +end |
| 37 | + |
31 | 38 | """Promote type when defining complexity mapping.""" |
32 | 39 | function ComplexityMapping(; |
33 | 40 | op_complexities::Tuple{Vararg{Vector,D}}, |
@@ -182,6 +189,7 @@ struct Options{ |
182 | 189 | } <: AbstractOptions |
183 | 190 | operators::OP |
184 | 191 | op_constraints::OP_CONSTRAINTS |
| 192 | + nested_constraints::Union{Vector{Tuple{Int,Int,Vector{Tuple{Int,Int,Int}}}},Nothing} |
185 | 193 | complexity_mapping::CM |
186 | 194 | tournament_selection_n::Int |
187 | 195 | tournament_selection_p::Float32 |
@@ -243,7 +251,6 @@ struct Options{ |
243 | 251 | max_evals::Union{Int,Nothing} |
244 | 252 | input_stream::IO |
245 | 253 | skip_mutation_failures::Bool |
246 | | - nested_constraints::Union{Vector{Tuple{Int,Int,Vector{Tuple{Int,Int,Int}}}},Nothing} |
247 | 254 | deterministic::Bool |
248 | 255 | define_helper_functions::Bool |
249 | 256 | use_recorder::Bool |
|
290 | 297 | end |
291 | 298 | end |
292 | 299 |
|
| 300 | +struct WarmStartIncompatibleError <: Exception |
| 301 | + fields::Vector{Symbol} |
| 302 | +end |
| 303 | + |
| 304 | +function Base.showerror(io::IO, e::WarmStartIncompatibleError) |
| 305 | + print(io, "Warm start incompatible due to changed field(s): ") |
| 306 | + join(io, e.fields, ", ") |
| 307 | + return print(io, ". Use `fit!(mach, force=true)` to restart training.") |
| 308 | +end |
| 309 | + |
| 310 | +check_warm_start_compatibility(::AbstractOptions, ::AbstractOptions) = nothing # LCOV_EXCL_LINE |
| 311 | + |
| 312 | +function check_warm_start_compatibility(old_options::Options, new_options::Options) |
| 313 | + incompatible_fields = ( |
| 314 | + :operators, |
| 315 | + :op_constraints, |
| 316 | + :nested_constraints, |
| 317 | + :complexity_mapping, |
| 318 | + :dimensionless_constants_only, |
| 319 | + :maxsize, |
| 320 | + :maxdepth, |
| 321 | + :populations, |
| 322 | + :population_size, |
| 323 | + :node_type, |
| 324 | + :expression_type, |
| 325 | + :expression_options, |
| 326 | + ) |
| 327 | + |
| 328 | + changed = [ |
| 329 | + f for f in incompatible_fields if |
| 330 | + getproperty(old_options, f) != getproperty(new_options, f) |
| 331 | + ] |
| 332 | + isempty(changed) || throw(WarmStartIncompatibleError(changed)) |
| 333 | + return nothing |
| 334 | +end |
| 335 | + |
293 | 336 | end |
0 commit comments