Skip to content

Commit

Permalink
Fixed CCMnet_py new usage
Browse files Browse the repository at this point in the history
  • Loading branch information
niemasd committed Jun 8, 2022
1 parent 95cbe77 commit df946c8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
13 changes: 10 additions & 3 deletions modules/ContactNetworkGenerator_CCMnetPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import FAVITES_GlobalContext as GC
from gzip import open as gopen
from os import chdir
from os.path import expanduser
from os.path import abspath, expanduser, isfile
import json
import math
import random

Expand Down Expand Up @@ -611,6 +612,12 @@ def init():
assert False, "Error loading NumPy. Install with: pip3 install numpy"

# check user args
if hasattr(GC, "cn_config_file"):
assert isfile(GC.cn_config_file), "CCMnet_py config file not found: %s" % GC.cn_config_file
GC.cn_config_file = abspath(expanduser(GC.cn_config_file))
if hasattr(GC, "cn_config_dict"):
assert 'G' in GC.cn_config_dict, "CCMnet_py config dict must have 'G' key"
GC.cn_config_dict['G'] = abspath(expanduser(GC.cn_config_dict['G']))
if hasattr(GC, "num_cn_nodes"):
assert isinstance(GC.num_cn_nodes, int), "num_cn_nodes must be an integer"
assert GC.num_cn_nodes >= 2, "Contact network must have at least 2 nodes"
Expand Down Expand Up @@ -651,8 +658,8 @@ def init():
assert GC.cn_mcmc_burnin > 0, "cn_mcmc_burnin must be a positive integer"

def get_edge_list():
if hasattr(GC, "cn_params_dict"):
cn = CCMnet_constr_py(**GC.cn_params_dict)
if hasattr(GC, "cn_config_dict"):
cn = CCMnet_constr_py(**GC.cn_config_dict)
elif hasattr(GC, "cn_config_file"):
cn = CCMnet_constr_py(config_file=GC.cn_config_file)
else:
Expand Down
5 changes: 2 additions & 3 deletions modules/FAVITES_ModuleFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def read_config(config, verbose):
modules[module]() # instantiate to force check of abstract methods
for req in sorted(module_implementations[module][config[module]]['req']):
assert req in config, "Parameter %r of %s_%s module is not in the configuration file!" % (req, module, config[module])
reqs[req] = config[req]
GC.init(reqs)
GC.init(config)
GC.VERBOSE = verbose

def init(mod_dir):
Expand Down Expand Up @@ -85,4 +84,4 @@ def init(mod_dir):
This function is just used for testing purposes. It has no actual function
in the simulator tool.
'''
init()
init()
2 changes: 1 addition & 1 deletion modules/FAVITES_ModuleList.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},

"CCMnetPy": {
"req": ["num_cn_nodes", "cn_network_stats", "cn_prob_dists", "cn_prob_dist_params", "cn_covariate_pattern", "cn_mcmc_burnin"]
"req": []
},

"Communities": {
Expand Down
4 changes: 4 additions & 0 deletions run_favites.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from os import environ,getcwd
from os.path import abspath,expanduser,isdir

# for parsing booleans in JSON
true = True
false = False

def parseArgs():
'''
Parse user arguments. As a developer, if you create any of your own module
Expand Down

0 comments on commit df946c8

Please sign in to comment.