Unverified Commit 23867991 authored by Jakob Görgen's avatar Jakob Görgen
Browse files

new symphony folder with new folder structure and packages + removed old orchestration framework

parent a14a0365
# Copyright 2024 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# external dependencies
# local dependencies
-e ../orchestration
-e ../utils
# Copyright 2024 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import argparse
import asyncio
from simbricks.utils import load_mod as utils
from simbricks import client
import sys
async def main():
parser = argparse.ArgumentParser(
prog="sim-chef",
description="CLI utility tool to send your SimBricks experiment script to the SimBricks backend for execution",
)
parser.add_argument(
"--submit-run",
metavar="SCRIPT.PY",
help="submit SimBricks expiriment python script as a run",
)
parser.add_argument(
"--check-run", metavar="RUNID", type=int, help="run id to check"
)
args = parser.parse_args()
base_client = client.BaseClient(base_url="http://0.0.0.0:8000")
namespace_client = client.NSClient(base_client=base_client, namespace="foo/bar/baz")
system_client = client.SimBricksClient(ns_client=namespace_client)
if args.submit_run:
await submit_run(system_client, args.submit_run)
elif args.check_run:
await check_run(system_client, args.check_run)
else:
print("Error: Need to specify one of the actions")
sys.exit(1)
async def submit_run(system_client: client.SimBricksClient, module_path):
experiment_mod = utils.load_module(module_path=module_path)
instantiations = experiment_mod.instantiations
sb_inst = instantiations[0]
sb_simulation = sb_inst.simulation
sb_system = sb_simulation.system
system = await system_client.create_system(sb_system)
system_id = int(system["id"])
system = await system_client.get_system(system_id)
print(system)
systems = await system_client.get_systems()
print(systems)
simulation = await system_client.create_simulation(system_id, sb_simulation)
sim_id = int(simulation["id"])
simulation = await system_client.get_simulation(sim_id)
print(simulation)
simulations = await system_client.get_simulations()
print(simulations)
instantiation = await system_client.create_instantiation(sim_id, None)
inst_id = int(instantiation["id"])
run = await system_client.create_run(inst_id)
print(run)
async def check_run(system_client, run_id):
run = await system_client.get_run(run_id)
print(run)
if __name__ == "__main__":
asyncio.run(main())
cli/simbricks/cli/__main__.py
\ No newline at end of file
# Copyright 2024 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import asyncio
import json
from simbricks.orchestration.runtime_new import simulation_executor
from simbricks.orchestration.instantiation import base as inst_base
from simbricks.orchestration.system import base as sys_base
from simbricks.orchestration.simulation import base as sim_base
from simbricks.orchestration.runtime_new import command_executor
from simbricks import client
verbose = True
async def run_instantiation(inst: inst_base.Instantiation) -> dict:
executor = command_executor.LocalExecutor()
runner = simulation_executor.SimulationSimpleRunner(
executor, inst, verbose
)
await runner.prepare()
output = await runner.run()
return output.__dict__
async def main():
base_client = client.BaseClient(base_url="http://0.0.0.0:8000")
namespace_client = client.NSClient(base_client=base_client, namespace="foo/bar/baz")
sb_client = client.SimBricksClient(namespace_client)
rc = client.RunnerClient(namespace_client, 42)
while True:
run_obj = await rc.next_run()
if not run_obj:
print('No valid run, sleeping')
await asyncio.sleep(5)
continue
print(f'Preparing run {run_obj["id"]}')
inst_obj = await sb_client.get_instantiation(run_obj['instantiation_id'])
sim_obj = await sb_client.get_simulation(inst_obj['simulation_id'])
sys_obj = await sb_client.get_system(sim_obj['system_id'])
system = sys_base.System.fromJSON(json.loads(sys_obj['sb_json']))
simulation = sim_base.Simulation.fromJSON(system, json.loads(sim_obj['sb_json']))
inst = inst_base.Instantiation(sim=simulation)
inst.preserve_tmp_folder = False
inst.create_checkpoint = True
print(f'Starting run {run_obj["id"]}')
await rc.update_run(run_obj['id'], 'running', '')
out = await run_instantiation(inst)
print(f'Finished run {run_obj["id"]}')
await rc.update_run(run_obj['id'], 'completed', json.dumps(out))
if __name__ == "__main__":
asyncio.run(main())
\ No newline at end of file
curl -X 'POST' \
'http://127.0.0.1:8000/ns/foo/bar/baz/-/systems' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJVMkJJVUhuNzJ6X25BcHVuQzNzdGI4QzUyamY0RzZ0ZTFnX2w2RU56TUdvIn0.eyJleHAiOjE3MzI1MjYyMjcsImlhdCI6MTczMjUyNTkyNywiYXV0aF90aW1lIjoxNzMyMDMzMTM1LCJqdGkiOiIzYWU1YWNmNC04MzIxLTRkYzQtODg0Mi05OTNmMGYzZDZiYzciLCJpc3MiOiJodHRwczovL2F1dGguc2ltYnJpY2tzLmlvL3JlYWxtcy9TaW1Ccmlja3MiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiMWYwMmE1Y2EtMGU1NC00NmRkLWJiZGUtZmU2NjNkYWE0OWQ2IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiYXBpLmF1dGguc2ltYnJpY2tzLmlvIiwic2lkIjoiMWRlYzExZWYtN2M1Mi00MjEyLWFhNjQtNzM0Y2JjMWI4ZjM2IiwiYWNyIjoiMCIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwczovLyouc2ltYnJpY2tzLmlvIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIiwiZGVmYXVsdC1yb2xlcy1zaW1icmlja3MiXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6Im9yZ2FuaXphdGlvbiBwcm9maWxlIGVtYWlsIG9yZ2FuaXphdGlvbiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJvcmdhbml6YXRpb24iOlsiTVBJLVNXUyJdLCJuYW1lIjoiSmFrb2IgR8O2cmdlbiIsInByZWZlcnJlZF91c2VybmFtZSI6Impnb2VyZ2VuQG1waS1zd3Mub3JnIiwiZ2l2ZW5fbmFtZSI6Ikpha29iIiwiZmFtaWx5X25hbWUiOiJHw7ZyZ2VuIiwiZW1haWwiOiJqZ29lcmdlbkBtcGktc3dzLm9yZyJ9.s4XXSPV6uTTxO94_YMmwmcFa1BE7zwMw7B9d8Vbelgg5emfNVji0GY16huCs4gncn8tNIz0HlGgr4hm_Crwi6h8hYyEACrMIqJJRJqioWLAdIT0tsbrFbH08SeyEcsqXQ4Id_os68Mq1Cc5PMB11s9T9PXru9DjRkJ7jxfCXiyKlhIo2wERIMwEOg2QIhXayNF2FGXgjvD1LkQPMdsdx9uo4ysDiGETlyXwNoR4odYM7yipQl9SAFnAgP37ws7SshmBiUWsNdQyJQ9b_4gIxetjF4S-EJzyT1zTSqBvTk-_VECNmyj-SimCLdGQK3qjeGs_h-LPC-Lb1_rqNzuUo-Q' \
-d '{"id":1,"namespace_id":44,"json": {"system": "test"}}'
# Copyright 2024 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "simbricks-utils"
version = "0.0.1"
description = "simbricks utils"
authors = [ "Jakob Görgen <jakob@simbricks.io>", ]
packages = [
{ include = "simbricks" }
]
# Copyright 2024 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# external dependencies
# local dependencies
# Copyright 2021 Max Planck Institute for Software Systems, and # Copyright 2024 Max Planck Institute for Software Systems, and
# National University of Singapore # National University of Singapore
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
...@@ -20,59 +20,25 @@ ...@@ -20,59 +20,25 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import json import os
import pathlib import importlib.util
import time
import typing as tp
from simbricks.orchestration.experiments import Experiment
if tp.TYPE_CHECKING: # prevent cyclic import class SimBricksModuleLoadError(Exception):
from simbricks.orchestration import exectools, simulators pass
class ExpOutput(object): def load_module(module_path: str):
"""Manages an experiment's output.""" modname, _ = os.path.splitext(os.path.basename(module_path))
def __init__(self, exp: Experiment) -> None: spec = importlib.util.spec_from_file_location(modname, module_path)
self.exp_name = exp.name if spec is None:
self.start_time = None raise SimBricksModuleLoadError("spec is None")
self.end_time = None
self.success = True
self.interrupted = False
self.metadata = exp.metadata
self.sims: tp.Dict[str, tp.Dict[str, tp.Union[str, tp.List[str]]]] = {}
def set_start(self) -> None: mod = importlib.util.module_from_spec(spec)
self.start_time = time.time() if spec.loader is None:
raise SimBricksModuleLoadError("spec.loader is None")
def set_end(self) -> None: spec.loader.exec_module(mod)
self.end_time = time.time()
def set_failed(self) -> None: return mod
self.success = False
def set_interrupted(self) -> None:
self.success = False
self.interrupted = True
def add_sim(
self, sim: 'simulators.Simulator', comp: 'exectools.Component'
) -> None:
obj = {
'class': sim.__class__.__name__,
'cmd': comp.cmd_parts,
'stdout': comp.stdout,
'stderr': comp.stderr,
}
self.sims[sim.full_name()] = obj
def dump(self, outpath: str) -> None:
pathlib.Path(outpath).parent.mkdir(parents=True, exist_ok=True)
with open(outpath, 'w', encoding='utf-8') as file:
json.dump(self.__dict__, file, indent=4)
def load(self, file: str) -> None:
with open(file, 'r', encoding='utf-8') as fp:
for k, v in json.load(fp).items():
self.__dict__[k] = v
Markdown is supported
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