From ee626c345bd0001005123d245cf22b05b6e150ab Mon Sep 17 00:00:00 2001 From: deltamarnix <150045289+deltamarnix@users.noreply.github.com> Date: Thu, 11 Jan 2024 11:24:07 +0100 Subject: [PATCH] Logger writes to both Terminal and File (#911) Fixes #502 Fixes #747 Using `LoggingExtras` as a basis to write logs to two places at the same time. The verbosity only applies to the file logger. The terminal logger will always be on Progress level (-1). The settings.json was adjusted to exclude some folders that do not help in our development. --------- Co-authored-by: Martijn Visser --- .vscode/settings.json | 7 +- Manifest.toml | 36 +++++++++ Project.toml | 3 + build/ribasim_cli/src/ribasim_cli.jl | 47 +----------- core/src/Ribasim.jl | 7 +- core/src/bmi.jl | 30 ++------ core/src/logging.jl | 28 +++++++ core/src/main.jl | 56 ++++++++++++++ core/test/cli_test.jl | 38 ---------- core/test/config_test.jl | 2 +- .../{testrun.toml => data/config_test.toml} | 4 +- .../data/logging_test_loglevel_debug.toml | 7 ++ core/test/data/logging_test_no_loglevel.toml | 4 + core/test/logging_test.jl | 75 +++++++++++++++++++ core/test/main_test.jl | 46 ++++++++++++ core/test/run_models_test.jl | 6 +- core/test/validation_test.jl | 4 +- docs/python/examples.ipynb | 8 +- pixi.toml | 2 + 19 files changed, 287 insertions(+), 123 deletions(-) create mode 100644 core/src/logging.jl create mode 100644 core/src/main.jl delete mode 100644 core/test/cli_test.jl rename core/test/{testrun.toml => data/config_test.toml} (65%) create mode 100644 core/test/data/logging_test_loglevel_debug.toml create mode 100644 core/test/data/logging_test_no_loglevel.toml create mode 100644 core/test/logging_test.jl create mode 100644 core/test/main_test.jl diff --git a/.vscode/settings.json b/.vscode/settings.json index 1e5b4d436..376ad58d6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,5 +22,10 @@ "." ], "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true + "python.testing.pytestEnabled": true, + "julia.lint.disabledDirs": [ + ".pixi", + "utils/juliaup" + ], + "julia.lint.run": true } diff --git a/Manifest.toml b/Manifest.toml index 4f6519041..3f635a725 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -159,6 +159,12 @@ git-tree-sha1 = "70232f82ffaab9dc52585e0dd043b5e0c6b714f1" uuid = "fb6a15b2-703c-40df-9091-08a04967cfa9" version = "0.1.12" +[[deps.CodeTracking]] +deps = ["InteractiveUtils", "UUIDs"] +git-tree-sha1 = "c0216e792f518b39b22212127d4a84dc31e4e386" +uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" +version = "1.3.5" + [[deps.CodecBzip2]] deps = ["Bzip2_jll", "Libdl", "TranscodingStreams"] git-tree-sha1 = "c0ae2a86b162fb5d7acc65269b469ff5b8a73594" @@ -715,6 +721,12 @@ version = "1.16.0" [deps.JuMP.weakdeps] DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0" +[[deps.JuliaInterpreter]] +deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"] +git-tree-sha1 = "e49bce680c109bc86e3e75ebcb15040d6ad9e1d3" +uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a" +version = "0.9.27" + [[deps.KLU]] deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse_jll"] git-tree-sha1 = "884c2968c2e8e7e6bf5956af88cb46aa745c854b" @@ -873,6 +885,12 @@ weakdeps = ["ChainRulesCore", "ForwardDiff", "SpecialFunctions"] ForwardDiffExt = ["ChainRulesCore", "ForwardDiff"] SpecialFunctionsExt = "SpecialFunctions" +[[deps.LoweredCodeUtils]] +deps = ["JuliaInterpreter"] +git-tree-sha1 = "0b8cf121228f7dae022700c1c11ac1f04122f384" +uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" +version = "2.3.2" + [[deps.Lz4_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl"] git-tree-sha1 = "6c26c5e8a4203d43b5497be3ec5d4e0c3cde240a" @@ -1147,6 +1165,12 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" deps = ["SHA"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +[[deps.ReTestItems]] +deps = ["Dates", "Logging", "LoggingExtras", "Pkg", "Serialization", "Sockets", "Test", "TestEnv"] +git-tree-sha1 = "e8dd0646b221f3b75af2f36f83f509e2dde8dbe8" +uuid = "817f1d60-ba6b-4fd5-9520-3cf149f6a823" +version = "1.22.0" + [[deps.RecipesBase]] deps = ["PrecompileTools"] git-tree-sha1 = "5c3d09cc4f31f5fc6af001c250bf1278733100ff" @@ -1194,6 +1218,12 @@ git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7" uuid = "ae029012-a4dd-5104-9daa-d747884805df" version = "1.3.0" +[[deps.Revise]] +deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "Requires", "UUIDs", "Unicode"] +git-tree-sha1 = "6990168abf3fe9a6e34ebb0e05aaaddf6572189e" +uuid = "295af30f-e4ad-537b-8983-00126c2a3abe" +version = "3.5.10" + [[deps.Ribasim]] deps = ["Accessors", "Arrow", "BasicModelInterface", "CodecLz4", "CodecZstd", "ComponentArrays", "Configurations", "DBInterface", "DataInterpolations", "DataStructures", "Dates", "Dictionaries", "DiffEqCallbacks", "EnumX", "FiniteDiff", "ForwardDiff", "Graphs", "HiGHS", "IterTools", "JuMP", "Legolas", "Logging", "LoggingExtras", "MetaGraphsNext", "OrdinaryDiffEq", "PreallocationTools", "SQLite", "SciMLBase", "SparseArrays", "StructArrays", "Tables", "TerminalLoggers", "TimeZones", "TimerOutputs", "TranscodingStreams"] path = "core" @@ -1506,6 +1536,12 @@ version = "0.1.7" deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +[[deps.TestEnv]] +deps = ["Pkg"] +git-tree-sha1 = "c35f69c951ac4f74b8b074f62dfb1e169b351497" +uuid = "1e6cf692-eddd-4d53-88a5-2d735e33781b" +version = "1.101.1" + [[deps.ThreadingUtilities]] deps = ["ManualMemory"] git-tree-sha1 = "eda08f7e9818eb53661b3deb74e3159460dfbc27" diff --git a/Project.toml b/Project.toml index 757365ff1..36cc6a120 100644 --- a/Project.toml +++ b/Project.toml @@ -3,7 +3,10 @@ authors = ["Deltares and contributors "] description = "Meta-project used to share the Manifest of Ribasim and its dependents" [deps] +ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823" +Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" Ribasim = "aac5e3d9-0b8f-4d4f-8241-b1a7a9632635" +TestEnv = "1e6cf692-eddd-4d53-88a5-2d735e33781b" TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" create_binaries = "3cfb6a46-05f0-43df-bb16-bf763deb14b4" docs = "8daea9ca-fc6c-4731-aa85-717fa0b706bc" diff --git a/build/ribasim_cli/src/ribasim_cli.jl b/build/ribasim_cli/src/ribasim_cli.jl index d04336281..6e28f8507 100644 --- a/build/ribasim_cli/src/ribasim_cli.jl +++ b/build/ribasim_cli/src/ribasim_cli.jl @@ -1,52 +1,7 @@ module ribasim_cli -using Logging: global_logger, with_logger -using TerminalLoggers: TerminalLogger -using SciMLBase: successful_retcode using Ribasim -function help(x)::Cint - println(x) - println("Usage: ribasim path/to/model/ribasim.toml") - return 1 -end - -function julia_main()::Cint - n = length(ARGS) - if n != 1 - return help("Exactly 1 argument expected, got $n") - end - arg = only(ARGS) - - if arg == "--version" - version = pkgversion(Ribasim) - print(version) - return 0 - end - - if !isfile(arg) - return help("File not found: $arg") - end - - try - # show progress bar in terminal - model = with_logger(TerminalLogger()) do - Ribasim.run(arg) - end - return if successful_retcode(model) - println("The model finished successfully") - 0 - else - t = Ribasim.datetime_since(model.integrator.t, model.config.starttime) - retcode = model.integrator.sol.retcode - println("The model exited at model time $t with return code $retcode") - println("See https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/#retcodes") - 1 - end - catch - Base.invokelatest(Base.display_error, current_exceptions()) - return 1 - end -end +julia_main()::Cint = Ribasim.main(ARGS) end # module diff --git a/core/src/Ribasim.jl b/core/src/Ribasim.jl index 956cb7f71..79947b8a6 100644 --- a/core/src/Ribasim.jl +++ b/core/src/Ribasim.jl @@ -19,6 +19,7 @@ import BasicModelInterface as BMI import HiGHS import JuMP import TranscodingStreams +import LoggingExtras using Accessors: @set using Arrow: Arrow, Table @@ -46,8 +47,7 @@ using Graphs: rem_edge! using Legolas: Legolas, @schema, @version, validate, SchemaVersion, declared -using Logging: current_logger, min_enabled_level, with_logger -using LoggingExtras: EarlyFilteredLogger, LevelOverrideLogger +using Logging: with_logger, LogLevel, AbstractLogger using MetaGraphsNext: MetaGraphsNext, MetaGraph, @@ -60,6 +60,7 @@ using OrdinaryDiffEq using OrdinaryDiffEq: OrdinaryDiffEqRosenbrockAdaptiveAlgorithm using PreallocationTools: DiffCache, FixedSizeDiffCache, get_tmp using SciMLBase +using SciMLBase: successful_retcode using SparseArrays using SQLite: SQLite, DB, Query, esc_id using StructArrays: StructVector @@ -74,6 +75,7 @@ include("validation.jl") include("solve.jl") include("config.jl") using .config +include("logging.jl") include("allocation.jl") include("utils.jl") include("lib.jl") @@ -81,5 +83,6 @@ include("io.jl") include("create.jl") include("bmi.jl") include("consts.jl") +include("main.jl") end # module Ribasim diff --git a/core/src/bmi.jl b/core/src/bmi.jl index 4d25344f0..b7b62e200 100644 --- a/core/src/bmi.jl +++ b/core/src/bmi.jl @@ -663,34 +663,14 @@ BMI.get_time_step(model::Model) = get_proposed_dt(model.integrator) """ run(config_file::AbstractString)::Model run(config::Config)::Model - Run a [`Model`](@ref), given a path to a TOML configuration file, or a Config object. Running a model includes initialization, solving to the end with `[`solve!`](@ref)` and writing results with [`BMI.finalize`](@ref). """ -run(config_file::AbstractString)::Model = run(Config(config_file)) - -function is_current_module(log) - (log._module == @__MODULE__) || - (parentmodule(log._module) == @__MODULE__) || - log._module == OrdinaryDiffEq # for the progress bar -end +run(config_path::AbstractString)::Model = run(Config(config_path)) function run(config::Config)::Model - logger = current_logger() - - # Reconfigure the logger if necessary with the correct loglevel - # but make sure to only log from Ribasim - if min_enabled_level(logger) + 1 != config.logging.verbosity - logger = EarlyFilteredLogger( - is_current_module, - LevelOverrideLogger(config.logging.verbosity, logger), - ) - end - - with_logger(logger) do - model = Model(config) - solve!(model) - BMI.finalize(model) - return model - end + model = Model(config) + solve!(model) + BMI.finalize(model) + return model end diff --git a/core/src/logging.jl b/core/src/logging.jl new file mode 100644 index 000000000..de4dcad96 --- /dev/null +++ b/core/src/logging.jl @@ -0,0 +1,28 @@ +""" + is_current_module(log::LogMessageType)::Bool + Returns true if the log message is from the current module or a submodule. + + See https://github.com/JuliaLogging/LoggingExtras.jl/blob/d35e7c8cfc197853ee336ace17182e6ed36dca24/src/CompositionalLoggers/earlyfiltered.jl#L39 + for the information available in log. +""" +function is_current_module(log)::Bool + (log._module == @__MODULE__) || + (parentmodule(log._module) == @__MODULE__) || + log._module == OrdinaryDiffEq # for the progress bar +end + +function setup_logger(; + verbosity::LogLevel, + stream::IOStream, + module_filter_function::Function = is_current_module, +)::AbstractLogger + file_logger = LoggingExtras.MinLevelLogger(LoggingExtras.FileLogger(stream), verbosity) + terminal_logger = LoggingExtras.MinLevelLogger( + TerminalLogger(), + LogLevel(-1), # To include progress bar + ) + return LoggingExtras.EarlyFilteredLogger( + module_filter_function, + LoggingExtras.TeeLogger(file_logger, terminal_logger), + ) +end diff --git a/core/src/main.jl b/core/src/main.jl new file mode 100644 index 000000000..fb621c0e9 --- /dev/null +++ b/core/src/main.jl @@ -0,0 +1,56 @@ +function help(x::AbstractString)::Cint + println(x) + println("Usage: ribasim path/to/model/ribasim.toml") + return 1 +end + +main(toml_path::AbstractString)::Cint = main([toml_path]) + +""" + main(ARGS::Vector{String})::Cint +This is the main entry point of the application. +Performs argument parsing and sets up logging for both terminal and file. +Calls Ribasim.run() and handles exceptions to convert to exit codes. +""" +function main(ARGS::Vector{String})::Cint + n = length(ARGS) + if n != 1 + return help("Exactly 1 argument expected, got $n") + end + arg = only(ARGS) + + if arg == "--version" + version = pkgversion(Ribasim) + print(version) + return 0 + end + + if !isfile(arg) + return help("File not found: $arg") + end + + try + # show progress bar in terminal + config = Config(arg) + mkpath(results_path(config, ".")) + open(results_path(config, "ribasim.log"), "w") do io + logger = + Ribasim.setup_logger(; verbosity = config.logging.verbosity, stream = io) + with_logger(logger) do + model = Ribasim.run(config) + if successful_retcode(model) + @info "The model finished successfully" + return 0 + end + + t = Ribasim.datetime_since(model.integrator.t, model.config.starttime) + retcode = model.integrator.sol.retcode + @error "The model exited at model time $t with return code $retcode.\nSee https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/#retcodes" + return 1 + end + end + catch + Base.invokelatest(Base.display_error, current_exceptions()) + return 1 + end +end diff --git a/core/test/cli_test.jl b/core/test/cli_test.jl deleted file mode 100644 index 78bb0a727..000000000 --- a/core/test/cli_test.jl +++ /dev/null @@ -1,38 +0,0 @@ -@testitem "version" begin - using IOCapture: capture - using Logging: global_logger, ConsoleLogger - - include("../../build/ribasim_cli/src/ribasim_cli.jl") - - empty!(ARGS) - push!(ARGS, "--version") - (; value, output) = capture(ribasim_cli.julia_main) - @test value == 0 - @test output == string(pkgversion(Ribasim)) - - # the global logger is modified by ribasim_cli; set it back to the default - global_logger(ConsoleLogger()) -end - -@testitem "toml_path" begin - using IOCapture: capture - using Logging: global_logger, ConsoleLogger - - include("../../build/ribasim_cli/src/ribasim_cli.jl") - - model_path = normpath(@__DIR__, "../../generated_testmodels/basic/") - toml_path = normpath(model_path, "ribasim.toml") - @test ispath(toml_path) - empty!(ARGS) - push!(ARGS, toml_path) - (; value, output, error, backtrace) = capture(ribasim_cli.julia_main) - @test value == 0 - if value != 0 - @show output - @show error - @show backtrace - end - - # the global logger is modified by ribasim_cli; set it back to the default - global_logger(ConsoleLogger()) -end diff --git a/core/test/config_test.jl b/core/test/config_test.jl index c10ba18b1..1d21594a9 100644 --- a/core/test/config_test.jl +++ b/core/test/config_test.jl @@ -5,7 +5,7 @@ using Dates @testset "testrun" begin - config = Ribasim.Config(normpath(@__DIR__, "testrun.toml")) + config = Ribasim.Config(normpath(@__DIR__, "data", "config_test.toml")) @test config isa Ribasim.Config @test config.endtime > config.starttime @test config.solver == Ribasim.Solver(; saveat = 86400.0) diff --git a/core/test/testrun.toml b/core/test/data/config_test.toml similarity index 65% rename from core/test/testrun.toml rename to core/test/data/config_test.toml index 10b04b46e..1a32a5f13 100644 --- a/core/test/testrun.toml +++ b/core/test/data/config_test.toml @@ -2,8 +2,8 @@ starttime = 2019-01-01 endtime = 2019-12-31 # optional, default is the path of the TOML -input_dir = "../generated_testmodels/lhm" -results_dir = "../generated_testmodels/lhm" +input_dir = "../../generated_testmodels/lhm" +results_dir = "../../generated_testmodels/lhm" database = "database.gpkg" diff --git a/core/test/data/logging_test_loglevel_debug.toml b/core/test/data/logging_test_loglevel_debug.toml new file mode 100644 index 000000000..ef75199c3 --- /dev/null +++ b/core/test/data/logging_test_loglevel_debug.toml @@ -0,0 +1,7 @@ +starttime = 2019-01-01 +endtime = 2019-12-31 +input_dir = "." +results_dir = "results" + +[logging] +verbosity = "debug" diff --git a/core/test/data/logging_test_no_loglevel.toml b/core/test/data/logging_test_no_loglevel.toml new file mode 100644 index 000000000..61b795254 --- /dev/null +++ b/core/test/data/logging_test_no_loglevel.toml @@ -0,0 +1,4 @@ +starttime = 2019-01-01 +endtime = 2019-12-31 +input_dir = "." +results_dir = "results" diff --git a/core/test/logging_test.jl b/core/test/logging_test.jl new file mode 100644 index 000000000..7b142065b --- /dev/null +++ b/core/test/logging_test.jl @@ -0,0 +1,75 @@ +@testitem "setup_logger defaults to level info-1" begin + using Logging + mktempdir() do dir + cp( + normpath(@__DIR__, "data", "logging_test_no_loglevel.toml"), + normpath(dir, "ribasim.toml"); + force = true, + ) + config = Ribasim.Config(normpath(dir, "ribasim.toml")) + mkdir(Ribasim.results_path(config, ".")) + open(Ribasim.results_path(config, "ribasim.log"), "w") do io + logger = + Ribasim.setup_logger(; verbosity = config.logging.verbosity, stream = io) + @test Logging.shouldlog(logger, Logging.Error, Ribasim, :group, :message) + @test Logging.shouldlog(logger, Logging.Info, Ribasim, :group, :message) + @test Logging.shouldlog(logger, Logging.Info - 1, Ribasim, :group, :message) # progress bar + @test !Logging.shouldlog(logger, Logging.Debug, Ribasim, :group, :message) + end + end +end + +@testitem "setup_logger reads debug verbosity from config" begin + using Logging + mktempdir() do dir + cp( + normpath(@__DIR__, "data", "logging_test_loglevel_debug.toml"), + normpath(dir, "ribasim.toml"); + force = true, + ) + config = Ribasim.Config(normpath(dir, "ribasim.toml")) + mkdir(Ribasim.results_path(config, ".")) + open(Ribasim.results_path(config, "ribasim.log"), "w") do io + logger = + Ribasim.setup_logger(; verbosity = config.logging.verbosity, stream = io) + @test Logging.shouldlog(logger, Logging.Error, Ribasim, :group, :message) + @test Logging.shouldlog(logger, Logging.Info, Ribasim, :group, :message) + @test Logging.shouldlog(logger, Logging.Info - 1, Ribasim, :group, :message) # progress bar + @test Logging.shouldlog(logger, Logging.Debug, Ribasim, :group, :message) + end + end +end + +@testitem "setup_logger creates TeeLogger with 2 sinks" begin + using Logging + using LoggingExtras + mktempdir() do dir + cp( + normpath(@__DIR__, "data", "logging_test_loglevel_debug.toml"), + normpath(dir, "ribasim.toml"); + force = true, + ) + config = Ribasim.Config(normpath(dir, "ribasim.toml")) + mkdir(Ribasim.results_path(config, ".")) + open(Ribasim.results_path(config, "ribasim.log"), "w") do io + logger = Ribasim.setup_logger(; + verbosity = Logging.Debug, + stream = io, + module_filter_function = log -> log._module == @__MODULE__, + ) + + with_logger(logger) do + @info "foo" + @warn "bar" + @debug "baz" + end + end + + open(normpath(dir, "results", "ribasim.log"), "r") do io + result = read(io, String) + @test occursin("Info: foo", result) + @test occursin("Warning: bar", result) + @test occursin("Debug: baz", result) + end + end +end diff --git a/core/test/main_test.jl b/core/test/main_test.jl new file mode 100644 index 000000000..fd21a9537 --- /dev/null +++ b/core/test/main_test.jl @@ -0,0 +1,46 @@ +@testitem "version" begin + using IOCapture: capture + + (; value, output) = capture() do + Ribasim.main(["--version"]) + end + @test value == 0 + @test output == string(pkgversion(Ribasim)) +end + +@testitem "toml_path" begin + using IOCapture: capture + + model_path = normpath(@__DIR__, "../../generated_testmodels/basic/") + toml_path = normpath(model_path, "ribasim.toml") + @test ispath(toml_path) + (; value, output, error, backtrace) = capture() do + Ribasim.main([toml_path]) + end + @test value == 0 + if value != 0 + @show output + @show error + @show backtrace + end +end + +@testitem "too many arguments for main" begin + using IOCapture: capture + + (; value, output) = capture() do + Ribasim.main(["too", "many"]) + end + @test value == 1 + @test occursin("Exactly 1 argument expected, got 2", output) +end + +@testitem "non-existing file for main" begin + using IOCapture: capture + + (; value, output) = capture() do + Ribasim.main(["non-existing-file.toml"]) + end + @test value == 1 + @test occursin("File not found: non-existing-file.toml", output) +end diff --git a/core/test/run_models_test.jl b/core/test/run_models_test.jl index db78a764c..e0b058e0a 100644 --- a/core/test/run_models_test.jl +++ b/core/test/run_models_test.jl @@ -98,6 +98,7 @@ end @testitem "basic model" begin using Logging: Debug, with_logger + using LoggingExtras using SciMLBase: successful_retcode import Tables using Dates @@ -105,8 +106,9 @@ end toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml") @test ispath(toml_path) - logger = TestLogger() - model = with_logger(logger) do + logger = TestLogger(; min_level = Debug) + filtered_logger = LoggingExtras.EarlyFilteredLogger(Ribasim.is_current_module, logger) + model = with_logger(filtered_logger) do Ribasim.run(toml_path) end diff --git a/core/test/validation_test.jl b/core/test/validation_test.jl index 41a6396f6..1d6dd4ce4 100644 --- a/core/test/validation_test.jl +++ b/core/test/validation_test.jl @@ -8,7 +8,7 @@ level = [[0.0, 0.0, 1.0]] area = [[0.0, 100.0, 90]] - logger = TestLogger() + logger = TestLogger(; min_level = Debug) with_logger(logger) do @test !valid_profiles(node_id, level, area) end @@ -124,7 +124,7 @@ end fractional_flow = Ribasim.FractionalFlow([NodeID(5)], [1.0], Dict{Tuple{Int, String}, NamedTuple}()) - logger = TestLogger() + logger = TestLogger(; min_level = Debug) with_logger(logger) do @test !Ribasim.valid_n_neighbors(fractional_flow, graph) end diff --git a/docs/python/examples.ipynb b/docs/python/examples.ipynb index 4e00ab232..7b27083d2 100644 --- a/docs/python/examples.ipynb +++ b/docs/python/examples.ipynb @@ -576,7 +576,7 @@ " \"julia\",\n", " \"--project=../../core\",\n", " \"--eval\",\n", - " f'using Ribasim; Ribasim.run(\"{datadir.as_posix()}/basic_transient/ribasim.toml\")',\n", + " f'using Ribasim; Ribasim.main(\"{datadir.as_posix()}/basic_transient/ribasim.toml\")',\n", " ],\n", " check=True,\n", ")" @@ -968,7 +968,7 @@ " \"julia\",\n", " \"--project=../../core\",\n", " \"--eval\",\n", - " f'using Ribasim; Ribasim.run(\"{datadir.as_posix()}/level_setpoint_with_minmax/ribasim.toml\")',\n", + " f'using Ribasim; Ribasim.main(\"{datadir.as_posix()}/level_setpoint_with_minmax/ribasim.toml\")',\n", " ],\n", " check=True,\n", ")" @@ -1390,7 +1390,7 @@ " \"julia\",\n", " \"--project=../../core\",\n", " \"--eval\",\n", - " f'using Ribasim; Ribasim.run(\"{datadir.as_posix()}/pid_control/ribasim.toml\")',\n", + " f'using Ribasim; Ribasim.main(\"{datadir.as_posix()}/pid_control/ribasim.toml\")',\n", " ],\n", " check=True,\n", ")" @@ -1849,7 +1849,7 @@ " \"julia\",\n", " \"--project=../../core\",\n", " \"--eval\",\n", - " f'using Ribasim; Ribasim.run(\"{datadir.as_posix()}/allocation_example/ribasim.toml\")',\n", + " f'using Ribasim; Ribasim.main(\"{datadir.as_posix()}/allocation_example/ribasim.toml\")',\n", " ],\n", " check=True,\n", ")" diff --git a/pixi.toml b/pixi.toml index 0cf0ad423..5edf37df8 100644 --- a/pixi.toml +++ b/pixi.toml @@ -113,6 +113,8 @@ install-qgis-plugins = { depends_on = [ "install-imod-qgis", ] } mypy-ribasim-qgis = "mypy ribasim_qgis" +# Run +ribasim-model = "julia --project=core -e 'using Ribasim; Ribasim.main(ARGS)'" [dependencies] build = "*"