From 04ff805a3e118860f2de8d0479701e63aeadf13f Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Tue, 19 Nov 2024 12:42:26 +0100 Subject: [PATCH] rm lgamma --- ext/MTKInfiniteOptExt.jl | 16 ++-- test/odesystem.jl | 2 +- test/runtests.jl | 176 +++++++++++++++++++-------------------- 3 files changed, 100 insertions(+), 94 deletions(-) diff --git a/ext/MTKInfiniteOptExt.jl b/ext/MTKInfiniteOptExt.jl index 79463f7e71..3b482a1f03 100644 --- a/ext/MTKInfiniteOptExt.jl +++ b/ext/MTKInfiniteOptExt.jl @@ -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 diff --git a/test/odesystem.jl b/test/odesystem.jl index 90d1c4c578..02eb80ef85 100644 --- a/test/odesystem.jl +++ b/test/odesystem.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 25b692f678..ce6d3fcf0b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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