Verified Commit 23871f65 authored by Raphaël Bleuse's avatar Raphaël Bleuse
Browse files

Remove pybatsim.batsim.tools module

parent b9f7c3d6
......@@ -21,8 +21,6 @@ let
"^src/pybatsim/.\+\.py$"
"^src/pybatsim/batsim$"
"^src/pybatsim/batsim/.\+\.py$"
"^src/pybatsim/batsim/tools$"
"^src/pybatsim/batsim/tools/.\+\.py$"
"^src/pybatsim/schedulers$"
"^src/pybatsim/schedulers/.\+\.py$"
"^src/pybatsim/schedulers/unMaintained$"
......
"""
batsim.tools
~~~~~~~~~~~~
Experimental tools useful only for data from Pybatsim schedulers.
"""
"""
batsim.tools.launcher
~~~~~~~~~~~~~~~~~~~~~
Tools to launch pybatsim schedulers.
"""
import json
import sys
import time
from datetime import timedelta
from pybatsim.batsim.batsim import Batsim
def launch_scheduler(scheduler,
socket_endpoint,
event_socket_endpoint,
options,
timeout):
print("Scheduler: {} ({})".format(scheduler.__class__.__name__, options))
time_start = time.time()
#try:
bs = Batsim(scheduler,
socket_endpoint,
timeout,
event_socket_endpoint)
aborted = False
# try:
bs.start()
# except KeyboardInterrupt:
# print("Aborted...")
# aborted = True
time_ran = str(timedelta(seconds=time.time() - time_start))
print("Simulation ran for: " + time_ran)
print("Job submitted:", bs.nb_jobs_submitted,
", scheduled:", bs.nb_jobs_scheduled,
", rejected:", bs.nb_jobs_rejected,
", killed:", bs.nb_jobs_killed,
", changed:", len(bs.jobs_manually_changed),
", timeout:", bs.nb_jobs_timeout,
", success", bs.nb_jobs_successful,
", complete:", bs.nb_jobs_completed)
if bs.nb_jobs_submitted != (
bs.nb_jobs_scheduled + bs.nb_jobs_rejected +
len(bs.jobs_manually_changed)):
return 1
return 1 if aborted else 0
#except KeyboardInterrupt:
# print("Aborted...")
# return 1
return 0
......@@ -8,12 +8,14 @@
import argparse
import io
import json
import logging
import sys
import time
from pybatsim import __version__
from pybatsim.batsim.batsim import Batsim
from pybatsim.plugin import (SCHEDULER_ENTRY_POINT, find_ambiguous_scheduler_names,
find_plugin_schedulers)
from pybatsim.batsim.tools.launcher import launch_scheduler as legacy_launch_scheduler
# TODO: relocate under scheduler module?
......@@ -116,17 +118,51 @@ def _abort_on_ambiguous_scheduler_name(name):
sys.exit(1)
def run_simulation(scheduler, *, socket_endpoint, event_socket_endpoint, timeout):
"""Instantiate the connection to Batsim and run the simulation."""
batsim = Batsim(
scheduler,
network_endpoint=socket_endpoint,
event_endpoint=event_socket_endpoint,
timeout=timeout
)
tstart = time.perf_counter_ns() # clock of highest resolution
batsim.start()
tend = time.perf_counter_ns()
logging.info(f'Simulation ran {(tend - tstart) * 1e-9:e} seconds (elapsed real time)')
logging.info(
'jobs: ' +
', '.join((
f'{batsim.nb_jobs_submitted} submitted',
f'{batsim.nb_jobs_scheduled} scheduled',
f'{batsim.nb_jobs_rejected} rejected',
f'{batsim.nb_jobs_killed} killed',
f'{len(batsim.jobs_manually_changed)} changed',
f'{batsim.nb_jobs_timeout} timeout',
f'{batsim.nb_jobs_successful} success',
f'{batsim.nb_jobs_completed} complete',
))
)
# TODO: deport check to Batsim class
if batsim.nb_jobs_submitted != \
batsim.nb_jobs_scheduled + batsim.nb_jobs_rejected + len(batsim.jobs_manually_changed):
sys.exit(1)
def main(args=None):
logging.basicConfig(level=logging.INFO)
parser = _build_parser()
arguments = parser.parse_args(args)
# instantiate scheduler
_abort_on_ambiguous_scheduler_name(arguments.scheduler)
scheduler = get_scheduler_by_name(arguments.scheduler, options=arguments.scheduler_options)
# launch simulation
legacy_launch_scheduler(
run_simulation(
scheduler=scheduler,
socket_endpoint=arguments.socket_endpoint,
event_socket_endpoint=arguments.event_socket_endpoint,
options=arguments.scheduler_options,
timeout=arguments.timeout,
)
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