Skip to content

Commit

Permalink
Merge pull request #5 from MRC-CSO-SPHSU/develop
Browse files Browse the repository at this point in the history
Version 0.1.2
  • Loading branch information
AtiyahElsheikh authored Dec 2, 2022
2 parents 39ad2a1 + 480b8fa commit 262a135
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 109 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lpm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=",")
Expand Down
4 changes: 2 additions & 2 deletions mainGui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
103 changes: 6 additions & 97 deletions mainHelpers.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@

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")

mutable struct Model
Expand All @@ -24,7 +12,7 @@ mutable struct Model
deathMale :: Matrix{Float64}
end

function createDemography!(pars)
function createDemography!(datapars, pars)
ukTowns = createTowns(pars.mappars)

ukHouses = Vector{PersonHouse}()
Expand All @@ -33,14 +21,9 @@ 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
ukDemoData = loadDemographyData(datapars)

Model(ukTowns, ukHouses, ukPopulation,
ukDemoData.fertility , ukDemoData.deathFemale, ukDemoData.deathMale)
Expand Down Expand Up @@ -110,85 +93,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)
function setupModel(datapars,pars)
model = createDemography!(datapars,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

Expand Down
6 changes: 3 additions & 3 deletions mainMA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions mainMAHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 262a135

Please sign in to comment.