From 9f50f5dbc3753875117ea16836ea403127184641 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 1 Dec 2022 09:33:10 +0000 Subject: [PATCH 1/5] V0.1.2 of SE lib --- lpm.jl | 2 +- mainMAHelpers.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lpm.jl b/lpm.jl index 2d973f5..b56de4d 100644 --- a/lpm.jl +++ b/lpm.jl @@ -3,7 +3,7 @@ include("libspath.jl") using SocioEconomicsX: SEVERSION using SocioEconomicsX: SEPATH, SESRCPATH -@assert SEVERSION == v"0.1.1" +@assert SEVERSION == v"0.1.2" using SocioEconomicsX.ParamTypes diff --git a/mainMAHelpers.jl b/mainMAHelpers.jl index a957a7c..dc12781 100644 --- a/mainMAHelpers.jl +++ b/mainMAHelpers.jl @@ -5,7 +5,7 @@ addToLoadPath!("../MultiAgents.jl") using SocioEconomics: SEVERSION, SEPATH, SESRCPATH -@assert SEVERSION == v"0.1.1" +@assert SEVERSION == v"0.1.2" using SocioEconomics.ParamTypes From 57aa78e2b641bb92ae6636548ba6bb3a93a6e8c3 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 1 Dec 2022 16:03:27 +0000 Subject: [PATCH 2/5] demographydata is part of SE.ParamTypes module and moving loadParameters to SE.handle parameters.jl --- mainHelpers.jl | 92 +++----------------------------------------------- 1 file changed, 4 insertions(+), 88 deletions(-) diff --git a/mainHelpers.jl b/mainHelpers.jl index 78caca6..ac36fd5 100644 --- a/mainHelpers.jl +++ b/mainHelpers.jl @@ -4,12 +4,6 @@ using ArgParse using Utilities -# TODO put into module somewhere? -# Atiyah: Suggestion: as it is related to ParamTypes, it fits there -# or another module for Data (though currently -# not that significant amount of code) -include("$(SESRCPATH)/socioeconomics/demography/demographydata.jl") - include("$(SESRCPATH)/handleParams.jl") include("analysis.jl") @@ -33,14 +27,10 @@ function createDemography!(pars) #ukPopulation = createPopulation(pars.poppars) ukPopulation = createPyramidPopulation(pars.poppars) - # Atiyah: For more DRY code, you may want to consider calling - # loadDemographyData(datapars) - datp = pars.datapars - dir = SEPATH * "/" * datp.datadir - - ukDemoData = loadDemographyData(dir * "/" * datp.fertFName, - dir * "/" * datp.deathFFName, - dir * "/" * datp.deathMFName) + # temporarily solution , input files and command line arguments + # should be invistigated + datp = DataPars() + ukDemoData = loadDemographyData(datp) Model(ukTowns, ukHouses, ukPopulation, ukDemoData.fertility , ukDemoData.deathFemale, ukDemoData.deathMale) @@ -110,85 +100,11 @@ function stepModel!(model, time, simPars, pars) append!(model.pop, babies) end - -function loadParameters(argv, cmdl...) - arg_settings = ArgParseSettings("run simulation", autofix_names=true) - - @add_arg_table! arg_settings begin - "--par-file", "-p" - help = "parameter file" - default = "" - "--par-out-file", "-P" - help = "file name for parameter output" - default = "parameters.run.yaml" - end - - if ! isempty(cmdl) - add_arg_table!(arg_settings, cmdl...) - end - - # setup command line arguments with docs - - add_arg_group!(arg_settings, "Simulation Parameters") - fieldsAsArgs!(arg_settings, SimulationPars) - - for t in fieldtypes(DemographyPars) - groupName = String(nameOfParType(t)) * " Parameters" - add_arg_group!(arg_settings, groupName) - fieldsAsArgs!(arg_settings, t) - end - - # parse command line - args = parse_args(argv, arg_settings, as_symbols=true) - - # read parameters from file if provided or set to default - simpars, pars = loadParametersFromFile(args[:par_file]) - - # override values that were provided on command line - - overrideParsCmdl!(simpars, args) - - @assert typeof(pars) == DemographyPars - for f in fieldnames(DemographyPars) - overrideParsCmdl!(getfield(pars, f), args) - end - - # Atiyah: for more DRY Code, you may consider using - # LPM.ParamTypes.{seed!,reseed0!} within mainHelpers.jl - # and remove the following call & the using statement - # set time dependent seed - if simpars.seed == 0 - simpars.seed = floor(Int, time()) - end - - # keep a record of parameters used (including seed!) - saveParametersToFile(simpars, pars, args[:par_out_file]) - - simpars, pars, args -end - - function setupModel(pars) model = createDemography!(pars) initializeDemography!(model, pars.poppars, pars.workpars, pars.mappars) - #= - Atiyah: this portion is not need any more. But if useful, could be - attached with Logging level. - @show "Town Samples: \n" - @show model.towns[1:10] - println(); println(); - - @show "Houses samples: \n" - @show model.houses[1:10] - println(); println(); - - @show "population samples : \n" - @show model.pop[1:10] - println(); println(); - =# - model end From db6dbbb4e332a712ae731b1c5bdf6cc76c5fd647 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 1 Dec 2022 17:09:20 +0000 Subject: [PATCH 3/5] retain data parameters in input file and command line --- main.jl | 4 ++-- mainGui.jl | 4 ++-- mainHelpers.jl | 9 ++++----- mainMA.jl | 6 +++--- mainMAHelpers.jl | 7 ++++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/main.jl b/main.jl index 8a26b85..b5c5957 100644 --- a/main.jl +++ b/main.jl @@ -5,7 +5,7 @@ using Random include("lpm.jl") # create parameters -const simPars, pars = loadParameters(ARGS) +const simPars, dataPars, pars = loadParameters(ARGS) pars.poppars.initialPop = 500 # Quick ad-hoc adjustment # Atiyah: for more DRY Code, you may consider using @@ -14,7 +14,7 @@ pars.poppars.initialPop = 500 # Quick ad-hoc adjustment Random.seed!(simPars.seed) # create model object -const model = setupModel(pars) +const model = setupModel(dataPars, pars) # like this for CSV output: # const logfile = setupLogging(simPars, FS=",") diff --git a/mainGui.jl b/mainGui.jl index ea34d5a..65f737e 100644 --- a/mainGui.jl +++ b/mainGui.jl @@ -19,10 +19,10 @@ function main(parOverrides...) end # need to do that first, otherwise it blocks the GUI - simPars, pars, args = loadParameters(args, + simPars, datapars, pars, args = loadParameters(args, ["--gui-scale"], Dict(:help => "set gui scale", :default => 1.0, :arg_type => Float64)) - model = setupModel(pars) + model = setupModel(datapars, pars) logfile = setupLogging(simPars) scale = args[:gui_scale] diff --git a/mainHelpers.jl b/mainHelpers.jl index ac36fd5..0fa0e23 100644 --- a/mainHelpers.jl +++ b/mainHelpers.jl @@ -18,7 +18,7 @@ mutable struct Model deathMale :: Matrix{Float64} end -function createDemography!(pars) +function createDemography!(datapars, pars) ukTowns = createTowns(pars.mappars) ukHouses = Vector{PersonHouse}() @@ -29,8 +29,7 @@ function createDemography!(pars) # temporarily solution , input files and command line arguments # should be invistigated - datp = DataPars() - ukDemoData = loadDemographyData(datp) + ukDemoData = loadDemographyData(datapars) Model(ukTowns, ukHouses, ukPopulation, ukDemoData.fertility , ukDemoData.deathFemale, ukDemoData.deathMale) @@ -100,8 +99,8 @@ function stepModel!(model, time, simPars, pars) append!(model.pop, babies) end -function setupModel(pars) - model = createDemography!(pars) +function setupModel(datapars,pars) + model = createDemography!(datapars,pars) initializeDemography!(model, pars.poppars, pars.workpars, pars.mappars) diff --git a/mainMA.jl b/mainMA.jl index d0636b9..bf568da 100644 --- a/mainMA.jl +++ b/mainMA.jl @@ -16,7 +16,7 @@ const mainConfig = Light() # no input files, logging or flags (REPL Exec.) const lpmExample = LPMUKDemography() # remove deads # lpmExample = LPMUKDemographyOpt() # don't remove deads -const simPars, pars = loadParameters(mainConfig) +const simPars, dataPars, pars = loadParameters(mainConfig) # Most significant simulation and model parameters # The following works only with Light() configuration @@ -29,11 +29,11 @@ if mainConfig == Light() pars.poppars.initialPop = 500 end -const model = setupModel(pars) +const model = setupModel(dataPars, pars) const logfile = setupLogging(simPars,mainConfig) -const demoData = loadDemographyData(pars.datapars,SEPATH) +const demoData = loadDemographyData(dataPars) const ukDemography = MAModel(model,pars,demoData) diff --git a/mainMAHelpers.jl b/mainMAHelpers.jl index dc12781..dda6518 100644 --- a/mainMAHelpers.jl +++ b/mainMAHelpers.jl @@ -37,16 +37,17 @@ struct WithInputFiles <: MainSim end # Input parameter files struct Light <: MainSim end # no input files function loadParameters(::WithInputFiles) - simPars, pars = loadParameters(ARGS) + simPars, dataPars, pars = loadParameters(ARGS) seed!(simPars) - simPars, pars + simPars, dataPars, pars end function loadParameters(::Light) simPars = SimulationPars() seed!(simPars) + dataPars = DataPars() pars = DemographyPars() - simPars, pars + simPars, dataPars, pars end setupLogging(simPars,::WithInputFiles) = setupLogging(simPars) From f54516ec365543ee24202411140e94cf53528e49 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 1 Dec 2022 17:50:18 +0000 Subject: [PATCH 4/5] handling parameters is done within SE library --- mainHelpers.jl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mainHelpers.jl b/mainHelpers.jl index 0fa0e23..2a8c0e8 100644 --- a/mainHelpers.jl +++ b/mainHelpers.jl @@ -1,11 +1,5 @@ - -using ArgParse - using Utilities - -include("$(SESRCPATH)/handleParams.jl") - include("analysis.jl") mutable struct Model From 480b8fa0d66b4f1bd3958846f87dc3d74e431abf Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Fri, 2 Dec 2022 09:39:06 +0000 Subject: [PATCH 5/5] Version 0.1.2 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2513818..92187f6 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,4 @@ Releases - **V0.1.0 (28.11.2022)** : The lone parent model (corresponding to LoneParentsModel.jl Version 0.6.1) based on the SocioEconomics.jl package V0.1.0 - V0.1.1 (29.11.2022) : Simplified usage of SocioEconomics Library + - V0.1.2 ( 1.12.2022) : "data parameters" and loading / handling parameters from command line and input files is now part of SE library within ParamTypes module