Skip to content

Commit

Permalink
Merge pull request #73 from SymbolicML/expression-type
Browse files Browse the repository at this point in the history
feat: create `Expression` type to store operators with expression and `parse_expression` to have robust parsing
  • Loading branch information
MilesCranmer committed Jun 4, 2024
2 parents fda4a4a + 703058e commit a55f966
Show file tree
Hide file tree
Showing 24 changed files with 2,052 additions and 113 deletions.
16 changes: 1 addition & 15 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DynamicExpressions"
uuid = "a40a106e-89c9-4ca8-8020-a735e8728b6b"
authors = ["MilesCranmer <miles.cranmer@gmail.com>"]
version = "0.17.0"
version = "0.18.0-alpha"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -28,11 +28,9 @@ DynamicExpressionsSymbolicUtilsExt = "SymbolicUtils"
DynamicExpressionsZygoteExt = "Zygote"

[compat]
Aqua = "0.7"
Bumper = "0.6"
ChainRulesCore = "1"
Compat = "3.37, 4"
Enzyme = "^0.11.12"
LoopVectorization = "0.12"
MacroTools = "0.4, 0.5"
Optim = "0.19, 1"
Expand All @@ -44,20 +42,8 @@ Zygote = "0.6"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Bumper = "8ce10254-0962-460f-a3d8-1f77fea1446e"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Test", "SafeTestsets", "Aqua", "Bumper", "Enzyme", "ForwardDiff", "LinearAlgebra", "LoopVectorization", "Optim", "SpecialFunctions", "StaticArrays", "Suppressor", "SymbolicUtils", "Zygote"]
32 changes: 28 additions & 4 deletions src/DynamicExpressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ include("EvaluationHelpers.jl")
include("Simplify.jl")
include("OperatorEnumConstruction.jl")
include("Random.jl")
include("Expression.jl")
include("Parse.jl")

import PackageExtensionCompat: @require_extensions
import Reexport: @reexport
Expand All @@ -26,7 +28,16 @@ import Reexport: @reexport
tree_mapreduce,
filter_map,
filter_map!
import .NodeModule: constructorof, preserve_sharing
import .NodeModule:
constructorof,
with_type_parameters,
preserve_sharing,
leaf_copy,
branch_copy,
leaf_hash,
branch_hash,
leaf_equal,
branch_equal
@reexport import .NodeUtilsModule:
count_nodes,
count_constants,
Expand All @@ -48,6 +59,11 @@ import .NodeModule: constructorof, preserve_sharing
@reexport import .EvaluationHelpersModule
@reexport import .ExtensionInterfaceModule: node_to_symbolic, symbolic_to_node
@reexport import .RandomModule: NodeSampler
@reexport import .ExpressionModule: AbstractExpression, Expression
# Not for export; just for overloading
import .ExpressionModule: get_tree, get_operators, get_variable_names, Metadata
@reexport import .ParseModule: @parse_expression, parse_expression
import .ParseModule: parse_leaf

function __init__()
@require_extensions
Expand All @@ -57,9 +73,17 @@ include("deprecated.jl")

import TOML: parsefile

const PACKAGE_VERSION = let
project = parsefile(joinpath(pkgdir(@__MODULE__), "Project.toml"))
VersionNumber(project["version"])
const PACKAGE_VERSION = let d = pkgdir(@__MODULE__)
try
if d isa String
project = parsefile(joinpath(d, "Project.toml"))
VersionNumber(project["version"])
else
v"0.0.0"
end
catch
v"0.0.0"
end
end

macro ignore(args...) end
Expand Down
4 changes: 3 additions & 1 deletion src/EvaluateDerivative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ end
end
end
deg2_branch = if nbin > OPERATOR_LIMIT_BEFORE_SLOWDOWN
diff_deg2_eval(tree, cX, operators.binops[op_idx], operators, direction)
quote
diff_deg2_eval(tree, cX, operators.binops[op_idx], operators, direction)
end
else
quote
Base.Cartesian.@nif(
Expand Down
Loading

0 comments on commit a55f966

Please sign in to comment.