Skip to content

Commit

Permalink
Add ability to run simulation from separate script
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Toppen authored and Jack Toppen committed May 25, 2023
1 parent 733a55d commit 896ae67
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pip install pythonabm

PythonABM can also be built from [source](https://github.com/kemplab/pythonabm) once downloaded from GitHub.
```
pip setup.py install
python setup.py install
```

##
Expand Down Expand Up @@ -66,4 +66,4 @@ command show below.
conda install cudatoolkit
```

##
##
30 changes: 30 additions & 0 deletions pythonabm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,33 @@ def start(cls, output_dir):
cls.simulation_mode_3(name, output_dir) # archive simulation
else:
raise Exception("Mode does not exist!")


@classmethod
def make(cls, name, output_dir):
""" Creates a new brand new simulation and sets it up for
running within a separate script. Would need to call
run_simulation() on Simulation instance.
:param name: The name of the simulation.
:param output_dir: Path to simulation output directory.
:type name: str
:type output_dir: str
"""
# get absolute path and check that the output directory exists
output_dir = os.path.abspath(os.path.expanduser(output_dir))
output_dir = check_output_dir(output_dir)

# make simulation instance, update name, and add paths
sim = cls()
sim.name = name
sim.set_paths(output_dir)

# copy model files to simulation directory, ignoring __pycache__ files
direc_path = sim.main_path + name + "_copy"
shutil.copytree(os.getcwd(), direc_path, ignore=shutil.ignore_patterns("__pycache__", os.path.basename(output_dir[:-1])))

# set up the simulation agents
sim.full_setup()

return sim
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

setuptools.setup(
name="pythonabm",
version="0.3.2",
version="0.3.3",
author="Jack Toppen",
author_email="[email protected]",
description="Framework for building Agent-Based Models (ABMs) in Python",
long_description=long_description,
long_description_content_type='text/markdown',
packages=["pythonabm"],
python_requires=">=3.7",
zip_safe=False,
install_requires=[
"matplotlib",
"numpy>=1.11",
Expand Down

0 comments on commit 896ae67

Please sign in to comment.