Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
help='show plots')
aa('--verbosity',
type=int,default=0,
help='specify integer > 0 to get more output [default 0]')
args = p.parse_args()
# run checks on output directory
dir = Path(args.dir)
if not dir.resolve().parent.name == 'sim':
raise argparse.ArgumentError(
dir_arg,
"The parent directory of the --dir argument needs to be named 'sim'"
)
else:
model = dir.name.split('_')[0]
settings.m(0, f'...model is: {model!r}')
if dir.is_dir() and 'test' not in str(dir):
message = (
f'directory {dir} already exists, '
'remove it and continue? [y/n, press enter]'
)
if str(input(message)) != 'y':
settings.m(0, ' ...quit program execution')
sys.exit()
else:
settings.m(0, ' ...removing directory and continuing...')
shutil.rmtree(dir)
settings.m(0, model)
settings.m(0, dir)
# sample data
def parents_from_boolRule(self,rule):
""" Determine parents based on boolean updaterule.
Returns list of parents.
"""
rule_pa = rule.replace('(','').replace(')','').replace('or','').replace('and','').replace('not','')
rule_pa = rule_pa.split()
# if there are no parents, continue
if not rule_pa:
return []
# check whether these are meaningful parents
pa_old = []
pa_delete = []
for pa in rule_pa:
if pa not in self.varNames.keys():
settings.m(0,'list of available variables:')
settings.m(0,list(self.varNames.keys()))
message = ('processing of rule "' + rule
+ ' yields an invalid parent: ' + pa
+ ' | check whether the syntax is correct: \n'
+ 'only python expressions "(",")","or","and","not" '
+ 'are allowed, variable names and expressions have to be separated '
+ 'by white spaces')
raise ValueError(message)
if pa in pa_old:
pa_delete.append(pa)
for pa in pa_delete:
rule_pa.remove(pa)
return rule_pa
dir = Path(args.dir)
if not dir.resolve().parent.name == 'sim':
raise argparse.ArgumentError(
dir_arg,
"The parent directory of the --dir argument needs to be named 'sim'"
)
else:
model = dir.name.split('_')[0]
settings.m(0, f'...model is: {model!r}')
if dir.is_dir() and 'test' not in str(dir):
message = (
f'directory {dir} already exists, '
'remove it and continue? [y/n, press enter]'
)
if str(input(message)) != 'y':
settings.m(0, ' ...quit program execution')
sys.exit()
else:
settings.m(0, ' ...removing directory and continuing...')
shutil.rmtree(dir)
settings.m(0, model)
settings.m(0, dir)
# sample data
if 'static' in model:
sample_static_data(model=model, dir=dir, verbosity=args.verbosity)
else:
sample_dynamic_data(model=model, dir=dir)
model = dir.name.split('_')[0]
settings.m(0, f'...model is: {model!r}')
if dir.is_dir() and 'test' not in str(dir):
message = (
f'directory {dir} already exists, '
'remove it and continue? [y/n, press enter]'
)
if str(input(message)) != 'y':
settings.m(0, ' ...quit program execution')
sys.exit()
else:
settings.m(0, ' ...removing directory and continuing...')
shutil.rmtree(dir)
settings.m(0, model)
settings.m(0, dir)
# sample data
if 'static' in model:
sample_static_data(model=model, dir=dir, verbosity=args.verbosity)
else:
sample_dynamic_data(model=model, dir=dir)
for g in range(self.dim):
if g in pasIndices:
if np.abs(self.Coupl[self.varNames[key],g]) < 1e-10:
raise ValueError(
f'specify coupling value for {key} <- {g}'
)
else:
if np.abs(self.Coupl[self.varNames[key],g]) > 1e-10:
raise ValueError(
'there should be no coupling value for '
f'{key} <- {g}'
)
if self.verbosity > 1:
settings.m(0, '...'+key)
settings.m(0, rule)
settings.m(0, rule_pa)
# now evaluate coefficients
for tuple in list(itertools.product([False, True], repeat=len(self.pas[key]))):
if self.process_rule(rule, self.pas[key], tuple):
self.boolCoeff[key].append(tuple)
#
if self.verbosity > 1:
settings.m(0,self.boolCoeff[key])
Adj
adjancancy matrix of dimension (dim, dim)
Returns
-------
True if there is no cycle, False otherwise.
"""
dim = Adj.shape[0]
for g in range(dim):
v = np.zeros(dim)
v[g] = 1
for i in range(dim):
v = Adj.dot(v)
if v[g] > 1e-10:
if verbosity > 2:
settings.m(0, Adj)
settings.m(
0, 'contains a cycle of length', i+1,
'starting from node', g,
'-> reject',
)
return False
return True
if np.abs(self.Coupl[self.varNames[key],g]) > 1e-10:
raise ValueError(
'there should be no coupling value for '
f'{key} <- {g}'
)
if self.verbosity > 1:
settings.m(0, '...'+key)
settings.m(0, rule)
settings.m(0, rule_pa)
# now evaluate coefficients
for tuple in list(itertools.product([False, True], repeat=len(self.pas[key]))):
if self.process_rule(rule, self.pas[key], tuple):
self.boolCoeff[key].append(tuple)
#
if self.verbosity > 1:
settings.m(0,self.boolCoeff[key])
if verbosity > 0:
Xdiff_syn_tuple_str += (
f'{"a" if v else "i"}'
f'({self.pas[child][iv]}, {threshold:.2})'
)
Xdiff_syn += Xdiff_syn_tuple
if verbosity > 0:
Xdiff_syn_str += ('+' if ituple != 0 else '') + Xdiff_syn_tuple_str
# multiply with degradation term
Xdiff[ichild] = self.invTimeStep*(Xdiff_syn - Xt[ichild])
if verbosity > 0:
Xdiff_str = (
f'{child}_{child}-{child} = '
f'{self.invTimeStep}*({Xdiff_syn_str}-{child})'
)
settings.m(0, Xdiff_str)
return Xdiff