Skip to content

Commit

Permalink
Merge branch 'master' into dynamic-autodiff
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer authored Dec 13, 2024
2 parents bfa0a72 + 701889f commit 5fd91a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ DifferentiationInterface = "0.5, 0.6"
DispatchDoctor = "^0.4.17"
Distributed = "<0.0.1, 1"
DynamicDiff = "0.2"
DynamicExpressions = "1.6.0"
DynamicExpressions = "~1.8"
DynamicQuantities = "1"
Enzyme = "0.12, 0.13"
JSON3 = "1"
Expand Down
9 changes: 9 additions & 0 deletions src/ComposableExpression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ end
function CO.count_constants_for_optimization(ex::AbstractComposableExpression)
return CO.count_constants_for_optimization(convert(Expression, ex))
end
function DE.allocate_container(
prototype::ComposableExpression, n::Union{Nothing,Integer}=nothing
)
return (; tree=DE.allocate_container(get_contents(prototype), n))
end
function DE.copy_into!(dest::NamedTuple, src::ComposableExpression)
new_tree = DE.copy_into!(dest.tree, get_contents(src))
return DE.with_contents(src, new_tree)
end

@implements(
ExpressionInterface{all_ei_methods_except(())}, ComposableExpression, [Arguments()]
Expand Down
13 changes: 8 additions & 5 deletions src/Mutate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module MutateModule

using DynamicExpressions:
AbstractExpression,
copy_into!,
get_tree,
preserve_sharing,
count_scalar_constants,
simplify_tree!,
combine_operators
combine_operators,
allocate_container
using ..CoreModule:
AbstractOptions,
AbstractMutationWeights,
Expand Down Expand Up @@ -187,13 +189,14 @@ function next_generation(
successful_mutation = false
attempts = 0
max_attempts = 10
node_storage = allocate_container(member.tree)

#############################################
# Mutations
#############################################
local tree
while (!successful_mutation) && attempts < max_attempts
tree = copy(member.tree)
tree = copy_into!(node_storage, member.tree)

mutation_result = _dispatch_mutations!(
tree,
Expand Down Expand Up @@ -238,7 +241,7 @@ function next_generation(
mutation_accepted = false
return (
PopMember(
copy(member.tree),
copy_into!(node_storage, member.tree),
beforeScore,
beforeLoss,
options,
Expand Down Expand Up @@ -267,7 +270,7 @@ function next_generation(
mutation_accepted = false
return (
PopMember(
copy(member.tree),
copy_into!(node_storage, member.tree),
beforeScore,
beforeLoss,
options,
Expand Down Expand Up @@ -310,7 +313,7 @@ function next_generation(
mutation_accepted = false
return (
PopMember(
copy(member.tree),
copy_into!(node_storage, member.tree),
beforeScore,
beforeLoss,
options,
Expand Down

0 comments on commit 5fd91a6

Please sign in to comment.