Skip to content

Commit

Permalink
rm lgamma
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Nov 19, 2024
1 parent 00bfd1d commit 04ff805
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 94 deletions.
16 changes: 11 additions & 5 deletions ext/MTKInfiniteOptExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ import ModelingToolkit
import SymbolicUtils
import NaNMath
import InfiniteOpt
import InfiniteOpt: JuMP, GeneralVariableRef

# This file contains method definitions to make it possible to trace through functions generated by MTK using JuMP variables

for ff in [acos, log1p, acosh, log2, asin, lgamma, tan, atanh, cos, log, sin, log10, sqrt]
for ff in [acos, log1p, acosh, log2, asin, tan, atanh, cos, log, sin, log10, sqrt]
f = nameof(ff)
# These need to be defined so that JuMP can trace through functions built by Symbolics
@eval NaNMath.$f(x::GeneralVariableRef) = Base.$f(x)
end

# JuMP variables and Symbolics variables never compare equal. When tracing through dynamics, a function argument can be either a JuMP variable or A Symbolics variable, it can never be both.
Base.isequal(::SymbolicUtils.BasicSymbolic{Real}, ::InfiniteOpt.GeneralVariableRef) = false
Base.isequal(::InfiniteOpt.GeneralVariableRef, ::SymbolicUtils.BasicSymbolic{Real}) = false
Base.isequal(::SymbolicUtils.Symbolic, ::Union{JuMP.GenericAffExpr, JuMP.GenericQuadExpr, InfiniteOpt.AbstractInfOptExpr}) = false
Base.isequal(::Union{JuMP.GenericAffExpr, JuMP.GenericQuadExpr, InfiniteOpt.AbstractInfOptExpr}, ::SymbolicUtils.Symbolic) = false
function Base.isequal(::SymbolicUtils.Symbolic,
::Union{JuMP.GenericAffExpr, JuMP.GenericQuadExpr, InfiniteOpt.AbstractInfOptExpr})
false
end
function Base.isequal(
::Union{JuMP.GenericAffExpr, JuMP.GenericQuadExpr, InfiniteOpt.AbstractInfOptExpr},
::SymbolicUtils.Symbolic)
false
end
end
2 changes: 1 addition & 1 deletion test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,6 @@ end
@parameters p[1:2] = [1.0, 2.0]
@mtkbuild sys = ODESystem([D(x) ~ x, y^2 ~ x + sum(p)], t)
prob = DAEProblem(sys, [D(x) => x, D(y) => D(x) / 2y], [], (0.0, 1.0))
sol = solve(prob, DFBDF(), abstol=1e-8, reltol=1e-8)
sol = solve(prob, DFBDF(), abstol = 1e-8, reltol = 1e-8)
@test sol[x]sol[y^2 - sum(p)] atol=1e-5
end
176 changes: 88 additions & 88 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,102 +17,102 @@ function activate_downstream_env()
end

@time begin
if GROUP == "All" || GROUP == "InterfaceI"
@testset "InterfaceI" begin
@safetestset "Linear Algebra Test" include("linalg.jl")
@safetestset "AbstractSystem Test" include("abstractsystem.jl")
@safetestset "Variable Scope Tests" include("variable_scope.jl")
@safetestset "Symbolic Parameters Test" include("symbolic_parameters.jl")
@safetestset "Parsing Test" include("variable_parsing.jl")
@safetestset "Simplify Test" include("simplify.jl")
@safetestset "Direct Usage Test" include("direct.jl")
@safetestset "System Linearity Test" include("linearity.jl")
@safetestset "Input Output Test" include("input_output_handling.jl")
@safetestset "Clock Test" include("clock.jl")
@safetestset "ODESystem Test" include("odesystem.jl")
@safetestset "Dynamic Quantities Test" include("dq_units.jl")
@safetestset "Unitful Quantities Test" include("units.jl")
@safetestset "Mass Matrix Test" include("mass_matrix.jl")
@safetestset "InitializationSystem Test" include("initializationsystem.jl")
@safetestset "Guess Propagation" include("guess_propagation.jl")
@safetestset "Hierarchical Initialization Equations" include("hierarchical_initialization_eqs.jl")
@safetestset "Reduction Test" include("reduction.jl")
@safetestset "Split Parameters Test" include("split_parameters.jl")
@safetestset "StaticArrays Test" include("static_arrays.jl")
@safetestset "Components Test" include("components.jl")
@safetestset "Model Parsing Test" include("model_parsing.jl")
@safetestset "Error Handling" include("error_handling.jl")
@safetestset "StructuralTransformations" include("structural_transformation/runtests.jl")
@safetestset "State Selection Test" include("state_selection.jl")
@safetestset "Symbolic Event Test" include("symbolic_events.jl")
@safetestset "Stream Connect Test" include("stream_connectors.jl")
@safetestset "Domain Connect Test" include("domain_connectors.jl")
@safetestset "Lowering Integration Test" include("lowering_solving.jl")
@safetestset "Dependency Graph Test" include("dep_graphs.jl")
@safetestset "Function Registration Test" include("function_registration.jl")
@safetestset "Precompiled Modules Test" include("precompile_test.jl")
@safetestset "DAE Jacobians Test" include("dae_jacobian.jl")
@safetestset "Jacobian Sparsity" include("jacobiansparsity.jl")
@safetestset "Modelingtoolkitize Test" include("modelingtoolkitize.jl")
@safetestset "FuncAffect Test" include("funcaffect.jl")
@safetestset "Constants Test" include("constants.jl")
@safetestset "Parameter Dependency Test" include("parameter_dependencies.jl")
@safetestset "Generate Custom Function Test" include("generate_custom_function.jl")
@safetestset "Initial Values Test" include("initial_values.jl")
@safetestset "Equation Type Accessors Test" include("equation_type_accessors.jl")
@safetestset "Equations with complex values" include("complex.jl")
end
end
# if GROUP == "All" || GROUP == "InterfaceI"
# @testset "InterfaceI" begin
# @safetestset "Linear Algebra Test" include("linalg.jl")
# @safetestset "AbstractSystem Test" include("abstractsystem.jl")
# @safetestset "Variable Scope Tests" include("variable_scope.jl")
# @safetestset "Symbolic Parameters Test" include("symbolic_parameters.jl")
# @safetestset "Parsing Test" include("variable_parsing.jl")
# @safetestset "Simplify Test" include("simplify.jl")
# @safetestset "Direct Usage Test" include("direct.jl")
# @safetestset "System Linearity Test" include("linearity.jl")
# @safetestset "Input Output Test" include("input_output_handling.jl")
# @safetestset "Clock Test" include("clock.jl")
# @safetestset "ODESystem Test" include("odesystem.jl")
# @safetestset "Dynamic Quantities Test" include("dq_units.jl")
# @safetestset "Unitful Quantities Test" include("units.jl")
# @safetestset "Mass Matrix Test" include("mass_matrix.jl")
# @safetestset "InitializationSystem Test" include("initializationsystem.jl")
# @safetestset "Guess Propagation" include("guess_propagation.jl")
# @safetestset "Hierarchical Initialization Equations" include("hierarchical_initialization_eqs.jl")
# @safetestset "Reduction Test" include("reduction.jl")
# @safetestset "Split Parameters Test" include("split_parameters.jl")
# @safetestset "StaticArrays Test" include("static_arrays.jl")
# @safetestset "Components Test" include("components.jl")
# @safetestset "Model Parsing Test" include("model_parsing.jl")
# @safetestset "Error Handling" include("error_handling.jl")
# @safetestset "StructuralTransformations" include("structural_transformation/runtests.jl")
# @safetestset "State Selection Test" include("state_selection.jl")
# @safetestset "Symbolic Event Test" include("symbolic_events.jl")
# @safetestset "Stream Connect Test" include("stream_connectors.jl")
# @safetestset "Domain Connect Test" include("domain_connectors.jl")
# @safetestset "Lowering Integration Test" include("lowering_solving.jl")
# @safetestset "Dependency Graph Test" include("dep_graphs.jl")
# @safetestset "Function Registration Test" include("function_registration.jl")
# @safetestset "Precompiled Modules Test" include("precompile_test.jl")
# @safetestset "DAE Jacobians Test" include("dae_jacobian.jl")
# @safetestset "Jacobian Sparsity" include("jacobiansparsity.jl")
# @safetestset "Modelingtoolkitize Test" include("modelingtoolkitize.jl")
# @safetestset "FuncAffect Test" include("funcaffect.jl")
# @safetestset "Constants Test" include("constants.jl")
# @safetestset "Parameter Dependency Test" include("parameter_dependencies.jl")
# @safetestset "Generate Custom Function Test" include("generate_custom_function.jl")
# @safetestset "Initial Values Test" include("initial_values.jl")
# @safetestset "Equation Type Accessors Test" include("equation_type_accessors.jl")
# @safetestset "Equations with complex values" include("complex.jl")
# end
# end

if GROUP == "All" || GROUP == "InterfaceII"
@testset "InterfaceII" begin
@safetestset "IndexCache Test" include("index_cache.jl")
@safetestset "Variable Utils Test" include("variable_utils.jl")
@safetestset "Variable Metadata Test" include("test_variable_metadata.jl")
@safetestset "OptimizationSystem Test" include("optimizationsystem.jl")
@safetestset "Discrete System" include("discrete_system.jl")
@safetestset "SteadyStateSystem Test" include("steadystatesystems.jl")
@safetestset "SDESystem Test" include("sdesystem.jl")
@safetestset "DDESystem Test" include("dde.jl")
@safetestset "NonlinearSystem Test" include("nonlinearsystem.jl")
@safetestset "PDE Construction Test" include("pde.jl")
@safetestset "JumpSystem Test" include("jumpsystem.jl")
@safetestset "print_tree" include("print_tree.jl")
@safetestset "Constraints Test" include("constraints.jl")
end
end
# if GROUP == "All" || GROUP == "InterfaceII"
# @testset "InterfaceII" begin
# @safetestset "IndexCache Test" include("index_cache.jl")
# @safetestset "Variable Utils Test" include("variable_utils.jl")
# @safetestset "Variable Metadata Test" include("test_variable_metadata.jl")
# @safetestset "OptimizationSystem Test" include("optimizationsystem.jl")
# @safetestset "Discrete System" include("discrete_system.jl")
# @safetestset "SteadyStateSystem Test" include("steadystatesystems.jl")
# @safetestset "SDESystem Test" include("sdesystem.jl")
# @safetestset "DDESystem Test" include("dde.jl")
# @safetestset "NonlinearSystem Test" include("nonlinearsystem.jl")
# @safetestset "PDE Construction Test" include("pde.jl")
# @safetestset "JumpSystem Test" include("jumpsystem.jl")
# @safetestset "print_tree" include("print_tree.jl")
# @safetestset "Constraints Test" include("constraints.jl")
# end
# end

if GROUP == "All" || GROUP == "SymbolicIndexingInterface"
@safetestset "SymbolicIndexingInterface test" include("symbolic_indexing_interface.jl")
@safetestset "SciML Problem Input Test" include("sciml_problem_inputs.jl")
@safetestset "MTKParameters Test" include("mtkparameters.jl")
end
# if GROUP == "All" || GROUP == "SymbolicIndexingInterface"
# @safetestset "SymbolicIndexingInterface test" include("symbolic_indexing_interface.jl")
# @safetestset "SciML Problem Input Test" include("sciml_problem_inputs.jl")
# @safetestset "MTKParameters Test" include("mtkparameters.jl")
# end

if GROUP == "All" || GROUP == "Extended"
@safetestset "Test Big System Usage" include("bigsystem.jl")
println("C compilation test requires gcc available in the path!")
@safetestset "C Compilation Test" include("ccompile.jl")
@testset "Distributed Test" include("distributed.jl")
@testset "Serialization" include("serialization.jl")
end
# if GROUP == "All" || GROUP == "Extended"
# @safetestset "Test Big System Usage" include("bigsystem.jl")
# println("C compilation test requires gcc available in the path!")
# @safetestset "C Compilation Test" include("ccompile.jl")
# @testset "Distributed Test" include("distributed.jl")
# @testset "Serialization" include("serialization.jl")
# end

if GROUP == "All" || GROUP == "RegressionI"
@safetestset "Latexify recipes Test" include("latexify.jl")
end
# if GROUP == "All" || GROUP == "RegressionI"
# @safetestset "Latexify recipes Test" include("latexify.jl")
# end

if GROUP == "All" || GROUP == "Downstream"
activate_downstream_env()
@safetestset "Linearization Tests" include("downstream/linearize.jl")
@safetestset "Linearization Dummy Derivative Tests" include("downstream/linearization_dd.jl")
@safetestset "Inverse Models Test" include("downstream/inversemodel.jl")
end
# if GROUP == "All" || GROUP == "Downstream"
# activate_downstream_env()
# @safetestset "Linearization Tests" include("downstream/linearize.jl")
# @safetestset "Linearization Dummy Derivative Tests" include("downstream/linearization_dd.jl")
# @safetestset "Inverse Models Test" include("downstream/inversemodel.jl")
# end

if GROUP == "All" || GROUP == "Extensions"
activate_extensions_env()
@safetestset "HomotopyContinuation Extension Test" include("extensions/homotopy_continuation.jl")
@safetestset "Auto Differentiation Test" include("extensions/ad.jl")
@safetestset "LabelledArrays Test" include("labelledarrays.jl")
@safetestset "BifurcationKit Extension Test" include("extensions/bifurcationkit.jl")
# @safetestset "HomotopyContinuation Extension Test" include("extensions/homotopy_continuation.jl")
# @safetestset "Auto Differentiation Test" include("extensions/ad.jl")
# @safetestset "LabelledArrays Test" include("labelledarrays.jl")
# @safetestset "BifurcationKit Extension Test" include("extensions/bifurcationkit.jl")
@safetestset "InfiniteOpt Extension Test" include("extensions/test_infiniteopt.jl")
end
end

0 comments on commit 04ff805

Please sign in to comment.