From 651d37b6169be9586acabd50e14389ae3768d825 Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Wed, 21 Dec 2022 12:57:37 +0000 Subject: [PATCH 01/33] Version 0.2.5 --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a72902b..0e05336 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ Releases - **V0.2.0 (5.12.2022)** : Unified API of CreateX and Initialize functions (compatible with SE V0.2) - - V0.2.1 (7.12) : - (MALPM only) New Simulation Interface for 3 functions, doBirths!, doDeaths!, doDivorces, Improved API for parameter accessory functions, compatible with SE* Version 0.2.1 - - V0.2.2 (8.12) : - (MALPM only) doMarriages (SE* V0.2.2) - - V0.2.3 (9.12) : - (MALPM only) adoptions, workTransitions, socialTransitions, ageTransitions (SE* V0.2.3) - - V0.2.4 (14.12) : - (MALPM only) adjusting to SimpleABM types of MA Version 0.4, improved model data structure + - V0.2.1 (7.12) : (MALPM only) New Simulation Interface for 3 functions, doBirths!, doDeaths!, doDivorces, Improved API for parameter accessory functions, compatible with SE* Version 0.2.1 + - V0.2.2 (8.12) : (MALPM only) doMarriages (SE* V0.2.2) + - V0.2.3 (9.12) : (MALPM only) adoptions, workTransitions, socialTransitions, ageTransitions (SE* V0.2.3) + - V0.2.4 (14.12) : (MALPM only) adjusting to SimpleABM types of MA Version 0.4, improved model data structure + - V0.2.5 (21.12) : (MALPM only) exploits some tuned simulation functions from SE* V0.2.5 and improved performance (3x faster) From 3fb5062779e38e61ca10e299997a5fd8613001a5 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Wed, 21 Dec 2022 11:30:38 +0000 Subject: [PATCH 02/33] fail attempt --- src/malpm/Models.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/malpm/Models.jl b/src/malpm/Models.jl index 44975b7..90015d9 100644 --- a/src/malpm/Models.jl +++ b/src/malpm/Models.jl @@ -6,7 +6,7 @@ This module is within the MALPM module module Models -using SocioEconomics.XAgents: Town, PersonHouse, Person, alive +using SocioEconomics.XAgents: Town, PersonHouse, PersonTown, Person, alive using SocioEconomics.ParamTypes: DemographyPars, MapPars, DemographyData using MultiAgents: AbstractMABM, SimpleABM @@ -19,14 +19,14 @@ import MultiAgents: allagents export MAModel struct MAModel <: AbstractMABM - towns :: SimpleABM{Town} + towns :: SimpleABM{PersonTown} houses :: SimpleABM{PersonHouse} pop :: SimpleABM{Person} parameters :: DemographyPars data :: DemographyData function MAModel(model,pars,data) - ukTowns = SimpleABM{Town}(model.towns) + ukTowns = SimpleABM{PersonTown}(model.towns) ukHouses = SimpleABM{PersonHouse}(model.houses) ukPopulation = SimpleABM{Person}(model.pop) new(ukTowns,ukHouses,ukPopulation,pars,data) From 7281182deebe7f4ba8d3c7b43cdd2d8c3ea255e9 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Sat, 24 Dec 2022 12:06:27 +0000 Subject: [PATCH 03/33] version 0.2.6 --- lpm.jl | 2 +- mainMAHelpers.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lpm.jl b/lpm.jl index 56138c2..67ba7e4 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.2.5" +@assert SEVERSION == v"0.2.6" using SocioEconomicsX.ParamTypes diff --git a/mainMAHelpers.jl b/mainMAHelpers.jl index c842eb8..fe0e110 100644 --- a/mainMAHelpers.jl +++ b/mainMAHelpers.jl @@ -5,7 +5,7 @@ addToLoadPath!("../MultiAgents.jl") using SocioEconomics: SEVERSION, SEPATH, SESRCPATH -@assert SEVERSION == v"0.2.5" +@assert SEVERSION == v"0.2.6" using SocioEconomics.ParamTypes From 7c8ea59ac6af99ddcd117d79a141e1550f4773ab Mon Sep 17 00:00:00 2001 From: Atiyah Date: Sat, 24 Dec 2022 12:07:29 +0000 Subject: [PATCH 04/33] only inhabited towns no empty pnes --- mainHelpers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainHelpers.jl b/mainHelpers.jl index 8c33b9a..3dc02c2 100644 --- a/mainHelpers.jl +++ b/mainHelpers.jl @@ -11,7 +11,7 @@ mutable struct Model end function createDemography!(datapars, pars) - ukTowns = createTowns(pars) + ukTowns = create_inhabited_towns(pars) ukHouses = Vector{PersonHouse}() From 76f7da7a6806503f160e20928c271a9af6ff50b7 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Sat, 24 Dec 2022 12:07:56 +0000 Subject: [PATCH 05/33] currently only doDeaths! --- src/malpm/demography/SimSetup.jl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/demography/SimSetup.jl index 843ce83..2035889 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/demography/SimSetup.jl @@ -27,7 +27,6 @@ is provided here @return dictionary of required simulation parameters """ - function setupCommon!(sim::AbstractABMSimulator) verbose(sim) ? setVerbose!() : unsetVerbose!() @@ -36,20 +35,20 @@ function setupCommon!(sim::AbstractABMSimulator) ignoreAssumptions!() attach_post_model_step!(sim,doDeaths!) - attach_post_model_step!(sim,doAssignGuardians!) - attach_post_model_step!(sim,doBirths!) - attach_post_model_step!(sim,doAgeTransitions!) + #attach_post_model_step!(sim,doAssignGuardians!) + #attach_post_model_step!(sim,doBirths!) + #=attach_post_model_step!(sim,doAgeTransitions!) attach_post_model_step!(sim,doWorkTransitions!) - attach_post_model_step!(sim,doSocialTransitions!) - attach_post_model_step!(sim,doDivorces!) - attach_post_model_step!(sim,doMarriages!) + attach_post_model_step!(sim,doSocialTransitions!)=# + #attach_post_model_step!(sim,doDivorces!) + #attach_post_model_step!(sim,doMarriages!) nothing end "set up simulation functions where dead people are removed" function setup!(sim::AbstractABMSimulator, example::LPMUKDemography) # attach_pre_model_step!(sim,population_step!) - #attach_agent_step!(sim,agestep!) + attach_agent_step!(sim,agestep!) setupCommon!(sim) nothing @@ -57,7 +56,7 @@ end function setup!(sim::AbstractABMSimulator,example::LPMUKDemographyOpt) - # attach_agent_step!(sim,agestepAlivePerson!) + attach_agent_step!(sim,agestepAlivePerson!) setupCommon!(sim) nothing From 5e4c0b6460115ada97766da3a8635b3185e5893f Mon Sep 17 00:00:00 2001 From: Atiyah Date: Sun, 25 Dec 2022 14:30:53 +0000 Subject: [PATCH 06/33] Implemeenting additional API functions for model modifications --- src/malpm/Models.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/malpm/Models.jl b/src/malpm/Models.jl index 90015d9..67383ba 100644 --- a/src/malpm/Models.jl +++ b/src/malpm/Models.jl @@ -8,11 +8,12 @@ module Models using SocioEconomics.XAgents: Town, PersonHouse, PersonTown, Person, alive using SocioEconomics.ParamTypes: DemographyPars, MapPars, DemographyData -using MultiAgents: AbstractMABM, SimpleABM +using MultiAgents: AbstractMABM, SimpleABM +using MultiAgents: add_agent!, kill_agent_at_opt! import SocioEconomics.API.ParamFunc: populationParameters, birthParameters, divorceParameters, marriageParameters, workParameters, allParameters -import SocioEconomics.API.ModelFunc: allPeople, alivePeople, dataOf, houses, towns +import SocioEconomics.API.ModelFunc: allPeople, alivePeople, dataOf, houses, towns, add_person!, add_house!, remove_person! import MultiAgents: allagents @@ -42,6 +43,9 @@ houses(model::MAModel) = allagents(model.houses) towns(model::MAModel) = allagents(model.towns) #dataOf(model) = model.pop.data dataOf(model) = model.data +add_person!(model, person) = add_agent!(model.pop, person) +remove_person!(model, personidx::Int) = kill_agent_at_opt!(personidx, model.pop) +add_house!(model, house) = add_agent!(model.houses, house) allParameters(model::MAModel) = model.parameters From 68500e27a203e1f65339887ea9a0e4f24e62f8ac Mon Sep 17 00:00:00 2001 From: Atiyah Date: Sun, 25 Dec 2022 14:32:48 +0000 Subject: [PATCH 07/33] tuned till doDivorce .. improved memory storage ~ 1000% --- src/malpm/demography/SimSetup.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/demography/SimSetup.jl index 2035889..f849429 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/demography/SimSetup.jl @@ -36,11 +36,11 @@ function setupCommon!(sim::AbstractABMSimulator) attach_post_model_step!(sim,doDeaths!) #attach_post_model_step!(sim,doAssignGuardians!) - #attach_post_model_step!(sim,doBirths!) + attach_post_model_step!(sim,doBirths!) #=attach_post_model_step!(sim,doAgeTransitions!) attach_post_model_step!(sim,doWorkTransitions!) attach_post_model_step!(sim,doSocialTransitions!)=# - #attach_post_model_step!(sim,doDivorces!) + attach_post_model_step!(sim,doDivorces!) #attach_post_model_step!(sim,doMarriages!) nothing end From 8c175a5eabb1566b58ddbabb85926529306d8a4e Mon Sep 17 00:00:00 2001 From: Atiyah Date: Tue, 27 Dec 2022 10:46:54 +0000 Subject: [PATCH 08/33] +1 accessory function --- src/malpm/Models.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/malpm/Models.jl b/src/malpm/Models.jl index 67383ba..4715762 100644 --- a/src/malpm/Models.jl +++ b/src/malpm/Models.jl @@ -12,7 +12,7 @@ using MultiAgents: AbstractMABM, SimpleABM using MultiAgents: add_agent!, kill_agent_at_opt! import SocioEconomics.API.ParamFunc: populationParameters, birthParameters, divorceParameters, - marriageParameters, workParameters, allParameters + marriageParameters, workParameters, allParameters, mapParameters import SocioEconomics.API.ModelFunc: allPeople, alivePeople, dataOf, houses, towns, add_person!, add_house!, remove_person! import MultiAgents: allagents @@ -54,5 +54,6 @@ birthParameters(model::MAModel) = model.parameters.birthpars divorceParameters(model::MAModel) = model.parameters.divorcepars marriageParameters(model::MAModel) = model.parameters.marriagepars workParameters(model::MAModel) = model.parameters.workpars +mapParameters(model::MAModel) = model.parameters.mappars end # module Models \ No newline at end of file From 4c4000e6c9f6b341d4b9d064b39e0a85568578c2 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Tue, 27 Dec 2022 10:47:28 +0000 Subject: [PATCH 09/33] complete model specification --- src/malpm/demography/SimSetup.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/demography/SimSetup.jl index f849429..4528b21 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/demography/SimSetup.jl @@ -35,20 +35,20 @@ function setupCommon!(sim::AbstractABMSimulator) ignoreAssumptions!() attach_post_model_step!(sim,doDeaths!) - #attach_post_model_step!(sim,doAssignGuardians!) + attach_post_model_step!(sim,doAssignGuardians!) attach_post_model_step!(sim,doBirths!) - #=attach_post_model_step!(sim,doAgeTransitions!) + attach_post_model_step!(sim,doAgeTransitions!) attach_post_model_step!(sim,doWorkTransitions!) - attach_post_model_step!(sim,doSocialTransitions!)=# + attach_post_model_step!(sim,doSocialTransitions!) attach_post_model_step!(sim,doDivorces!) - #attach_post_model_step!(sim,doMarriages!) + attach_post_model_step!(sim,doMarriages!) nothing end "set up simulation functions where dead people are removed" function setup!(sim::AbstractABMSimulator, example::LPMUKDemography) # attach_pre_model_step!(sim,population_step!) - attach_agent_step!(sim,agestep!) + #attach_agent_step!(sim,agestep!) setupCommon!(sim) nothing @@ -56,7 +56,7 @@ end function setup!(sim::AbstractABMSimulator,example::LPMUKDemographyOpt) - attach_agent_step!(sim,agestepAlivePerson!) + #attach_agent_step!(sim,agestepAlivePerson!) setupCommon!(sim) nothing From b88a8b111ee5644e91db6b8d4a2d136c2c049d47 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Tue, 27 Dec 2022 10:53:07 +0000 Subject: [PATCH 10/33] adjust to the newly domarriages function --- src/malpm/demography/Simulate.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/malpm/demography/Simulate.jl b/src/malpm/demography/Simulate.jl index 6041245..3c68e69 100644 --- a/src/malpm/demography/Simulate.jl +++ b/src/malpm/demography/Simulate.jl @@ -11,9 +11,9 @@ using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt using SocioEconomics using SocioEconomics.API.Traits: FullPopulation, NoReturn import SocioEconomics.Specification.SimulateNew: dodeaths!, dobirths!, - dodivorces!, + dodivorces!, domarriages!, doAgeTransitions!, doWorkTransitions!, doSocialTransitions!, - doMarriages!, doAssignGuardians! + doAssignGuardians! function doDeaths!(model::AbstractMABM, sim::AbstractABMSimulator, ::LPMUKDemography) @@ -27,7 +27,7 @@ function doDeaths!(model::AbstractMABM, sim::AbstractABMSimulator, ::LPMUKDemogr end # function doDeaths! function doDeaths!(model, sim, ::LPMUKDemographyOpt) - dodeaths!(model,currstep(sim),FullPopulation()) + dodeaths!(model,currstep(sim),FullPopulation(),NoReturn()) nothing end # function doDeaths! @@ -46,18 +46,18 @@ function doBirths!(model, sim, example) end _dodivorces!(model,sim,::LPMUKDemography) = dodivorces!(model, currstep(sim)) -_dodivorces!(model,sim,::LPMUKDemographyOpt) = dodivorces!(model, currstep(sim),FullPopulation()) +_dodivorces!(model,sim,::LPMUKDemographyOpt) = dodivorces!(model, currstep(sim),FullPopulation(), NoReturn()) function doDivorces!(model, sim, example) _dodivorces!(model, sim, example) nothing end +_domarriages!(model,sim,::LPMUKDemography) = domarriages!(model, currstep(sim)) +_domarriages!(model,sim,::LPMUKDemographyOpt) = domarriages!(model, currstep(sim),FullPopulation(), NoReturn()) function doMarriages!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) - - doMarriages!(model, currstep(sim)) - + _domarriages!(model, sim,example) nothing end From e891f375fef776f5c416c1c0dcba023d928b0630 Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Tue, 27 Dec 2022 11:24:21 +0000 Subject: [PATCH 11/33] Version 0.2.6 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0e05336..5ec5f3b 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,4 @@ Releases - V0.2.3 (9.12) : (MALPM only) adoptions, workTransitions, socialTransitions, ageTransitions (SE* V0.2.3) - V0.2.4 (14.12) : (MALPM only) adjusting to SimpleABM types of MA Version 0.4, improved model data structure - V0.2.5 (21.12) : (MALPM only) exploits some tuned simulation functions from SE* V0.2.5 and improved performance (3x faster) + - V0.2.6 (27.12) : (MALPM only) Improved implementation of allocation algorithms (no temporary arrays), tuned do marriage algorithm (memoization can be avoided) & Improved runtime performance (3x faster & 4x less memory allocation and storage w.r.t. V0.2.5) From 9cfd2ebe5fdfbf6bfdc9f9ac13cea0177fd2b656 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 5 Jan 2023 11:41:22 +0000 Subject: [PATCH 12/33] equivalent step functions calling x rather than dox --- src/malpm/demography/SimSetup.jl | 78 ++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 20 deletions(-) diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/demography/SimSetup.jl index 4528b21..cb68585 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/demography/SimSetup.jl @@ -1,9 +1,10 @@ module SimSetup - +using Memoization using MALPM.Demography.Population: removeDead!, agestepAlivePerson!, agestep!, population_step! +using MALPM.Models: MAModel, allPeople, birthParameters using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt using MALPM.Demography.Simulate: doDeaths!, doBirths!, @@ -12,53 +13,90 @@ using MALPM.Demography.Simulate: doDeaths!, doBirths!, using MultiAgents: AbstractABMSimulator using MultiAgents: attach_pre_model_step!, attach_post_model_step!, - attach_agent_step! + attach_agent_step!, currstep using SocioEconomics.Utilities: setVerbose!, unsetVerbose!, setDelay!, - checkAssumptions!, ignoreAssumptions! + checkAssumptions!, ignoreAssumptions!, date2yearsmonths +using SocioEconomics.XAgents: age, isMale, isFemale, isSingle, alive, hasDependents +using SocioEconomics.API.Traits: FullPopulation +using SocioEconomics.Specification.SimulateNew: death!, birth!, divorce!, marriage! + +import SocioEconomics.API.ModelFunc: share_childless_men, eligible_women import MultiAgents: setup!, verbose export setup! -""" -set simulation paramters @return dictionary of symbols to values - -All information needed by the generic Simulators.run! function -is provided here - -@return dictionary of required simulation parameters -""" - function setupCommon!(sim::AbstractABMSimulator) verbose(sim) ? setVerbose!() : unsetVerbose!() setDelay!(sim.parameters.sleeptime) sim.parameters.checkassumption ? checkAssumptions!() : ignoreAssumptions!() - + attach_post_model_step!(sim,doDeaths!) - attach_post_model_step!(sim,doAssignGuardians!) attach_post_model_step!(sim,doBirths!) + attach_post_model_step!(sim,doAssignGuardians!) attach_post_model_step!(sim,doAgeTransitions!) attach_post_model_step!(sim,doWorkTransitions!) attach_post_model_step!(sim,doSocialTransitions!) - attach_post_model_step!(sim,doDivorces!) attach_post_model_step!(sim,doMarriages!) + nothing end +_popfeature(::LPMUKDemography) = FullPopulation() +_popfeature(::LPMUKDemographyOpt) = AlivePopulation() + +deathstep!(person, model, sim, example) = + death!(person, currstep(sim),model,_popfeature(example)) + +birthstep!(person, model, sim, example) = + birth!(person, currstep(sim),model,_popfeature(example)) + +divorcestep!(person, model, sim, example) = + divorce!(person, currstep(sim), model, _popfeature(example)) + +marriagestep!(person, model, sim, example) = + marriage!(person, currstep(sim), model, _popfeature(example)) + +_ageclass(person) = trunc(Int, age(person)/10) +@memoize Dict function share_childless_men(model::MAModel, ageclass :: Int) + nAll = 0 + nNoC = 0 + for p in Iterators.filter(x->alive(x) && isMale(x) && _ageclass(x) == ageclass, allPeople(model)) + nAll += 1 + if !hasDependents(p) + nNoC += 1 + end + end + return nNoC / nAll +end + +@memoize eligible_women(model::MAModel) = + [f for f in allPeople(model) if isFemale(f) && alive(f) && + isSingle(f) && age(f) > birthParameters(model).minPregnancyAge] + +function reset_cache_marriages(model,sim,::LPMUKDemography) + #@info "cache reset at $(date2yearsmonths(currstep(sim)))" + Memoization.empty_cache!(share_childless_men) + Memoization.empty_cache!(eligible_women) +end + "set up simulation functions where dead people are removed" function setup!(sim::AbstractABMSimulator, example::LPMUKDemography) # attach_pre_model_step!(sim,population_step!) - #attach_agent_step!(sim,agestep!) + # attach_pre_model_step!(sim,reset_cache_marriages) + # attach_agent_step!(sim,agestepAlivePerson!) + # attach_agent_step!(sim,deathstep!) this leads to excessive memory allocation and memory storage + # attach_agent_step!(sim,birthstep!) this leads to excessive memory allocation and memory storage + attach_agent_step!(sim,divorcestep!) + # attach_agent_step!(sim,marriagestep!) # does not seem to work properly (may be due to memoization) setupCommon!(sim) - nothing end - function setup!(sim::AbstractABMSimulator,example::LPMUKDemographyOpt) - #attach_agent_step!(sim,agestepAlivePerson!) + # attach_agent_step!(sim,agestep!) + attach_post_model_step!(sim,doDivorces!) setupCommon!(sim) - nothing end From 50c50508b423342f3bab565cefa641204f39fc26 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 5 Jan 2023 11:41:41 +0000 Subject: [PATCH 13/33] tuning --- src/malpm/demography/Simulate.jl | 72 +++++++++++++++++--------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/malpm/demography/Simulate.jl b/src/malpm/demography/Simulate.jl index 3c68e69..16b763e 100644 --- a/src/malpm/demography/Simulate.jl +++ b/src/malpm/demography/Simulate.jl @@ -9,55 +9,65 @@ using MultiAgents: add_agent!, currstep using MALPM.Demography.Population: removeDead! using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt using SocioEconomics -using SocioEconomics.API.Traits: FullPopulation, NoReturn +using SocioEconomics.XAgents: Person +using SocioEconomics.API.Traits: FullPopulation, SimProcess, Death, Birth, Marriage +using SocioEconomics.Utilities: date2yearsmonths import SocioEconomics.Specification.SimulateNew: dodeaths!, dobirths!, dodivorces!, domarriages!, doAgeTransitions!, doWorkTransitions!, doSocialTransitions!, doAssignGuardians! - - -function doDeaths!(model::AbstractMABM, sim::AbstractABMSimulator, ::LPMUKDemography) - # (; deadsind) = dodeaths!(model,currstep(sim)) - # ToDo separate step? - # for ind in Iterators.reverse(deadsind) - # removeDead!(ind,model.pop) - # end - dodeaths!(model, currstep(sim)) - nothing -end # function doDeaths! + + +const retDeath = Person[] -function doDeaths!(model, sim, ::LPMUKDemographyOpt) - dodeaths!(model,currstep(sim),FullPopulation(),NoReturn()) +_init_return(::LPMUKDemographyOpt,::SimProcess) = 0 +_init_return(::LPMUKDemography,::Death) = retDeath + +_dodeaths!(ret,model,time,::LPMUKDemography) = dodeaths!(model,time,FullPopulation(),ret) +_dodeaths!(ret,model,time,::LPMUKDemographyOpt) = dodeaths!(model,time,ret) + +function doDeaths!(model, sim, example) + ret = _init_return(example,Death()) + ret = _dodeaths!(ret, model, currstep(sim), example) + #=years, months = date2yearsmonths(currstep(sim)) + @info "# of deaths $(years) $(months+1) : $(length(ret.people))"=# nothing end # function doDeaths! -_dobirths!(model,sim,::LPMUKDemography) = dobirths!(model, currstep(sim)) -_dobirths!(model,sim,::LPMUKDemographyOpt) = - dobirths!(model, currstep(sim),FullPopulation(),NoReturn()) +const retBirth = Person[] +_init_return(::LPMUKDemography,::Birth) = retBirth + +_dobirths!(ret,model,sim,::LPMUKDemographyOpt) = dobirths!(model, currstep(sim), ret) +_dobirths!(ret,model,sim,::LPMUKDemography) = + dobirths!(model, currstep(sim), FullPopulation(),ret) function doBirths!(model, sim, example) - #(;babies) = _dobirths!(model, sim, example) - # TODO separate step? - # for baby in babies - # add_agent!(model.pop,baby) - #end - _dobirths!(model, sim, example) + ret = _init_return(example,Birth()) + ret = _dobirths!(ret,model, sim, example) nothing end -_dodivorces!(model,sim,::LPMUKDemography) = dodivorces!(model, currstep(sim)) -_dodivorces!(model,sim,::LPMUKDemographyOpt) = dodivorces!(model, currstep(sim),FullPopulation(), NoReturn()) +const retBirth = Person[] +_init_return(::LPMUKDemography,::Birth) = retBirth + +_dodivorces!(ret,model,sim,::LPMUKDemographyOpt) = dodivorces!(model, currstep(sim), ret) +_dodivorces!(ret,model,sim,::LPMUKDemography) = dodivorces!(model, currstep(sim),FullPopulation(),ret) function doDivorces!(model, sim, example) - _dodivorces!(model, sim, example) + ret = _init_return(example, Birth()) + ret = _dodivorces!(ret, model, sim, example) nothing end -_domarriages!(model,sim,::LPMUKDemography) = domarriages!(model, currstep(sim)) -_domarriages!(model,sim,::LPMUKDemographyOpt) = domarriages!(model, currstep(sim),FullPopulation(), NoReturn()) +_domarriages!(ret,model,sim,::LPMUKDemographyOpt) = domarriages!(model, currstep(sim)) +_domarriages!(ret,model,sim,::LPMUKDemography) = domarriages!(model, currstep(sim),FullPopulation(), ret) + +const retMarriage = Person[] +_init_return(::LPMUKDemography,::Marriage) = retMarriage function doMarriages!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) - _domarriages!(model, sim,example) + ret = _init_return(example, Marriage()) + _domarriages!(ret,model, sim,example) nothing end @@ -91,8 +101,4 @@ function doSocialTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, ex nothing end - - - - end # Simulate \ No newline at end of file From e1c55261cffaba163ae1248b59fee21a29b2d76c Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 5 Jan 2023 11:41:50 +0000 Subject: [PATCH 14/33] V 0.2.7 --- mainMAHelpers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainMAHelpers.jl b/mainMAHelpers.jl index fe0e110..ce733df 100644 --- a/mainMAHelpers.jl +++ b/mainMAHelpers.jl @@ -5,7 +5,7 @@ addToLoadPath!("../MultiAgents.jl") using SocioEconomics: SEVERSION, SEPATH, SESRCPATH -@assert SEVERSION == v"0.2.6" +@assert SEVERSION == v"0.2.7" using SocioEconomics.ParamTypes From de961bcddb9c8a7a23c5971e51e62a17868d169e Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 5 Jan 2023 11:42:17 +0000 Subject: [PATCH 15/33] cleaning comment --- src/malpm/Models.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/malpm/Models.jl b/src/malpm/Models.jl index 4715762..a32fe8b 100644 --- a/src/malpm/Models.jl +++ b/src/malpm/Models.jl @@ -41,13 +41,11 @@ alivePeople(model::MAModel) = # Iterators.filter(person->alive(person),people) # Iterators did not show significant value sofar houses(model::MAModel) = allagents(model.houses) towns(model::MAModel) = allagents(model.towns) -#dataOf(model) = model.pop.data dataOf(model) = model.data add_person!(model, person) = add_agent!(model.pop, person) remove_person!(model, personidx::Int) = kill_agent_at_opt!(personidx, model.pop) add_house!(model, house) = add_agent!(model.houses, house) - allParameters(model::MAModel) = model.parameters populationParameters(model::MAModel) = model.parameters.poppars birthParameters(model::MAModel) = model.parameters.birthpars From a1fcd933b86df61b95a038cf5ca0a0b0c3a28231 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Thu, 5 Jan 2023 11:46:32 +0000 Subject: [PATCH 16/33] tuning example naming conventions --- mainMA.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mainMA.jl b/mainMA.jl index 1e023ef..427750a 100644 --- a/mainMA.jl +++ b/mainMA.jl @@ -18,8 +18,8 @@ using MALPM.Demography: LPMUKDemography, LPMUKDemographyOpt const mainConfig = Light() # no input files, logging or flags (REPL Exec.) # mainConfig = WithInputFiles() -lpmExample = LPMUKDemography() # remove deads -# lpmExample = LPMUKDemographyOpt() # don't remove deads +lpmExample = LPMUKDemography() # don't remove deads +# lpmExample = LPMUKDemographyOpt() # remove deads const simPars, dataPars, pars = loadParameters(mainConfig) @@ -28,9 +28,9 @@ const simPars, dataPars, pars = loadParameters(mainConfig) # useful when executing from REPL if mainConfig == Light() simPars.seed = 0; seed!(simPars) - simPars.verbose = false + simPars.verbose = false simPars.checkassumption = false - simPars.sleeptime = 0 + simPars.sleeptime = 0 pars.poppars.initialPop = 500 end From c476b7e27adef07f31a19ccf635aba8d67b7e0ce Mon Sep 17 00:00:00 2001 From: Atiyah Date: Fri, 6 Jan 2023 10:57:40 +0000 Subject: [PATCH 17/33] Optimized simulation is the default --- mainMA.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mainMA.jl b/mainMA.jl index 427750a..c092587 100644 --- a/mainMA.jl +++ b/mainMA.jl @@ -18,8 +18,8 @@ using MALPM.Demography: LPMUKDemography, LPMUKDemographyOpt const mainConfig = Light() # no input files, logging or flags (REPL Exec.) # mainConfig = WithInputFiles() -lpmExample = LPMUKDemography() # don't remove deads -# lpmExample = LPMUKDemographyOpt() # remove deads +# lpmExample = LPMUKDemography() # don't remove deads +lpmExample = LPMUKDemographyOpt() # remove deads const simPars, dataPars, pars = loadParameters(mainConfig) @@ -31,7 +31,7 @@ if mainConfig == Light() simPars.verbose = false simPars.checkassumption = false simPars.sleeptime = 0 - pars.poppars.initialPop = 500 + pars.poppars.initialPop = 5000 end const model = setupModel(dataPars, pars) From 29a047805b7d9897dade5c944dd92a0864cb2087 Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Fri, 6 Jan 2023 11:08:08 +0000 Subject: [PATCH 18/33] Version 0.2.7 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5ec5f3b..dea63ab 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,4 @@ Releases - V0.2.4 (14.12) : (MALPM only) adjusting to SimpleABM types of MA Version 0.4, improved model data structure - V0.2.5 (21.12) : (MALPM only) exploits some tuned simulation functions from SE* V0.2.5 and improved performance (3x faster) - V0.2.6 (27.12) : (MALPM only) Improved implementation of allocation algorithms (no temporary arrays), tuned do marriage algorithm (memoization can be avoided) & Improved runtime performance (3x faster & 4x less memory allocation and storage w.r.t. V0.2.5) + - V0.2.7 (6.1.2023) : (MALPM only) Memoization with domarriage alg can be done only externally (if desired). Employing newly tuned and exact API of four simulation functions. Optimized simulation (with deads removal) vs. normal simulation (without deads removal) From 112e53e6b9d8083dec0a1811ee7229f9b1f9504f Mon Sep 17 00:00:00 2001 From: Atiyah Date: Sun, 8 Jan 2023 21:25:09 +0000 Subject: [PATCH 19/33] Version 0.2.8 --- mainMAHelpers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainMAHelpers.jl b/mainMAHelpers.jl index e74227b..1056210 100644 --- a/mainMAHelpers.jl +++ b/mainMAHelpers.jl @@ -5,7 +5,7 @@ addToLoadPath!("../MultiAgents.jl") using SocioEconomics: SEVERSION, SEPATH, SESRCPATH -@assert SEVERSION == v"0.2.7" +@assert SEVERSION == v"0.2.8" using SocioEconomics.ParamTypes using SocioEconomics.XAgents From be81b757e1ef41929aa17bc0fc51e563f55ef712 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Sun, 8 Jan 2023 21:25:52 +0000 Subject: [PATCH 20/33] employing tuned-API of assigning guardians --- src/malpm/demography/SimSetup.jl | 9 +++++++-- src/malpm/demography/Simulate.jl | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/demography/SimSetup.jl index 00a3258..ed049f2 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/demography/SimSetup.jl @@ -18,7 +18,7 @@ using SocioEconomics.Utilities: setVerbose!, unsetVerbose!, setDelay!, checkAssumptions!, ignoreAssumptions!, date2yearsmonths using SocioEconomics.XAgents: age, isMale, isFemale, isSingle, alive, hasDependents using SocioEconomics.API.Traits: FullPopulation -using SocioEconomics.Specification.SimulateNew: death!, birth!, divorce!, marriage! +using SocioEconomics.Specification.SimulateNew: death!, birth!, divorce!, marriage!, assign_guardian! import SocioEconomics.API.ModelFunc: share_childless_men, eligible_women import MultiAgents: setup!, verbose @@ -32,8 +32,8 @@ function setupCommon!(sim::AbstractABMSimulator) ignoreAssumptions!() attach_post_model_step!(sim,doDeaths!) - attach_post_model_step!(sim,doBirths!) attach_post_model_step!(sim,doAssignGuardians!) + attach_post_model_step!(sim,doBirths!) attach_post_model_step!(sim,doAgeTransitions!) attach_post_model_step!(sim,doWorkTransitions!) attach_post_model_step!(sim,doSocialTransitions!) @@ -57,6 +57,9 @@ divorcestep!(person, model, sim, example) = marriagestep!(person, model, sim, example) = marriage!(person, currstep(sim), model, _popfeature(example)) +assign_guardian_step!(person, model, sim, example) = + assign_guardian!(person, currstep(sim), model, _popfeature(example)) + _ageclass(person) = trunc(Int, age(person)/10) @memoize Dict function share_childless_men(model::MAModel, ageclass :: Int) nAll = 0 @@ -87,6 +90,7 @@ function setup!(sim::AbstractABMSimulator, example::LPMUKDemography) # attach_agent_step!(sim,agestepAlivePerson!) # attach_agent_step!(sim,deathstep!) this leads to excessive memory allocation and memory storage # attach_agent_step!(sim,birthstep!) this leads to excessive memory allocation and memory storage + #attach_agent_step!(sim,assign_guardian_step!) attach_agent_step!(sim,divorcestep!) # attach_agent_step!(sim,marriagestep!) # does not seem to work properly (may be due to memoization) setupCommon!(sim) @@ -95,6 +99,7 @@ end function setup!(sim::AbstractABMSimulator,example::LPMUKDemographyOpt) # attach_agent_step!(sim,agestep!) + #attach_post_model_step!(sim,doAssignGuardians!) attach_post_model_step!(sim,doDivorces!) setupCommon!(sim) nothing diff --git a/src/malpm/demography/Simulate.jl b/src/malpm/demography/Simulate.jl index 35aa852..8922cdc 100644 --- a/src/malpm/demography/Simulate.jl +++ b/src/malpm/demography/Simulate.jl @@ -10,12 +10,11 @@ using MALPM.Demography.Population: removeDead! using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt using SocioEconomics using SocioEconomics.XAgents: Person -using SocioEconomics.API.Traits: FullPopulation, SimProcess, Death, Birth, Marriage +using SocioEconomics.API.Traits: FullPopulation, SimProcess, Death, Birth, Marriage, AssignGuardian using SocioEconomics.Utilities: date2yearsmonths import SocioEconomics.Specification.SimulateNew: dodeaths!, dobirths!, - dodivorces!, domarriages!, - doAgeTransitions!, doWorkTransitions!, doSocialTransitions!, - doAssignGuardians! + dodivorces!, domarriages!, do_assign_guardians!, + doAgeTransitions!, doWorkTransitions!, doSocialTransitions! const retDeath = Person[] _init_return(::LPMUKDemographyOpt,::SimProcess) = 0 @@ -69,11 +68,17 @@ function doMarriages!(model::AbstractMABM, sim::AbstractABMSimulator, example::D nothing end +_do_assign_guardians!(ret,model,sim,::LPMUKDemographyOpt) = + do_assign_guardians!(model, currstep(sim), ret) +_do_assign_guardians!(ret,model,sim,::LPMUKDemography) = + do_assign_guardians!(model, currstep(sim), FullPopulation(), ret) -function doAssignGuardians!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) - - doAssignGuardians!(model, currstep(sim)) +const retAGuarians = Person[] +_init_return(::LPMUKDemography,::AssignGuardian) = retAGuarians +function doAssignGuardians!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) + ret = _init_return(example, AssignGuardian()) + _do_assign_guardians!(ret,model,sim,example) nothing end From de572a56e6d1970b1a14ecad1c6c9a7d0c5baf6f Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Sun, 8 Jan 2023 21:28:56 +0000 Subject: [PATCH 21/33] Version 0.2.8 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d7a8d70..33b7e0a 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,5 @@ Releases - V0.2.5 (21.12) : (MALPM only) exploits some tuned simulation functions from SE* V0.2.5 and improved performance (3x faster) - V0.2.6 (27.12) : (MALPM only) Improved implementation of allocation algorithms (no temporary arrays), tuned do marriage algorithm (memoization can be avoided) & Improved runtime performance (3x faster & 4x less memory allocation and storage w.r.t. V0.2.5) - V0.2.7 (6.1.2023) : (MALPM only) Memoization with domarriage alg can be done only externally (if desired). Employing newly tuned and exact API of four simulation functions. Optimized simulation (with deads removal) vs. normal simulation (without deads removal) + - V0.2.8 (8.1.2023) : (MALPM only) employing tuned API of assigning guardians From 5182ed7c1fc01154869673c9751205e20a5c71f6 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Mon, 9 Jan 2023 22:26:07 +0000 Subject: [PATCH 22/33] Version 0.3 --- mainMAHelpers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainMAHelpers.jl b/mainMAHelpers.jl index 1056210..341e7b2 100644 --- a/mainMAHelpers.jl +++ b/mainMAHelpers.jl @@ -5,7 +5,7 @@ addToLoadPath!("../MultiAgents.jl") using SocioEconomics: SEVERSION, SEPATH, SESRCPATH -@assert SEVERSION == v"0.2.8" +@assert SEVERSION == v"0.3" using SocioEconomics.ParamTypes using SocioEconomics.XAgents From e1484f14439ca91aef0fc848140f1dab2ff64898 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Tue, 10 Jan 2023 10:46:10 +0000 Subject: [PATCH 23/33] code tuning / reduction + employing new do_age_transition --- src/malpm/demography/Simulate.jl | 50 ++++++++++++-------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/src/malpm/demography/Simulate.jl b/src/malpm/demography/Simulate.jl index 8922cdc..67e3862 100644 --- a/src/malpm/demography/Simulate.jl +++ b/src/malpm/demography/Simulate.jl @@ -10,22 +10,25 @@ using MALPM.Demography.Population: removeDead! using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt using SocioEconomics using SocioEconomics.XAgents: Person -using SocioEconomics.API.Traits: FullPopulation, SimProcess, Death, Birth, Marriage, AssignGuardian +using SocioEconomics.API.Traits: FullPopulation, AlivePopulation, + SimProcess, Death, Birth, Marriage, + AssignGuardian, AgeTransition using SocioEconomics.Utilities: date2yearsmonths import SocioEconomics.Specification.SimulateNew: dodeaths!, dobirths!, - dodivorces!, domarriages!, do_assign_guardians!, - doAgeTransitions!, doWorkTransitions!, doSocialTransitions! + dodivorces!, domarriages!, do_assign_guardians!, do_age_transitions!, + doWorkTransitions!, doSocialTransitions! + +_popfeature(::LPMUKDemography) = FullPopulation() +_popfeature(::LPMUKDemographyOpt) = AlivePopulation() -const retDeath = Person[] _init_return(::LPMUKDemographyOpt,::SimProcess) = 0 -_init_return(::LPMUKDemography,::Death) = retDeath -_dodeaths!(ret,model,time,::LPMUKDemography) = dodeaths!(model,time,FullPopulation(),ret) -_dodeaths!(ret,model,time,::LPMUKDemographyOpt) = dodeaths!(model,time,ret) +const retDeath = Person[] +_init_return(::LPMUKDemography,::Death) = retDeath function doDeaths!(model, sim, example) ret = _init_return(example,Death()) - ret = _dodeaths!(ret, model, currstep(sim), example) + ret = dodeaths!(model,currstep(sim),_popfeature(example),ret) #=years, months = date2yearsmonths(currstep(sim)) @info "# of deaths $(years) $(months+1) : $(length(ret.people))"=# nothing @@ -34,59 +37,44 @@ end # function doDeaths! const retBirth = Person[] _init_return(::LPMUKDemography,::Birth) = retBirth -_dobirths!(ret,model,sim,::LPMUKDemographyOpt) = dobirths!(model, currstep(sim), ret) -_dobirths!(ret,model,sim,::LPMUKDemography) = - dobirths!(model, currstep(sim), FullPopulation(),ret) - function doBirths!(model, sim, example) ret = _init_return(example,Birth()) - ret = _dobirths!(ret,model, sim, example) + ret = dobirths!(model,currstep(sim),_popfeature(example),ret) nothing end const retBirth = Person[] _init_return(::LPMUKDemography,::Birth) = retBirth -_dodivorces!(ret,model,sim,::LPMUKDemographyOpt) = dodivorces!(model, currstep(sim), ret) -_dodivorces!(ret,model,sim,::LPMUKDemography) = dodivorces!(model, currstep(sim),FullPopulation(),ret) - function doDivorces!(model, sim, example) ret = _init_return(example, Birth()) - ret = _dodivorces!(ret, model, sim, example) + ret = dodivorces!(model,currstep(sim),_popfeature(example),ret) nothing end -_domarriages!(ret,model,sim,::LPMUKDemographyOpt) = domarriages!(model, currstep(sim)) -_domarriages!(ret,model,sim,::LPMUKDemography) = domarriages!(model, currstep(sim),FullPopulation(), ret) - const retMarriage = Person[] _init_return(::LPMUKDemography,::Marriage) = retMarriage function doMarriages!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) ret = _init_return(example, Marriage()) - _domarriages!(ret,model, sim,example) - nothing + ret = domarriages!(model,currstep(sim),_popfeature(example),ret) end -_do_assign_guardians!(ret,model,sim,::LPMUKDemographyOpt) = - do_assign_guardians!(model, currstep(sim), ret) -_do_assign_guardians!(ret,model,sim,::LPMUKDemography) = - do_assign_guardians!(model, currstep(sim), FullPopulation(), ret) - const retAGuarians = Person[] _init_return(::LPMUKDemography,::AssignGuardian) = retAGuarians function doAssignGuardians!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) ret = _init_return(example, AssignGuardian()) - _do_assign_guardians!(ret,model,sim,example) + ret = do_assign_guardians!(model,currstep(sim),_popfeature(example),ret) nothing end +_init_return(::LPMUKDemography,pr::AgeTransition) = + _init_return(LPMUKDemographyOpt(),pr) function doAgeTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) - - doAgeTransitions!(model, currstep(sim)) - + ret = _init_return(example,AgeTransition()) + ret = do_age_transitions!(model,currstep(sim),_popfeature(example),ret) nothing end From 536c0222ce022e81312afd135116a4501e7959ee Mon Sep 17 00:00:00 2001 From: Atiyah Date: Wed, 11 Jan 2023 09:58:45 +0000 Subject: [PATCH 24/33] remove unused submodule --- mainMAHelpers.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/mainMAHelpers.jl b/mainMAHelpers.jl index 341e7b2..0d930b8 100644 --- a/mainMAHelpers.jl +++ b/mainMAHelpers.jl @@ -11,7 +11,6 @@ using SocioEconomics.ParamTypes using SocioEconomics.XAgents using SocioEconomics.Specification.Create using SocioEconomics.Specification.Initialize -using SocioEconomics.Specification.Simulate include("mainHelpers.jl") From 6524ad6b02a49b362ebb999381a0d27069cdc5a8 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Wed, 11 Jan 2023 09:59:24 +0000 Subject: [PATCH 25/33] making use of the newl;y tuned API simulation functions --- src/malpm/demography/SimSetup.jl | 28 +++++++++++++++++++++------- src/malpm/demography/Simulate.jl | 25 +++++++++++++++---------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/demography/SimSetup.jl index ed049f2..23cad71 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/demography/SimSetup.jl @@ -17,8 +17,9 @@ using MultiAgents: attach_pre_model_step!, attach_post_model_step!, using SocioEconomics.Utilities: setVerbose!, unsetVerbose!, setDelay!, checkAssumptions!, ignoreAssumptions!, date2yearsmonths using SocioEconomics.XAgents: age, isMale, isFemale, isSingle, alive, hasDependents -using SocioEconomics.API.Traits: FullPopulation -using SocioEconomics.Specification.SimulateNew: death!, birth!, divorce!, marriage!, assign_guardian! +using SocioEconomics.API.Traits: FullPopulation, AlivePopulation +using SocioEconomics.Specification.SimulateNew: death!, birth!, divorce!, marriage!, + assign_guardian!, age_transition!, work_transition!, social_transition! import SocioEconomics.API.ModelFunc: share_childless_men, eligible_women import MultiAgents: setup!, verbose @@ -34,9 +35,6 @@ function setupCommon!(sim::AbstractABMSimulator) attach_post_model_step!(sim,doDeaths!) attach_post_model_step!(sim,doAssignGuardians!) attach_post_model_step!(sim,doBirths!) - attach_post_model_step!(sim,doAgeTransitions!) - attach_post_model_step!(sim,doWorkTransitions!) - attach_post_model_step!(sim,doSocialTransitions!) attach_post_model_step!(sim,doMarriages!) nothing @@ -60,6 +58,15 @@ marriagestep!(person, model, sim, example) = assign_guardian_step!(person, model, sim, example) = assign_guardian!(person, currstep(sim), model, _popfeature(example)) +age_transition_step!(person, model, sim, example) = + age_transition!(person, currstep(sim), model, _popfeature(example)) + +work_transition_step!(person, model, sim, example) = + work_transition!(person, currstep(sim), model, _popfeature(example)) + +social_transition_step!(person, model, sim, example) = + social_transition!(person, currstep(sim), model, _popfeature(example)) + _ageclass(person) = trunc(Int, age(person)/10) @memoize Dict function share_childless_men(model::MAModel, ageclass :: Int) nAll = 0 @@ -87,20 +94,27 @@ end function setup!(sim::AbstractABMSimulator, example::LPMUKDemography) # attach_pre_model_step!(sim,population_step!) # attach_pre_model_step!(sim,reset_cache_marriages) - # attach_agent_step!(sim,agestepAlivePerson!) + #attach_agent_step!(sim,agestepAlivePerson!) # attach_agent_step!(sim,deathstep!) this leads to excessive memory allocation and memory storage # attach_agent_step!(sim,birthstep!) this leads to excessive memory allocation and memory storage #attach_agent_step!(sim,assign_guardian_step!) + attach_agent_step!(sim,age_transition_step!) attach_agent_step!(sim,divorcestep!) + attach_agent_step!(sim,work_transition_step!) + attach_agent_step!(sim,social_transition_step!) # attach_agent_step!(sim,marriagestep!) # does not seem to work properly (may be due to memoization) setupCommon!(sim) nothing end function setup!(sim::AbstractABMSimulator,example::LPMUKDemographyOpt) - # attach_agent_step!(sim,agestep!) + #attach_agent_step!(sim,agestep!) + #attach_agent_step!(sim,age_transition_step!) #attach_post_model_step!(sim,doAssignGuardians!) + attach_post_model_step!(sim,doAgeTransitions!) attach_post_model_step!(sim,doDivorces!) + attach_post_model_step!(sim,doWorkTransitions!) + attach_post_model_step!(sim,doSocialTransitions!) setupCommon!(sim) nothing end diff --git a/src/malpm/demography/Simulate.jl b/src/malpm/demography/Simulate.jl index 67e3862..a602230 100644 --- a/src/malpm/demography/Simulate.jl +++ b/src/malpm/demography/Simulate.jl @@ -11,12 +11,13 @@ using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt using SocioEconomics using SocioEconomics.XAgents: Person using SocioEconomics.API.Traits: FullPopulation, AlivePopulation, - SimProcess, Death, Birth, Marriage, - AssignGuardian, AgeTransition + SimProcess, Death, Birth, Marriage, + AssignGuardian, AgeTransition, + WorkTransition, SocialTransition using SocioEconomics.Utilities: date2yearsmonths import SocioEconomics.Specification.SimulateNew: dodeaths!, dobirths!, - dodivorces!, domarriages!, do_assign_guardians!, do_age_transitions!, - doWorkTransitions!, doSocialTransitions! + dodivorces!, domarriages!, do_assign_guardians!, + do_age_transitions!, do_work_transitions!, do_social_transitions! _popfeature(::LPMUKDemography) = FullPopulation() _popfeature(::LPMUKDemographyOpt) = AlivePopulation() @@ -78,17 +79,21 @@ function doAgeTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, examp nothing end +_init_return(::LPMUKDemography,pr::WorkTransition) = + _init_return(LPMUKDemographyOpt(),pr) + function doWorkTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) - - doWorkTransitions!(model, currstep(sim)) - + ret = _init_return(example,WorkTransition()) + ret = do_work_transitions!(model,currstep(sim),_popfeature(example),ret) nothing end -function doSocialTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) - - doSocialTransitions!(model, currstep(sim)) +_init_return(::LPMUKDemography,pr::SocialTransition) = + _init_return(LPMUKDemographyOpt(),pr) +function doSocialTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) + ret = _init_return(example,SocialTransition()) + ret = do_social_transitions!(model,currstep(sim),_popfeature(example),ret) nothing end From db8a18bab26b2bdbd100751b0a22e2593d1d4863 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Fri, 13 Jan 2023 09:21:42 +0000 Subject: [PATCH 26/33] renaming function and cleaning code --- src/malpm/demography/SimSetup.jl | 40 +++++++++++--------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/demography/SimSetup.jl index 23cad71..a158990 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/demography/SimSetup.jl @@ -1,15 +1,12 @@ module SimSetup using Memoization -using MALPM.Demography.Population: removeDead!, - agestepAlivePerson!, agestep!, population_step! using MALPM.Models: MAModel, allPeople, birthParameters -using MALPM.Demography: DemographyExample, - LPMUKDemography, LPMUKDemographyOpt -using MALPM.Demography.Simulate: doDeaths!, doBirths!, - doAgeTransitions!, doWorkTransitions!, doSocialTransitions!, - doDivorces!, doMarriages!, doAssignGuardians! +using MALPM.Demography: LPMUKDemography, LPMUKDemographyOpt +using MALPM.Demography.Simulate: dodeaths!, dobirths!, + do_age_transitions!, do_work_transitions!, do_social_transitions!, + dodivorces!, domarriages!, do_assign_guardians! using MultiAgents: AbstractABMSimulator using MultiAgents: attach_pre_model_step!, attach_post_model_step!, @@ -19,11 +16,11 @@ using SocioEconomics.Utilities: setVerbose!, unsetVerbose!, setDelay!, using SocioEconomics.XAgents: age, isMale, isFemale, isSingle, alive, hasDependents using SocioEconomics.API.Traits: FullPopulation, AlivePopulation using SocioEconomics.Specification.SimulateNew: death!, birth!, divorce!, marriage!, - assign_guardian!, age_transition!, work_transition!, social_transition! + assign_guardian!, age_transition!, work_transition!, social_transition! import SocioEconomics.API.ModelFunc: share_childless_men, eligible_women import MultiAgents: setup!, verbose -export setup! +#export setup! function setupCommon!(sim::AbstractABMSimulator) @@ -32,10 +29,10 @@ function setupCommon!(sim::AbstractABMSimulator) sim.parameters.checkassumption ? checkAssumptions!() : ignoreAssumptions!() - attach_post_model_step!(sim,doDeaths!) - attach_post_model_step!(sim,doAssignGuardians!) - attach_post_model_step!(sim,doBirths!) - attach_post_model_step!(sim,doMarriages!) + attach_post_model_step!(sim,dodeaths!) + attach_post_model_step!(sim,do_assign_guardians!) + attach_post_model_step!(sim,dobirths!) + attach_post_model_step!(sim,domarriages!) nothing end @@ -92,12 +89,6 @@ end "set up simulation functions where dead people are removed" function setup!(sim::AbstractABMSimulator, example::LPMUKDemography) - # attach_pre_model_step!(sim,population_step!) - # attach_pre_model_step!(sim,reset_cache_marriages) - #attach_agent_step!(sim,agestepAlivePerson!) - # attach_agent_step!(sim,deathstep!) this leads to excessive memory allocation and memory storage - # attach_agent_step!(sim,birthstep!) this leads to excessive memory allocation and memory storage - #attach_agent_step!(sim,assign_guardian_step!) attach_agent_step!(sim,age_transition_step!) attach_agent_step!(sim,divorcestep!) attach_agent_step!(sim,work_transition_step!) @@ -108,13 +99,10 @@ function setup!(sim::AbstractABMSimulator, example::LPMUKDemography) end function setup!(sim::AbstractABMSimulator,example::LPMUKDemographyOpt) - #attach_agent_step!(sim,agestep!) - #attach_agent_step!(sim,age_transition_step!) - #attach_post_model_step!(sim,doAssignGuardians!) - attach_post_model_step!(sim,doAgeTransitions!) - attach_post_model_step!(sim,doDivorces!) - attach_post_model_step!(sim,doWorkTransitions!) - attach_post_model_step!(sim,doSocialTransitions!) + attach_post_model_step!(sim,do_age_transitions!) + attach_post_model_step!(sim,dodivorces!) + attach_post_model_step!(sim,do_work_transitions!) + attach_post_model_step!(sim,do_social_transitions!) setupCommon!(sim) nothing end From 04bf47dd9ee25c8c962a4081330f49afcdacf4cb Mon Sep 17 00:00:00 2001 From: Atiyah Date: Fri, 13 Jan 2023 09:22:02 +0000 Subject: [PATCH 27/33] renaming functions and cleanning code --- src/malpm/demography/Simulate.jl | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/malpm/demography/Simulate.jl b/src/malpm/demography/Simulate.jl index a602230..8b5ae3e 100644 --- a/src/malpm/demography/Simulate.jl +++ b/src/malpm/demography/Simulate.jl @@ -5,8 +5,7 @@ module Simulate using MultiAgents: AbstractMABM, AbstractABMSimulator -using MultiAgents: add_agent!, currstep -using MALPM.Demography.Population: removeDead! +using MultiAgents: currstep using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt using SocioEconomics using SocioEconomics.XAgents: Person @@ -27,7 +26,7 @@ _init_return(::LPMUKDemographyOpt,::SimProcess) = 0 const retDeath = Person[] _init_return(::LPMUKDemography,::Death) = retDeath -function doDeaths!(model, sim, example) +function dodeaths!(model, sim, example::DemographyExample) ret = _init_return(example,Death()) ret = dodeaths!(model,currstep(sim),_popfeature(example),ret) #=years, months = date2yearsmonths(currstep(sim)) @@ -38,7 +37,7 @@ end # function doDeaths! const retBirth = Person[] _init_return(::LPMUKDemography,::Birth) = retBirth -function doBirths!(model, sim, example) +function dobirths!(model, sim, example::DemographyExample) ret = _init_return(example,Birth()) ret = dobirths!(model,currstep(sim),_popfeature(example),ret) nothing @@ -47,7 +46,7 @@ end const retBirth = Person[] _init_return(::LPMUKDemography,::Birth) = retBirth -function doDivorces!(model, sim, example) +function dodivorces!(model, sim, example::DemographyExample) ret = _init_return(example, Birth()) ret = dodivorces!(model,currstep(sim),_popfeature(example),ret) nothing @@ -56,7 +55,7 @@ end const retMarriage = Person[] _init_return(::LPMUKDemography,::Marriage) = retMarriage -function doMarriages!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) +function domarriages!(model, sim, example::DemographyExample) ret = _init_return(example, Marriage()) ret = domarriages!(model,currstep(sim),_popfeature(example),ret) end @@ -64,7 +63,7 @@ end const retAGuarians = Person[] _init_return(::LPMUKDemography,::AssignGuardian) = retAGuarians -function doAssignGuardians!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) +function do_assign_guardians!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) ret = _init_return(example, AssignGuardian()) ret = do_assign_guardians!(model,currstep(sim),_popfeature(example),ret) nothing @@ -73,7 +72,7 @@ end _init_return(::LPMUKDemography,pr::AgeTransition) = _init_return(LPMUKDemographyOpt(),pr) -function doAgeTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) +function do_age_transitions!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) ret = _init_return(example,AgeTransition()) ret = do_age_transitions!(model,currstep(sim),_popfeature(example),ret) nothing @@ -82,7 +81,7 @@ end _init_return(::LPMUKDemography,pr::WorkTransition) = _init_return(LPMUKDemographyOpt(),pr) -function doWorkTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) +function do_work_transitions!(model::AbstractMABM, sim, example::DemographyExample) ret = _init_return(example,WorkTransition()) ret = do_work_transitions!(model,currstep(sim),_popfeature(example),ret) nothing @@ -91,7 +90,7 @@ end _init_return(::LPMUKDemography,pr::SocialTransition) = _init_return(LPMUKDemographyOpt(),pr) -function doSocialTransitions!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample) +function do_social_transitions!(model::AbstractMABM, sim, example::DemographyExample) ret = _init_return(example,SocialTransition()) ret = do_social_transitions!(model,currstep(sim),_popfeature(example),ret) nothing From 2bb65c1727f35d92eea029168f26aa4a8e878484 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Fri, 13 Jan 2023 09:35:39 +0000 Subject: [PATCH 28/33] reorganize and simplify , 2 modules removed --- mainMA.jl | 2 +- src/MALPM.jl | 4 +- src/malpm/DemographyXX.jl | 8 +++ src/malpm/{Demography.jl => Examples.jl} | 15 ++--- src/malpm/{demography => }/SimSetup.jl | 4 +- src/malpm/{demography => }/Simulate.jl | 2 +- src/malpm/demography/Population.jl | 81 ------------------------ 7 files changed, 21 insertions(+), 95 deletions(-) create mode 100644 src/malpm/DemographyXX.jl rename src/malpm/{Demography.jl => Examples.jl} (74%) rename src/malpm/{demography => }/SimSetup.jl (97%) rename src/malpm/{demography => }/Simulate.jl (97%) delete mode 100644 src/malpm/demography/Population.jl diff --git a/mainMA.jl b/mainMA.jl index c092587..f8b3d4d 100644 --- a/mainMA.jl +++ b/mainMA.jl @@ -13,7 +13,7 @@ include("mainMAHelpers.jl") using MultiAgents: ABMSimulatorP using MultiAgents: run!, setup! using MALPM.Models: MAModel -using MALPM.Demography: LPMUKDemography, LPMUKDemographyOpt +using MALPM.Examples const mainConfig = Light() # no input files, logging or flags (REPL Exec.) # mainConfig = WithInputFiles() diff --git a/src/MALPM.jl b/src/MALPM.jl index 907bb08..e7fd9bf 100644 --- a/src/MALPM.jl +++ b/src/MALPM.jl @@ -4,6 +4,8 @@ Main components of LoneParentsModel simulation based on MultiAgents.jl package module MALPM include("./malpm/Models.jl") -include("./malpm/Demography.jl") +include("./malpm/Examples.jl") +include("./malpm/Simulate.jl") +include("./malpm/SimSetup.jl") end # MALPM \ No newline at end of file diff --git a/src/malpm/DemographyXX.jl b/src/malpm/DemographyXX.jl new file mode 100644 index 0000000..4c27181 --- /dev/null +++ b/src/malpm/DemographyXX.jl @@ -0,0 +1,8 @@ +module Demography + + + +include("./demography/Simulate.jl") +include("./demography/SimSetup.jl") + +end # Demography \ No newline at end of file diff --git a/src/malpm/Demography.jl b/src/malpm/Examples.jl similarity index 74% rename from src/malpm/Demography.jl rename to src/malpm/Examples.jl index ac3a0b3..477d4bf 100644 --- a/src/malpm/Demography.jl +++ b/src/malpm/Examples.jl @@ -1,5 +1,8 @@ -module Demography - +""" +Example traits to express different models and configurations +""" +module Examples + import MultiAgents.Util: AbstractExample export DemographyExample, LPMUKDemography, LPMUKDemographyOpt @@ -14,10 +17,4 @@ struct LPMUKDemography <: DemographyExample end "This is an attemp for improved algorthimic translation" struct LPMUKDemographyOpt <: DemographyExample end - -include("./demography/Population.jl") -include("./demography/Simulate.jl") -include("./demography/SimSetup.jl") - - -end # Demography \ No newline at end of file +end \ No newline at end of file diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/SimSetup.jl similarity index 97% rename from src/malpm/demography/SimSetup.jl rename to src/malpm/SimSetup.jl index a158990..091cf7a 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/SimSetup.jl @@ -3,8 +3,8 @@ module SimSetup using Memoization using MALPM.Models: MAModel, allPeople, birthParameters -using MALPM.Demography: LPMUKDemography, LPMUKDemographyOpt -using MALPM.Demography.Simulate: dodeaths!, dobirths!, +using MALPM.Examples +using MALPM.Simulate: dodeaths!, dobirths!, do_age_transitions!, do_work_transitions!, do_social_transitions!, dodivorces!, domarriages!, do_assign_guardians! diff --git a/src/malpm/demography/Simulate.jl b/src/malpm/Simulate.jl similarity index 97% rename from src/malpm/demography/Simulate.jl rename to src/malpm/Simulate.jl index 8b5ae3e..e56f043 100644 --- a/src/malpm/demography/Simulate.jl +++ b/src/malpm/Simulate.jl @@ -6,7 +6,7 @@ module Simulate using MultiAgents: AbstractMABM, AbstractABMSimulator using MultiAgents: currstep -using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt +using MALPM.Examples using SocioEconomics using SocioEconomics.XAgents: Person using SocioEconomics.API.Traits: FullPopulation, AlivePopulation, diff --git a/src/malpm/demography/Population.jl b/src/malpm/demography/Population.jl deleted file mode 100644 index db59de2..0000000 --- a/src/malpm/demography/Population.jl +++ /dev/null @@ -1,81 +0,0 @@ -""" -Population module providing help utilities for realizing a population as an ABM -""" - -module Population - -using MultiAgents: SimpleABM, AbstractABMSimulator, AbstractMABM -using MultiAgents: allagents, dt, kill_agent!, kill_agent_opt!, - kill_agent_at!, kill_agent_at_opt! -using SocioEconomics.XAgents: Person -using SocioEconomics.XAgents: alive, agestepAlive! - -import SocioEconomics.XAgents: agestep! - -export population_step!, agestepAlivePerson!, removeDead! -export PopulationType - -const PopulationType = SimpleABM{Person} - -"Step function for the population" -function population_step!(population::PopulationType, - sim::AbstractABMSimulator, - example) - for person in allagents(population) - if alive(person) - agestep!(person,dt(sim)) - end - end -end - -population_step!(model::AbstractMABM, - sim::AbstractABMSimulator, - example) = - population_step!(model.pop,sim,example) - -"remove dead persons" -function removeDead!(person::Person, population::PopulationType) - @assert alive(person) - kill_agent_opt!(person, population) - nothing -end - -function removeDead!(idx::Int, population::PopulationType) - kill_agent_at_opt!(idx, population) - nothing -end - -function removeDead!(population::PopulationType, - ::AbstractABMSimulator, - example) - people = reverse(allagents(population)) - for person in people - alive(person) ? nothing : kill_agent!(person,population) - end - nothing -end - -"increment age with the simulation step size" -agestep!(person::Person, - population::PopulationType, - sim::AbstractABMSimulator, - example) = agestep!(person,dt(sim)) - - -agestep!(person::Person,model::AbstractMABM,sim,example) = - agestep!(person,model.pop,sim,example) - -"increment age with the simulation step size" -agestepAlivePerson!(person::Person, population::PopulationType, - sim::AbstractABMSimulator, - example) = - agestepAlive!(person, dt(sim)) - - -agestepAlivePerson!(person,model::AbstractMABM,sim,example) = - agestepAlivePerson!(person,model.pop,sim,example) - -end # Population - - - From 82abbdd7218cd1e45d1b714ad5ac2934a9c9b113 Mon Sep 17 00:00:00 2001 From: Atiyah Date: Fri, 13 Jan 2023 09:36:48 +0000 Subject: [PATCH 29/33] remove unused module --- src/malpm/DemographyXX.jl | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/malpm/DemographyXX.jl diff --git a/src/malpm/DemographyXX.jl b/src/malpm/DemographyXX.jl deleted file mode 100644 index 4c27181..0000000 --- a/src/malpm/DemographyXX.jl +++ /dev/null @@ -1,8 +0,0 @@ -module Demography - - - -include("./demography/Simulate.jl") -include("./demography/SimSetup.jl") - -end # Demography \ No newline at end of file From e52af98b2ac4fb60bea5be82e5f3094204b1af47 Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Sat, 14 Jan 2023 08:41:56 +0000 Subject: [PATCH 30/33] Version 0.3 --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 33b7e0a..a574c6a 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,17 @@ Releases - V0.1.3 ( 2.12) : Utilties is a part of the SE* libraries (compatible with SE V0.1.3) - **V0.2.0 (5.12.2022)** : Unified API of CreateX and Initialize functions (compatible with SE V0.2) + - Remark: main.jl is no longer maintained. - - V0.2.1 (7.12) : (MALPM only) New Simulation Interface for 3 functions, doBirths!, doDeaths!, doDivorces, Improved API for parameter accessory functions, compatible with SE* Version 0.2.1 - - V0.2.2 (8.12) : (MALPM only) doMarriages (SE* V0.2.2) - - V0.2.3 (9.12) : (MALPM only) adoptions, workTransitions, socialTransitions, ageTransitions (SE* V0.2.3) - - V0.2.4 (14.12) : (MALPM only) adjusting to SimpleABM types of MA Version 0.4, improved model data structure - - V0.2.5 (21.12) : (MALPM only) exploits some tuned simulation functions from SE* V0.2.5 and improved performance (3x faster) - - V0.2.6 (27.12) : (MALPM only) Improved implementation of allocation algorithms (no temporary arrays), tuned do marriage algorithm (memoization can be avoided) & Improved runtime performance (3x faster & 4x less memory allocation and storage w.r.t. V0.2.5) + - V0.2.1 (7.12) : New Simulation Interface for 3 functions, doBirths!, doDeaths!, doDivorces, Improved API for parameter accessory functions, compatible with SE* Version 0.2.1 + - V0.2.2 (8.12) : doMarriages (SE* V0.2.2) + - V0.2.3 (9.12) : adoptions, workTransitions, socialTransitions, ageTransitions (SE* V0.2.3) + - V0.2.4 (14.12) : adjusting to SimpleABM types of MA Version 0.4, improved model data structure + - V0.2.5 (21.12) : exploits some tuned simulation functions from SE* V0.2.5 and improved performance (3x faster) + - V0.2.6 (27.12) : Improved implementation of allocation algorithms (no temporary arrays), tuned do marriage algorithm (memoization can be avoided) & Improved runtime performance (3x faster & 4x less memory allocation and storage w.r.t. V0.2.5) - V0.2.7 (6.1.2023) : (MALPM only) Memoization with domarriage alg can be done only externally (if desired). Employing newly tuned and exact API of four simulation functions. Optimized simulation (with deads removal) vs. normal simulation (without deads removal) - V0.2.8 (8.1.2023) : (MALPM only) employing tuned API of assigning guardians +- **V0.3 (14-01-2022) : Making use of the rest of the fixed API of SE's Simulate function, further code simplification and tuning. Signficant memory allocation reduction and runtime performance improvement + + From bee31aac6547b7bc5f9430dac98fdff55f2d26a3 Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Sat, 14 Jan 2023 17:37:20 +0000 Subject: [PATCH 31/33] performance rogress history --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a574c6a..22110fc 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Releases - V0.1.3 ( 2.12) : Utilties is a part of the SE* libraries (compatible with SE V0.1.3) - **V0.2.0 (5.12.2022)** : Unified API of CreateX and Initialize functions (compatible with SE V0.2) - - Remark: main.jl is no longer maintained. + - Remark: main.jl is no longer maintained. - V0.2.1 (7.12) : New Simulation Interface for 3 functions, doBirths!, doDeaths!, doDivorces, Improved API for parameter accessory functions, compatible with SE* Version 0.2.1 - V0.2.2 (8.12) : doMarriages (SE* V0.2.2) @@ -23,5 +23,18 @@ Releases - V0.2.8 (8.1.2023) : (MALPM only) employing tuned API of assigning guardians - **V0.3 (14-01-2022) : Making use of the rest of the fixed API of SE's Simulate function, further code simplification and tuning. Signficant memory allocation reduction and runtime performance improvement +Performance Progress History +============================ + +The following is the progress history of executing mainMA.jl on + + +Version | Runtime | # Memory Allocation | Storage used | Comment +--- | --- | --- | --- | --- +0 | ~29 sec. | ~ 400 M | 12.6 GB | The state of LoneParentsModel.jl before starting this repo. +V0.2.2 | 21.sec | ~ 282 M | 9.7 GB | execution with main.jl was quite faster but consumed more memory and storage + + + From ecdc401adab6d357c5575b01cb5a7410116eb816 Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Sat, 14 Jan 2023 18:16:37 +0000 Subject: [PATCH 32/33] completing performance progress history --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 22110fc..dc3f5af 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Releases - V0.2.2 (8.12) : doMarriages (SE* V0.2.2) - V0.2.3 (9.12) : adoptions, workTransitions, socialTransitions, ageTransitions (SE* V0.2.3) - V0.2.4 (14.12) : adjusting to SimpleABM types of MA Version 0.4, improved model data structure - - V0.2.5 (21.12) : exploits some tuned simulation functions from SE* V0.2.5 and improved performance (3x faster) + - V0.2.5 (21.12) : exploits some tuned simulation functions from SE* V0.2.5 and improved performance - V0.2.6 (27.12) : Improved implementation of allocation algorithms (no temporary arrays), tuned do marriage algorithm (memoization can be avoided) & Improved runtime performance (3x faster & 4x less memory allocation and storage w.r.t. V0.2.5) - V0.2.7 (6.1.2023) : (MALPM only) Memoization with domarriage alg can be done only externally (if desired). Employing newly tuned and exact API of four simulation functions. Optimized simulation (with deads removal) vs. normal simulation (without deads removal) - V0.2.8 (8.1.2023) : (MALPM only) employing tuned API of assigning guardians @@ -28,11 +28,15 @@ Performance Progress History The following is the progress history of executing mainMA.jl on - Version | Runtime | # Memory Allocation | Storage used | Comment ---- | --- | --- | --- | --- -0 | ~29 sec. | ~ 400 M | 12.6 GB | The state of LoneParentsModel.jl before starting this repo. -V0.2.2 | 21.sec | ~ 282 M | 9.7 GB | execution with main.jl was quite faster but consumed more memory and storage +0 | ~29 sec. | ~ 400 M | 12.5 GB | The state of LoneParentsModel.jl before starting this repo. +V0.2.3 | 29 sec. | ~ 360 M | ~ 14 GB | execution with main.jl was quite faster but consumed more memory and storage +V0.2.4 | 21.5 sec. | ~ 280 M | ~ 10.5 GB | MA Version 0.4 +V0.2.5 | 20 sec. | ~ 155 M | ~ 8 GB | +V0.2.6 | 7.6 sec. | ~ 37 M | ~ 2.2 GB | +V0.2.8 | 6.3 sec. | ~ 24 M | ~ 1.6 GB | +V0.3 | 4.7 sec | ~ 380 K | ~ 90 MB | + From ce6a6b6bd5d93cffe40b8c989ad6170d9ad22b84 Mon Sep 17 00:00:00 2001 From: "atiyah.elsheikh" Date: Sat, 14 Jan 2023 18:18:04 +0000 Subject: [PATCH 33/33] formatting pr. hist. table --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index dc3f5af..7cd1bf7 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,17 @@ V0.2.6 | 7.6 sec. | ~ 37 M | ~ 2.2 GB | V0.2.8 | 6.3 sec. | ~ 24 M | ~ 1.6 GB | V0.3 | 4.7 sec | ~ 380 K | ~ 90 MB | +Version | Runtime | # Memory Allocation | Storage used | Comment +--- | --- | --- | --- | --- +0 | ~29 sec. | ~ 400 M | 12.5 GB | The state of LoneParentsModel.jl before starting this repo. +V0.2.3 | 29 sec. | ~ 360 M | ~ 14 GB | execution with main.jl was quite faster but consumed more memory and storage +V0.2.4 | 21.5 sec. | ~ 280 M | ~ 10.5 GB | MA Version 0.4 +V0.2.5 | 20 sec. | ~ 155 M | ~ 8 GB | +V0.2.6 | 7.6 sec. | ~ 37 M | ~ 2.2 GB | +V0.2.8 | 6.3 sec. | ~ 24 M | ~ 1.6 GB | +V0.3 | 4.7 sec | ~ 380 K | ~ 90 MB | + +