mirror of
https://github.com/gsi-upm/soil
synced 2025-01-09 08:11:28 +00:00
Compare commits
No commits in common. "1cf85ea45073482dcaffe4a71b4259e285dd7edf" and "d1006bd55cdf2bc4b4fd86178d01d245a6d76913" have entirely different histories.
1cf85ea450
...
d1006bd55c
7
Makefile
7
Makefile
@ -1,7 +1,4 @@
|
|||||||
quick-test:
|
test:
|
||||||
docker-compose exec dev python -m pytest -s -v
|
docker-compose exec dev python -m pytest -s -v
|
||||||
|
|
||||||
test:
|
.PHONY: test
|
||||||
docker run -t -v $$PWD:/usr/src/app -w /usr/src/app python:3.7 python setup.py test
|
|
||||||
|
|
||||||
.PHONY: test
|
|
@ -3,8 +3,8 @@ simpy
|
|||||||
networkx>=2.0
|
networkx>=2.0
|
||||||
numpy
|
numpy
|
||||||
matplotlib
|
matplotlib
|
||||||
pyyaml>=5.1
|
pyyaml
|
||||||
pandas>=0.23
|
pandas>=0.23
|
||||||
scipy==1.2.1 # scipy 1.3.0rc1 is not compatible with salib
|
scipy>=1.2
|
||||||
SALib>=1.3
|
SALib>=1.3
|
||||||
Jinja2
|
Jinja2
|
||||||
|
@ -21,7 +21,6 @@ def for_sim(simulation, names, *args, **kwargs):
|
|||||||
exporters.append(mod(simulation, *args, **kwargs))
|
exporters.append(mod(simulation, *args, **kwargs))
|
||||||
return exporters
|
return exporters
|
||||||
|
|
||||||
|
|
||||||
class DryRunner(BytesIO):
|
class DryRunner(BytesIO):
|
||||||
def __init__(self, fname, *args, copy_to=None, **kwargs):
|
def __init__(self, fname, *args, copy_to=None, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -55,7 +55,7 @@ def load_file(infile):
|
|||||||
|
|
||||||
|
|
||||||
def load_string(string):
|
def load_string(string):
|
||||||
yield from yaml.load_all(string, Loader=yaml.FullLoader)
|
yield from yaml.load_all(string)
|
||||||
|
|
||||||
|
|
||||||
def expand_template(config):
|
def expand_template(config):
|
||||||
|
@ -1,110 +0,0 @@
|
|||||||
import os
|
|
||||||
import io
|
|
||||||
import tempfile
|
|
||||||
import shutil
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
from unittest import TestCase
|
|
||||||
from soil import exporters
|
|
||||||
from soil.utils import safe_open
|
|
||||||
from soil import simulation
|
|
||||||
|
|
||||||
|
|
||||||
class Dummy(exporters.Exporter):
|
|
||||||
started = False
|
|
||||||
trials = 0
|
|
||||||
ended = False
|
|
||||||
total_time = 0
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self.__class__.started = True
|
|
||||||
|
|
||||||
def trial_end(self, env):
|
|
||||||
assert env
|
|
||||||
self.__class__.trials += 1
|
|
||||||
self.__class__.total_time += env.now
|
|
||||||
|
|
||||||
def end(self):
|
|
||||||
self.__class__.ended = True
|
|
||||||
|
|
||||||
|
|
||||||
class Exporters(TestCase):
|
|
||||||
def test_basic(self):
|
|
||||||
config = {
|
|
||||||
'name': 'exporter_sim',
|
|
||||||
'network_params': {},
|
|
||||||
'agent_type': 'CounterModel',
|
|
||||||
'max_time': 2,
|
|
||||||
'num_trials': 5,
|
|
||||||
'environment_params': {}
|
|
||||||
}
|
|
||||||
s = simulation.from_config(config)
|
|
||||||
s.run_simulation(exporters=[Dummy], dry_run=True)
|
|
||||||
assert Dummy.started
|
|
||||||
assert Dummy.ended
|
|
||||||
assert Dummy.trials == 5
|
|
||||||
assert Dummy.total_time == 2*5
|
|
||||||
|
|
||||||
def test_distribution(self):
|
|
||||||
'''The distribution exporter should write the number of agents in each state'''
|
|
||||||
config = {
|
|
||||||
'name': 'exporter_sim',
|
|
||||||
'network_params': {
|
|
||||||
'generator': 'complete_graph',
|
|
||||||
'n': 4
|
|
||||||
},
|
|
||||||
'agent_type': 'CounterModel',
|
|
||||||
'max_time': 2,
|
|
||||||
'num_trials': 5,
|
|
||||||
'environment_params': {}
|
|
||||||
}
|
|
||||||
output = io.StringIO()
|
|
||||||
s = simulation.from_config(config)
|
|
||||||
s.run_simulation(exporters=[exporters.Distribution], dry_run=True, exporter_params={'copy_to': output})
|
|
||||||
result = output.getvalue()
|
|
||||||
assert 'count' in result
|
|
||||||
assert 'SEED,Noneexporter_sim_trial_3,1,,1,1,1,1' in result
|
|
||||||
|
|
||||||
def test_writing(self):
|
|
||||||
'''Try to write CSV, GEXF, sqlite and YAML (without dry_run)'''
|
|
||||||
n_trials = 5
|
|
||||||
config = {
|
|
||||||
'name': 'exporter_sim',
|
|
||||||
'network_params': {
|
|
||||||
'generator': 'complete_graph',
|
|
||||||
'n': 4
|
|
||||||
},
|
|
||||||
'agent_type': 'CounterModel',
|
|
||||||
'max_time': 2,
|
|
||||||
'num_trials': n_trials,
|
|
||||||
'environment_params': {}
|
|
||||||
}
|
|
||||||
output = io.StringIO()
|
|
||||||
s = simulation.from_config(config)
|
|
||||||
tmpdir = tempfile.mkdtemp()
|
|
||||||
envs = s.run_simulation(exporters=[
|
|
||||||
exporters.Default,
|
|
||||||
exporters.CSV,
|
|
||||||
exporters.Gexf,
|
|
||||||
exporters.Distribution,
|
|
||||||
],
|
|
||||||
outdir=tmpdir,
|
|
||||||
exporter_params={'copy_to': output})
|
|
||||||
result = output.getvalue()
|
|
||||||
|
|
||||||
simdir = os.path.join(tmpdir, s.group or '', s.name)
|
|
||||||
with open(os.path.join(simdir, '{}.dumped.yml'.format(s.name))) as f:
|
|
||||||
result = f.read()
|
|
||||||
assert result
|
|
||||||
|
|
||||||
try:
|
|
||||||
for e in envs:
|
|
||||||
with open(os.path.join(simdir, '{}.gexf'.format(e.name))) as f:
|
|
||||||
result = f.read()
|
|
||||||
assert result
|
|
||||||
|
|
||||||
with open(os.path.join(simdir, '{}.csv'.format(e.name))) as f:
|
|
||||||
result = f.read()
|
|
||||||
assert result
|
|
||||||
finally:
|
|
||||||
shutil.rmtree(tmpdir)
|
|
@ -1,7 +1,6 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import io
|
|
||||||
import yaml
|
import yaml
|
||||||
import pickle
|
import pickle
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
@ -218,8 +217,7 @@ class TestMain(TestCase):
|
|||||||
"""
|
"""
|
||||||
G = nx.random_geometric_graph(20, 0.1)
|
G = nx.random_geometric_graph(20, 0.1)
|
||||||
env = Environment(topology=G)
|
env = Environment(topology=G)
|
||||||
f = io.BytesIO()
|
env.dump_gexf('/tmp/dump-gexf/prueba.gexf')
|
||||||
env.dump_gexf(f)
|
|
||||||
|
|
||||||
def test_save_graph(self):
|
def test_save_graph(self):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user