Commit cde3219d authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

Squashed 'Tools/SUQController/' changes from b1be60c6..b56433db

b56433db finish version 1.0 (examples work on Ubuntu and Win10)
4df67e62 #48, but test on Windows before closing

git-subtree-dir: Tools/SUQController
git-subtree-split: b56433db9f7b31e05be96ea3a45d8ddf082bd7ac
parent 94eb3fbd
......@@ -16,7 +16,7 @@ __authors__ = "Daniel Lehmberg"
__credits__ = ["n/a"]
# --------------------------------------------------
# To generate a new reqirements.txt file run in console (install vis 'pip3 install pipreqs'):
# To generate a new requirements.txt file run in console (install vis 'pip3 install pipreqs'):
# pipreqs --use-local --force /home/daniel/REPOS/suq-controller
with open('requirements.txt', "r") as f:
......
......@@ -16,4 +16,4 @@ from suqc.parameter.postchanges import ScenarioChanges
from suqc.qoi import *
from suqc.request import *
__version__ = "1.0rc1"
__version__ = "1.0"
......@@ -2,10 +2,10 @@
# TODO: """ << INCLUDE DOCSTRING (one-line or multi-line) >> """
import abc
import os
import subprocess
import pickle
import abc
import zipfile
from fabric import Connection
......@@ -143,10 +143,8 @@ class ServerRequest(object):
def _compress_output(self):
compressed_filepath = self._join_linux_path([self.remote_folder_path, "vadere_output.tar.gz"], is_folder=False)
# from https://stackoverflow.com/questions/939982/how-do-i-tar-a-directory-of-files-and-folders-without-including-the-directory-it
s = f"""cd {self.remote_output_folder()} && tar -zcvf ../{os.path.basename(compressed_filepath)} . && cd -"""
compressed_filepath = self._join_linux_path([self.remote_folder_path, "vadere_output.zip"], is_folder=False)
s = f"""python3 -m zipfile -c {compressed_filepath} {self.remote_output_folder()}"""
self.server.con.run(s)
return compressed_filepath
......@@ -193,8 +191,10 @@ class ServerRequest(object):
if not os.path.exists(path_output):
create_folder(path_output)
subprocess.call(["tar", "xvzf", local_compressed_file, "-C", path_output])
subprocess.call(["rm", local_compressed_file])
with zipfile.ZipFile(local_compressed_file, "r") as result_zip:
result_zip.extractall(path=path_output)
os.remove(local_compressed_file)
def _remove_remote_folder(self):
s = f"""rm -r {self.remote_folder_path}"""
......
......@@ -25,8 +25,8 @@ run_local = True
# Example where the values of 'speedDistributionMean' are set between 0.1 and 1.5 in 5 equidistant points
if __name__ == "__main__": # main required by Windows to run in parallel
if __name__ == "__main__": # main required by Windows to run in parallel
setup = SingleKeyVaryScenario(scenario_path=path2scenario, # -> path to the Vadere .scenario file to vary
key="speedDistributionMean", # -> parameter key to change
......
......@@ -9,16 +9,18 @@ from tutorial.imports import *
run_local = True
###############################################################################################################
# Usecase: Set yourself the parameters you want to change. Do this by defining a list of dictionaries with the
# corresponding parameter. Again, the Vadere output is deleted after all scenarios run.
# Set own values to vary, they don't have to be the same - in the first run acceleration is left to default.
par_var = [{"speedDistributionMean": 1.0, "maximumSpeed": 3.0},
{"speedDistributionMean": 1.3, "maximumSpeed": 4.0, "acceleration": 3.0}]
if __name__ == "__main__": # main required by Windows to run in parallel
# Set own values to vary, they don't have to be the same - in the first run acceleration is left to default.
par_var = [{"speedDistributionMean": 1.0, "maximumSpeed": 3.0},
{"speedDistributionMean": 1.3, "maximumSpeed": 4.0, "acceleration": 3.0}]
setup = QuickVaryScenario(scenario_path=path2scenario,
parameter_var=par_var,
qoi="density.txt",
......
......@@ -8,13 +8,15 @@ sys.path.append(os.path.abspath(".."))
from tutorial.imports import *
run_local = True
run_local = False
# NOTE: If running this script twice, there is an user input required. Because an "output folder" already exists from
# the first run, this output folder gets replaced with the next run. Therefore, the old output is removed.
if __name__ == "__main__": # main required by Windows to run in parallel
###############################################################################################################
# Usecase: Provide a single Vadere scenario and location to write out the output to.
setup = SingleScenarioOutput(path_scenario=path2scenario,
path_output=os.path.join(path2tutorial, "example_output"),
model=path2model,
......@@ -26,14 +28,12 @@ if __name__ == "__main__": # main required by Windows to run in parallel
else:
setup.remote()
###############################################################################################################
# Usecase: Provide a folder with more than .scenario file and an output folder. All scenarios are simulated, also
# in parallel). Here it is not possible to hand in a quantity of interest, because there is no guarantee that
# all scenarios have the same processors. Because there is only one example scenario file, only this will be
# executed.
setup = MultiScenarioOutput(path_scenarios=path2tutorial,
path_output=os.path.join(path2tutorial, "example_multirun_output"),
model=path2model)
......@@ -42,7 +42,3 @@ if __name__ == "__main__": # main required by Windows to run in parallel
res = setup.run(2)
else:
res = setup.remote(2)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment