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

Fluctuations of the Crude Birth Rate variable #60

Closed
universmile opened this issue Sep 20, 2022 · 10 comments
Closed

Fluctuations of the Crude Birth Rate variable #60

universmile opened this issue Sep 20, 2022 · 10 comments
Assignees
Labels
improvement Improve existing code

Comments

@universmile
Copy link
Contributor

In few figures of Chapter 2 (Population), the plot corresponding to the cbr variable fluctuates. This instability might be related to Issue #59 (e.g., iphst parameter).

In the following, we provide a minimal reproducible example.

Source code :

using WorldDynamics

include("../scenarios/pop1_historicalrun.jl")

@named pop = WorldDynamics.World3.Pop1.population()
@named br = WorldDynamics.World3.Pop1.birth_rate()
@named dr = WorldDynamics.World3.Pop1.death_rate()
@named so = WorldDynamics.World3.Pop1.service_output()
@named io = WorldDynamics.World3.Pop1.industrial_output()
@named f = WorldDynamics.World3.Pop1.food()

@variables t

fig_2_88_variables = [
    (so.sopc, 0,   1000,   "sopc"),
    (io.iopc, 0,   1000,   "iopc"),
    (f.fpc,   0,   1000,   "fpc"),
    (pop.pop, 0,   1.6e10, "pop"),
    (br.cbr,  0,   50,     "cbr"),
    (dr.cdr,  0,   50,     "cdr"),
    (dr.le,   0,   80,     "le"),
    (dr.fpu,  0,   1,      "fpu"),
    (br.fce,  0.5, 1,      "fce"),
]

parameters_2_88 = WorldDynamics.World3.Pop1.getparameters()
parameters_2_88[:iphst] = 4000
parameters_2_88[:lt2] = 1900
parameters_2_88[:cio] = 1000
parameters_2_88[:cso] = 1500
parameters_2_88[:cfood] = 2500

system = pop1_historicalrun(params=parameters_2_88)
sol_2_88 = WorldDynamics.solve(system, (1900, 2100))

plotvariables(sol_2_88, (t, 1900, 2100), fig_2_88_variables, name="Fig. 2.88a", showlegend=true, showaxis=true, colored=true)

Resulting plot :

Fig  2 88a

@universmile
Copy link
Contributor Author

universmile commented Sep 21, 2022

The issue is related to the method used by the solver. We should find the adequate method.

In the following, we show the plots returned by different methods, namely Tsit5 (default), BS5 (for non-stiff ODE), and Rosenbrock23, TRBDF2, Rodas5 (for stiff ODE).

Cf. https://docs.juliahub.com/DifferentialEquations/UQdwS/6.17.1/solvers/ode_solve/#ode_solve

solvers

@natema
Copy link
Member

natema commented Sep 21, 2022

I had a look at the Unknown Stiffness section in the docs, and calling

sol_2_88 = WorldDynamics.solve(system, (1900, 2100), solver=AutoVern9(Rodas5()))

gives
image

@paulobruno
Copy link
Collaborator

We set the default solver to AutoVern9(Rodas5()), but I'm still getting the fluctuations.

@natema
Copy link
Member

natema commented Sep 29, 2022

We set the default solver to AutoVern9(Rodas5()), but I'm still getting the fluctuations.

This persists on julia 1.8.1?

@paulobruno
Copy link
Collaborator

We set the default solver to AutoVern9(Rodas5()), but I'm still getting the fluctuations.

This persists on julia 1.8.1?

Yes, it does.

Screenshot from 2022-09-29 23-10-31

@universmile
Copy link
Contributor Author

I do not get the fluctuations when I move (from Julia 1.7.2) to Julia 1.8.1.

plot_1

Side information : I am using DifferentialEquations 7.3.0 and ModelingToolkit 8.16.0.

@paulobruno
Copy link
Collaborator

This is very strange, I'm also using those versions.

(WorldDynamics) pkg> status
Project WorldDynamics v0.1.0
Status `/home/pdesousa/Documents/git/WorldDynamics/Project.toml`
  [35d6a980] ColorSchemes v3.19.0
  [3da002f7] ColorTypes v0.11.4
⌅ [0c46a032] DifferentialEquations v7.3.0
  [bd48cda9] GraphRecipes v0.5.12
  [615f187c] IfElse v0.1.1
⌅ [961ee093] ModelingToolkit v8.16.0
  [f0f68f2c] PlotlyJS v0.18.9

@paulobruno paulobruno added improvement Improve existing code and removed break Something isn't working labels Oct 5, 2022
@paulobruno paulobruno removed this from the reproducing World3 milestone Oct 5, 2022
@natema
Copy link
Member

natema commented May 9, 2023

@paulobruno on Julia 1.8.5 AutoVern9(Rodas5()) works fine (I instantiated a fresh environment).
If you still get the issue, we can compare our Manifest files.
Otherwise, this should be closed as soon as we solve #114 .

@paulobruno
Copy link
Collaborator

I confirm there are no fluctuations anymore.

Screenshot from 2023-05-10 17-57-01

@natema
Copy link
Member

natema commented May 16, 2023

Since #114 has been closed and the oscillation disappeared, I close this issue.

@natema natema closed this as completed May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improve existing code
Projects
None yet
Development

No branches or pull requests

4 participants