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

feat: create Expression type to store operators with expression and parse_expression to have robust parsing #73

Merged
merged 77 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
c1343c2
feat: create `Expression` type and `@parse_expression` macro
MilesCranmer Apr 28, 2024
75c1fb9
test: add basic tests for expression and parsing
MilesCranmer Apr 28, 2024
bf5a33f
refactor: remove unused `display_variable_names` field
MilesCranmer Apr 28, 2024
32d2d07
docs: for `Expression` and `@parse_expression`
MilesCranmer Apr 28, 2024
44e541b
feat: make parse_expression work for tuple and vector leafs
MilesCranmer Apr 28, 2024
67bbb89
chore: bump version with new Expression type
MilesCranmer Apr 28, 2024
b04cb2d
ci: fix benchmark module import
MilesCranmer Apr 28, 2024
5df7d37
Merge branch 'master' into expression-type
MilesCranmer Apr 28, 2024
2c26032
style: use `@argcheck` for validation
MilesCranmer Apr 28, 2024
0855c1b
refactor: speed up `max_feature` when nodes are shared
MilesCranmer Apr 29, 2024
e1f938b
feat: export with_type_parameters
MilesCranmer Apr 29, 2024
51a1a93
fix: stack overflow with bad struct def
MilesCranmer Apr 29, 2024
a6716f5
fix: only validate Expression input for OperatorEnum
MilesCranmer Apr 29, 2024
48fd127
feat: allow user to pass external functions to `@parse_expression`
MilesCranmer Apr 29, 2024
13dc9fa
style: fix formatting
MilesCranmer Apr 29, 2024
4b02dd2
chore: remove debugging statement
MilesCranmer Apr 29, 2024
7b63aa0
docs: improve `@parse_expression` docs
MilesCranmer Apr 29, 2024
ac63f74
test: fix missing type in test
MilesCranmer Apr 29, 2024
3db4508
refactor: safer macro for parsing
MilesCranmer Apr 29, 2024
9b56eb2
refactor: remove redundant clear
MilesCranmer Apr 29, 2024
ac25082
refactor: simplify macro
MilesCranmer Apr 29, 2024
a67de40
refactor: ensure clean macro execution
MilesCranmer Apr 29, 2024
0479f5e
refactor: create getters for Expression type
MilesCranmer Apr 30, 2024
cfa3930
test: fix leakage of local variable
MilesCranmer May 1, 2024
e0cbced
refactor!: modify expression to allow additional features
MilesCranmer May 1, 2024
a7c8580
fix: account for parsing chained operators
MilesCranmer May 1, 2024
6d238ec
fix: implement various edge cases for Expression
MilesCranmer May 1, 2024
663333c
refactor: better error messages
MilesCranmer May 1, 2024
7e2c722
refactor: use getproperty
MilesCranmer May 1, 2024
22c3e82
refactor: remove use of argcheck
MilesCranmer May 1, 2024
0d27489
docs: additional notes on interface
MilesCranmer May 2, 2024
e45c7c8
feat: allow user to overload pieces of copy, hash, and isequal
MilesCranmer May 2, 2024
c269fab
docs: describe AbstractExpressionNode interface
MilesCranmer May 2, 2024
cfe7d2b
refactor: fix allocation in metadata copy
MilesCranmer May 2, 2024
9c26e6d
refactor: export Metadata
MilesCranmer May 2, 2024
e15b1c3
refactor: dont export Metadata
MilesCranmer May 2, 2024
3ea426a
fix: add missing `*` special behavior
MilesCranmer May 3, 2024
d6fc222
feat: allow `@parse_expression` to take arg not kwarg
MilesCranmer May 3, 2024
160b9b9
test: add implementation of multi expressions to testing
MilesCranmer May 3, 2024
9516158
refactor: safer parsing macro
MilesCranmer May 3, 2024
ecd8ed0
refactor: improve abstract interface for expressions
MilesCranmer May 3, 2024
950e95b
fix: type unstable copy
MilesCranmer May 3, 2024
9fd8265
fix: add break_sharing kw to copy
MilesCranmer May 3, 2024
8bd5b78
fix: add missing parts of interface
MilesCranmer May 3, 2024
239797a
test: more coverage
MilesCranmer May 3, 2024
c060fdd
test: add missing test_parse
MilesCranmer May 3, 2024
100c9df
ci: compat with 1.6
MilesCranmer May 3, 2024
587050b
test: improve coverage
MilesCranmer May 4, 2024
7e7adb0
docs: tweak docstring
MilesCranmer May 4, 2024
e10465c
test: more test coverage
MilesCranmer May 5, 2024
3143648
ci: add TestItems and TestItemRunner
MilesCranmer May 6, 2024
8d39a50
test: move test dependencies to test/Project.toml
MilesCranmer May 6, 2024
2d1dfb3
Revert "ci: add TestItems and TestItemRunner"
MilesCranmer May 6, 2024
74210b9
test: move back to test_parse.jl
MilesCranmer May 6, 2024
4af0e3e
test: switch to using TestItemRunner
MilesCranmer May 6, 2024
518d3ed
test: avoid redefining MultiScalarExpression
MilesCranmer May 7, 2024
08333dd
feat: add additional parts of node interface
MilesCranmer May 8, 2024
224dca4
fix: `show` for custom expressions
MilesCranmer May 8, 2024
ac7420d
feat: generalize parsing to different expression types
MilesCranmer May 8, 2024
c11ad9e
feat!: pass keywords rather than named tuple to expression
MilesCranmer May 8, 2024
cdbac2c
feat: add example of parametric expression
MilesCranmer May 8, 2024
5a8d7b2
fix: leaf_equal for parametric node test
MilesCranmer May 8, 2024
488553a
test: freezing and thawing nodes
MilesCranmer May 12, 2024
ec10651
refactor: use expression-based tree factory in multi-expression
MilesCranmer May 15, 2024
10d9e76
refactor: remove calling module from parse expression
MilesCranmer May 21, 2024
ac8e704
fix copy of nothing
MilesCranmer May 21, 2024
b06d82f
docs: clarify is experimental
MilesCranmer Jun 2, 2024
23b1bd3
feat: allow `binary_operators` passed to `parse_expression`
MilesCranmer Jun 2, 2024
a1fc807
test: add test of binary_operator direct parsing
MilesCranmer Jun 2, 2024
3453826
refactor: smaller testitem
MilesCranmer Jun 2, 2024
5d511aa
feat: allow empty operators
MilesCranmer Jun 2, 2024
ee151d6
style: formatting
MilesCranmer Jun 2, 2024
1e2f100
missing import
MilesCranmer Jun 3, 2024
25b937f
remove docs since experimental
MilesCranmer Jun 3, 2024
b70e7f7
fix: issues spotted by JET
MilesCranmer Jun 3, 2024
bc59a17
chore: bump to alpha minor version
MilesCranmer Jun 3, 2024
703058e
Merge branch 'master' into expression-type
MilesCranmer Jun 3, 2024
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
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
Loading