Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
8c64641
Skeleton of orchestrator entrypoint
Jun 29, 2022
cb86ef1
added total scheduled time metric
DaGinYus Jun 29, 2022
8606a1b
added total scheduled count metric
DaGinYus Jun 30, 2022
053ba64
move metric functions to a separate file
DaGinYus Jun 30, 2022
6d42329
added functions for getting the data we want, implemented binning by …
DaGinYus Jun 30, 2022
7ca823e
small comments and modifications to record_metrics function
DaGinYus Jun 30, 2022
98c5e14
available_time
Jun 30, 2022
5daaad5
available_time
Jun 30, 2022
0737f96
time capping function for filtering metrics (WIP)
DaGinYus Jun 30, 2022
29dca71
available time
Jun 30, 2022
6d1505c
Some changes for supporting running the scheduler simulator
Jul 1, 2022
3f372da
draft airmass metrics
Jul 1, 2022
b357c1d
merge in branch and change record_metrics signature
Jul 1, 2022
89ad3cf
fixed bugs in metrics to get a runnable program
DaGinYus Jul 5, 2022
25d4c96
added documentation
DaGinYus Jul 5, 2022
9873cfd
updated to reflect renamed function in metrics.py
DaGinYus Jul 5, 2022
e3a4882
michael
Jul 5, 2022
926da49
finished ideal average airmass calculation
DaGinYus Jul 6, 2022
59a2efd
idk
Jul 6, 2022
c12a14d
this is what i want
Jul 6, 2022
4d702aa
fix merge conflicts
Jul 6, 2022
e89b460
add get midpoint airmass
Jul 6, 2022
d153bff
skeleton of planned tests for scheduler simulator metrics
DaGinYus Jul 6, 2022
049f8ee
Merge branch 'add_orchestrator' of github.com:observatorycontrolsyste…
DaGinYus Jul 6, 2022
7ed5110
fixed file and began moving things into a class
DaGinYus Jul 6, 2022
1ae4a07
midpoint airmasses
Jul 6, 2022
1ddbf3c
fix merge conflicts and add midpoint airmasses
Jul 6, 2022
fc2c961
fix build issues
Jul 6, 2022
8de30d5
test bin filler function
DaGinYus Jul 7, 2022
634ccc5
percent of function was deleted on accident during merge resolution
DaGinYus Jul 7, 2022
78ac01f
Merge branch 'add_orchestrator' of github.com:observatorycontrolsyste…
DaGinYus Jul 7, 2022
6d4f036
test binning function, counter function, and aggregators
DaGinYus Jul 7, 2022
fc134f4
moved some functions around
DaGinYus Jul 7, 2022
8495dc4
merge conflict fix
Jul 7, 2022
d31fb3d
Merge branch 'add_orchestrator' of github.com:observatorycontrolsyste…
Jul 7, 2022
58eb001
tested airmass metrics and debugged
Jul 7, 2022
c190f0b
migrate airmass data to a json file
DaGinYus Jul 7, 2022
1563bf1
ignore rapid response if there are no rr scheduler results
DaGinYus Jul 7, 2022
9a2b3f0
migrate
Jul 7, 2022
a83fbce
fixed reservation.request
Jul 8, 2022
d6fa06c
fixed reservation.request
Jul 8, 2022
2dd0d20
fixed reservation.request
Jul 8, 2022
e84b796
some style fixes
Jul 8, 2022
22c9512
some refactoring into a class for metrics
DaGinYus Jul 8, 2022
e337186
resolve merge conflicts
DaGinYus Jul 8, 2022
0d2f55c
tests for refactored code
DaGinYus Jul 8, 2022
040ac35
Add code to submit metrics to opensearch
Jul 8, 2022
039d1f4
updated orchestrator to work with current iteration of metrics
DaGinYus Jul 8, 2022
9a48a88
resolve merge conflicts
DaGinYus Jul 8, 2022
6e739e9
merged too fast, missed some bugs
DaGinYus Jul 8, 2022
c29460e
refactoring airmasses metrics into the metrics calculator class
Jul 9, 2022
5031653
add tests for averaging multiple airmasses
qingzewu Jul 11, 2022
e9030b1
upload another airmass mock data for testing
qingzewu Jul 11, 2022
a75bb3a
delete the parameters passed in for airmasses functions
qingzewu Jul 11, 2022
781950a
deleted debug prints
qingzewu Jul 11, 2022
524ef2b
reworked binning function
DaGinYus Jul 11, 2022
e89db58
fix merge conflicts
DaGinYus Jul 11, 2022
b2cc024
updated to only request from observe portal once
DaGinYus Jul 11, 2022
17d997f
Store off normal and rr scheduling inputs for accesibility in metrics
Jul 11, 2022
c2ffbbd
Store the input reservations within the scheduler results too
Jul 11, 2022
7deb153
add documentation for airmass metrics calculation functions
qingzewu Jul 11, 2022
ee0a305
update percent scheduled logic to reflect actual scheduler input
DaGinYus Jul 11, 2022
0b1de91
updated binning function to bin additional data
DaGinYus Jul 12, 2022
3700fcc
updated binning function to handle floats
DaGinYus Jul 12, 2022
47bb974
add different metrics for midpoint airmass and resolve merge conflicts
qingzewu Jul 12, 2022
55feb90
merge airmass metrics into one function call
qingzewu Jul 12, 2022
65c6cca
metrics code cleaning
qingzewu Jul 12, 2022
87eb7d6
merge and clean up airmass function
DaGinYus Jul 12, 2022
4ac744b
minor edit in binning test
DaGinYus Jul 12, 2022
88be215
merged too fast (again) sadface
DaGinYus Jul 12, 2022
2555585
merge conflict resolve
qingzewu Jul 12, 2022
3ac3ed3
test
qingzewu Jul 13, 2022
e334ad6
remove emacs autosave file
DaGinYus Jul 13, 2022
c728c10
finished updating airmass metrics testings
qingzewu Jul 13, 2022
827332f
Merge branch 'add_orchestrator' of github.com:observatorycontrolsyste…
qingzewu Jul 13, 2022
4bb8bf1
small speed optimizations and additional priority metrics
DaGinYus Jul 13, 2022
104a76c
fix merge conflicts
DaGinYus Jul 13, 2022
8cff4e4
wip data caching using redis, tried to test but ran out of storage sp…
DaGinYus Jul 13, 2022
4604f95
bugfix for caching the wrong object type
DaGinYus Jul 13, 2022
11fcaaf
reenable sending to opensearch after testing
DaGinYus Jul 13, 2022
a60a2d1
fixed redis cache error
qingzewu Jul 13, 2022
5e8f516
Merge branch 'add_orchestrator' of github.com:observatorycontrolsyste…
qingzewu Jul 13, 2022
f44e948
Merge branch 'add_orchestrator' of github.com:observatorycontrolsyste…
DaGinYus Jul 13, 2022
28152a0
add documentation for airmass data
qingzewu Jul 13, 2022
cef09c4
Add configdb overrides for simulation
Jul 13, 2022
320cfde
Merge branch 'add_orchestrator' of github.com:observatorycontrolsyste…
Jul 13, 2022
2dcd4d4
Merge branch 'feature/optimize_airmass' of github.com:observatorycont…
Jul 13, 2022
99a2320
Fix the missing redis instance
Jul 13, 2022
a7acaeb
fixed request group attribute error
DaGinYus Jul 14, 2022
be7cb98
Fix rs_target serizliation
Jul 14, 2022
ddd3317
Fix error in single target airmasses
Jul 14, 2022
2d8382a
fix dict values list
Jul 14, 2022
b2376a7
bugfixes in airmass optimization caching
DaGinYus Jul 14, 2022
fdd9c98
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
DaGinYus Jul 14, 2022
11c9ca5
fixed incorrect total count for priorities
DaGinYus Jul 14, 2022
071f419
changed airmass weighting to be an environment variable
DaGinYus Jul 14, 2022
448ed76
fixed type error in airmass weighting coefficient
DaGinYus Jul 14, 2022
03fafbd
plotting functions for airmass coefficient data
DaGinYus Jul 18, 2022
b177bb1
remove emacs autosave
DaGinYus Jul 18, 2022
5e327cb
update to include worst airmass data, optimizations to midpoint airma…
DaGinYus Jul 18, 2022
052940b
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
DaGinYus Jul 18, 2022
f7f3baf
implemented image export and cleaned up chart labels
DaGinYus Jul 19, 2022
3005922
moved helper functions to plotutils
DaGinYus Jul 19, 2022
b71e88c
add plot effective priority
qingzewu Jul 19, 2022
c6c6c9d
uniform scaling for histograms
DaGinYus Jul 20, 2022
324f3d8
small documentation updates and optimizations
DaGinYus Jul 20, 2022
572f0f8
no longer dumps all the metrics to the log
DaGinYus Jul 20, 2022
730ad09
changed optimization_type back to default from 'AIRMASS'
DaGinYus Jul 20, 2022
5dec6e8
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
DaGinYus Jul 20, 2022
84b5fe0
added basic cli interface
DaGinYus Jul 20, 2022
7f4486c
fixed ploting effective priority
qingzewu Jul 20, 2022
cb81051
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
qingzewu Jul 20, 2022
f98b071
updated master plotting file, can be turned into example code
DaGinYus Jul 21, 2022
a1bc9d3
update to include raw duration and priority data
DaGinYus Jul 21, 2022
dbbe618
priority duration scatter plot for with/withou duration
qingzewu Jul 22, 2022
00e9774
fixed unscheduled duration data
DaGinYus Jul 22, 2022
bde8e80
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
DaGinYus Jul 22, 2022
22d1dc2
plot the priority duration scatterplot
qingzewu Jul 25, 2022
b9638a6
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
qingzewu Jul 25, 2022
9458288
fixed priorities
DaGinYus Jul 25, 2022
fcdea71
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
DaGinYus Jul 25, 2022
96b1283
added functionality to store raw data, improved documentation
DaGinYus Jul 25, 2022
f53b548
heat map for priority duration
qingzewu Jul 25, 2022
67705f5
fill feature added to binning function
DaGinYus Jul 25, 2022
7102b9f
minor change to fill functionality
DaGinYus Jul 25, 2022
5eef112
oops, broke something, changing it back
DaGinYus Jul 25, 2022
d5e8045
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
qingzewu Jul 25, 2022
3aa78bc
updated documentation and slightly modified binning function behavior
DaGinYus Jul 26, 2022
75364d8
changed default binning behavior
DaGinYus Jul 26, 2022
3c9750c
minor updates to binning test
DaGinYus Jul 26, 2022
bff610b
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
qingzewu Jul 26, 2022
9736d7e
heatmap
qingzewu Jul 26, 2022
49f478a
priority duration
qingzewu Jul 26, 2022
3de1ab3
heatmap
qingzewu Jul 26, 2022
15bc9fa
add timing decorators to time our metrics runtime
qingzewu Jul 27, 2022
b392fe6
add timing decorators to time our metrics runtime
qingzewu Jul 27, 2022
ba5d27a
slew distance calculations
DaGinYus Jul 27, 2022
84be11b
added new plot for effective priority binned data
DaGinYus Jul 27, 2022
074a7e9
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
DaGinYus Jul 27, 2022
f824110
add slew distance to orchestrator
DaGinYus Jul 27, 2022
629f7ec
update to handle non sidereal targets
DaGinYus Jul 27, 2022
2036de4
wip restructure for more user friendly code
DaGinYus Jul 29, 2022
af0fa05
merge plots
qingzewu Jul 29, 2022
97b6518
working UI for plotting program
DaGinYus Jul 29, 2022
098fe31
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
DaGinYus Jul 29, 2022
3e134fb
updated documentation
DaGinYus Jul 29, 2022
e231050
updated documentation, small change to barplotting function
DaGinYus Jul 29, 2022
ce444ec
fixed bug with duration aggregation
DaGinYus Jul 29, 2022
8debc40
small naming change
DaGinYus Jul 29, 2022
88cc546
ported some more functions from plot_all
DaGinYus Jul 29, 2022
e6fa334
plot func
qingzewu Jul 29, 2022
c362f32
plot func
qingzewu Jul 29, 2022
91c32d0
added window duration calculation
DaGinYus Aug 1, 2022
d2f0e40
more airmass plots
DaGinYus Aug 1, 2022
f19a680
bugfix for misindented break statement, slight input cleaning
DaGinYus Aug 1, 2022
fc47c2c
small modification to error handling, renamed plot_barplot to plot_mu…
DaGinYus Aug 1, 2022
72ba3c1
simulation
qingzewu Aug 1, 2022
6457e7c
plot input durations
qingzewu Aug 2, 2022
083f2e1
stacked sched/unsched requests
qingzewu Aug 2, 2022
54e1ebc
add heatmap plots
qingzewu Aug 3, 2022
5125204
change to 300 dpi
DaGinYus Aug 3, 2022
29de01c
move to new airmass tests
DaGinYus Aug 3, 2022
40b7abe
fix merge conflicts
DaGinYus Aug 3, 2022
975cee2
update plots
qingzewu Aug 3, 2022
c579d29
minor update on plotfuncs
qingzewu Aug 4, 2022
ad6432f
small fix to titles and titlesizes
DaGinYus Aug 4, 2022
e4c87fb
modified title sizes to be bigger
DaGinYus Aug 4, 2022
19522a0
remove old plotting files, they have been integrated into plotfuncs
DaGinYus Aug 4, 2022
976e48b
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
DaGinYus Aug 4, 2022
40a0ea4
removed old plotting file
DaGinYus Aug 4, 2022
7223030
fixed some line plot things
DaGinYus Aug 4, 2022
abe8f1a
minor changes
qingzewu Aug 5, 2022
d11129d
Merge branch 'optimize_airmass_in_orchestrator' of github.com:observa…
qingzewu Aug 5, 2022
dac07b9
fixed whitespace issues
DaGinYus Aug 5, 2022
43a9ed9
began writing readme
DaGinYus Aug 5, 2022
1cff1b7
modified env variables and 'show all' behavior
DaGinYus Aug 5, 2022
168ac8d
minor change to the way input data is handled
DaGinYus Aug 5, 2022
2046f0b
finished first draft of readme
DaGinYus Aug 5, 2022
af270d5
update datasets
qingzewu Aug 5, 2022
1290c6e
pass copy instead of reference
qingzewu Aug 5, 2022
7d984f0
few updates to the orchestrator readme
Aug 6, 2022
ae66c15
Merge branch 'document_orchestrator' of github.com:observatorycontrol…
Aug 6, 2022
2480132
fixed utilization calculation
DaGinYus Aug 8, 2022
e23d982
Merge branch 'document_orchestrator' of github.com:observatorycontrol…
DaGinYus Aug 8, 2022
e5362db
updated error handling and masked useless opensearch warning messages
DaGinYus Aug 8, 2022
8f17d74
small rewordings
DaGinYus Aug 8, 2022
26280af
changed wording for opensearch env variable
DaGinYus Aug 8, 2022
abc8672
updated documentation and fixed trailing whitespace
DaGinYus Aug 8, 2022
ea63cbb
updated documentation
DaGinYus Aug 8, 2022
74c279b
merge in some readme changes
Aug 8, 2022
aefb704
fix for airmass optimization
Aug 9, 2022
e6ce825
divide by zero bugfix
DaGinYus Aug 9, 2022
c12c975
broke plots into sections
DaGinYus Aug 9, 2022
7abc28d
modified binning option
DaGinYus Aug 10, 2022
020a1f3
changed comment for clarity
DaGinYus Aug 10, 2022
841c176
Merge branch 'main' of github.com:observatorycontrolsystem/adaptive_s…
Aug 10, 2022
7d2b9d0
Merge pull request #56 from observatorycontrolsystem/document_orchest…
jnation3406 Aug 10, 2022
6f1dc1d
Merge branch 'main' of github.com:observatorycontrolsystem/adaptive_s…
Aug 10, 2022
a8d2810
Merge branch 'feature/optimize_airmass' of github.com:observatorycont…
Aug 10, 2022
b9b2dbb
Merge branch 'add_orchestrator' into optimize_airmass_in_orchestrator
jnation3406 Aug 10, 2022
7278c68
Merge pull request #57 from observatorycontrolsystem/optimize_airmass…
jnation3406 Aug 10, 2022
7e68ce1
Merge branch 'add_orchestrator' of github.com:observatorycontrolsyste…
DaGinYus Aug 11, 2022
0277784
is bad
DaGinYus Aug 11, 2022
20ead84
cache by request in redis instead of one big dict
DaGinYus Aug 11, 2022
86e9e9c
pep8 fixes and import renaming for clarity
DaGinYus Aug 12, 2022
dbae293
forgot to save the file haha
DaGinYus Aug 12, 2022
040a199
fix merge conflict
DaGinYus Aug 12, 2022
67bba5a
final commit of Michael; adapted input requests plot to fit new test …
qingzewu Aug 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ python -c "from ortools.linear_solver import pywraplp as p; p.Solver.CreateSolve
python -c "from ortools.linear_solver import pywraplp as p; p.Solver.CreateSolver('GLPK')"

# assumption: if it's trying to read the licence, it's probably linked properly
strace -e openat python -c "from ortools.linear_solver import pywraplp as p; p.Solver.CreateSolver('GUROBI')" 2>&1 | grep -q gurobi.lic
# strace -e openat python -c "from ortools.linear_solver import pywraplp as p; p.Solver.CreateSolver('GUROBI')" 2>&1 | grep -q gurobi.lic
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just so the interns could build the container without full priviledges - we can remove this comment

EOT

USER app
Expand Down
19 changes: 18 additions & 1 deletion adaptive_scheduler/configdb_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ConfigDBInterface(SendMetricMixin):
"""

def __init__(self, configdb_url, telescope_classes, telescopes_file='data/telescopes.json',
active_instruments_file='data/active_instruments.json'):
active_instruments_file='data/active_instruments.json', overrides=None):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file all pertain to being able to override configdb values with a dict provided (which can be read in from a simple json file in the simulation orchestrator)

self.configdb_url = configdb_url
if not self.configdb_url.endswith('/'):
self.configdb_url += '/'
Expand All @@ -31,11 +31,28 @@ def __init__(self, configdb_url, telescope_classes, telescopes_file='data/telesc
self.active_instruments_file = active_instruments_file
self.active_instruments = None
self.telescope_info = None
self.overrides = overrides
self.update_configdb_structures()

def update_configdb_structures(self):
self.update_telescope_info()
self.apply_overrides_to_telescopes()
self.update_active_instruments()
self.apply_overrides_to_instruments()

def apply_overrides_to_telescopes(self):
if self.overrides:
for telescope in self.overrides.get('telescopes', {}).keys():
if telescope in self.telescope_info and 'status' in self.overrides['telescopes'][telescope]:
self.telescope_info[telescope]['status'] = self.overrides['telescopes'][telescope]['status']

def apply_overrides_to_instruments(self):
if self.overrides and self.overrides.get('instruments', {}):
for instrument in self.active_instruments:
if instrument['code'] in self.overrides['instruments']:
instrument['state'] = self.overrides['instruments'][instrument['code']].get('state', instrument['state'])
if instrument['instrument_type']['code'] in self.overrides['instruments']:
instrument['state'] = self.overrides['instruments'][instrument['instrument_type']['code']].get('state', instrument['state'])

def update_active_instruments(self):
try:
Expand Down
31 changes: 19 additions & 12 deletions adaptive_scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def run_scheduler(self, scheduler_input, estimated_scheduler_end, semester_detai

print_compound_reservations(compound_reservations)
# Prepare scheduler result
scheduler_result = SchedulerResult()
scheduler_result = SchedulerResult(input_reservations=compound_reservations)
scheduler_result.schedule = {}
scheduler_result.resource_schedules_to_cancel = list(available_resources)

Expand Down Expand Up @@ -569,14 +569,15 @@ class SchedulerResult(object):
'''Aggregates together output of a scheduler run
'''

def __init__(self, schedule=None, resource_schedules_to_cancel=None):
def __init__(self, schedule=None, resource_schedules_to_cancel=None, input_reservations=None):
'''
schedule - Expected to be a dict mapping resource to scheduled reservations
resource_schedules_to_cancel - List of resources to cancel schedules on - this is the list of all available
resources that have any request scheduled on them. Resources with no requests scheduled on them will be
removed from the list.
'''
self.schedule = schedule if schedule else {}
self.input_reservations = input_reservations if input_reservations else []
self.resource_schedules_to_cancel = resource_schedules_to_cancel if resource_schedules_to_cancel else []

def count_reservations(self):
Expand Down Expand Up @@ -626,11 +627,13 @@ def __init__(self, sched_params, scheduler, network_interface, network_model, in
self.sched_params = sched_params
self.warm_starts_setting = sched_params.warm_starts
self.scheduler = scheduler
self.normal_scheduler_input = None
self.rr_scheduler_input = None
self.normal_scheduler_result = None
self.rr_scheduler_result = None
self.network_interface = network_interface
self.network_model = network_model
self.input_factory = input_factory
self.normal_scheduled_requests_by_rg = {}
self.rr_scheduled_requests_by_rg = {}
self.log = logging.getLogger(__name__)
# List of strings to be printed in final scheduling summary
self.summary_events = []
Expand Down Expand Up @@ -828,6 +831,10 @@ def _can_apply_scheduler_result(self, scheduler_result, apply_deadline):
self.log.warn("Empty scheduler result. Schedule will not be saved.")
return False

if self.sched_params.simulate_now:
# Don't care about deadlines if you are simulating a time in the past
return True

estimated_apply_timedelta = self.avg_save_time_per_reservation_timedelta * scheduler_result.count_reservations()
estimated_apply_completion = datetime.utcnow() + estimated_apply_timedelta
self.log.info(
Expand Down Expand Up @@ -973,7 +980,7 @@ def create_rr_schedule(self, scheduler_input):
rr_scheduler_result = self.call_scheduler(scheduler_input, deadline)

try:
self.rr_scheduled_requests_by_rg = rr_scheduler_result.get_scheduled_requests_by_request_group_id()
self.rr_scheduler_result = rr_scheduler_result
self.apply_rr_result(rr_scheduler_result, scheduler_input, deadline)
rr_scheduling_end = datetime.utcnow()
rr_scheduling_timedelta = rr_scheduling_end - rr_scheduling_start
Expand Down Expand Up @@ -1019,7 +1026,7 @@ def create_normal_schedule(self, scheduler_input):
resources_to_clear = list(self.network_model.keys())
try:
before_apply = datetime.utcnow()
self.normal_scheduled_requests_by_rg = scheduler_result.get_scheduled_requests_by_request_group_id()
self.normal_scheduler_result = scheduler_result
n_submitted = self.apply_normal_result(scheduler_result,
scheduler_input,
resources_to_clear, deadline)
Expand Down Expand Up @@ -1066,18 +1073,18 @@ def scheduling_cycle(self, schedule_type, network_state_timestamp, rr_schedule_r
set_schedule_type(schedule_type)
result = None
if schedule_type == NORMAL_OBSERVATION_TYPE:
scheduler_input = self.input_factory.create_normal_scheduling_input(
self.normal_scheduler_input = self.input_factory.create_normal_scheduling_input(
self.estimated_normal_run_timedelta.total_seconds(),
scheduled_requests_by_rg=self.normal_scheduled_requests_by_rg,
scheduled_requests_by_rg=self.normal_scheduler_result.get_scheduled_requests_by_request_group_id() if self.normal_scheduler_result else {},
rr_schedule=rr_schedule_result.schedule,
network_state_timestamp=network_state_timestamp)
result = self.create_normal_schedule(scheduler_input)
result = self.create_normal_schedule(self.normal_scheduler_input)
elif schedule_type == RR_OBSERVATION_TYPE:
scheduler_input = self.input_factory.create_rr_scheduling_input(
self.rr_scheduler_input = self.input_factory.create_rr_scheduling_input(
self.estimated_rr_run_timedelta.total_seconds(),
scheduled_requests_by_rg=self.rr_scheduled_requests_by_rg,
scheduled_requests_by_rg=self.rr_scheduler_result.get_scheduled_requests_by_request_group_id() if self.rr_scheduler_result else {},
network_state_timestamp=network_state_timestamp)
result = self.create_rr_schedule(scheduler_input)
result = self.create_rr_schedule(self.rr_scheduler_input)
return result


Expand Down
4 changes: 3 additions & 1 deletion adaptive_scheduler/scheduler_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __init__(self,
ignore_ipp=to_bool(os.getenv('IGNORE_IPP_VALUES', 'False')),
avg_reservation_save_time_seconds=float(os.getenv('INITIAL_PER_RESERVATION_SAVE_TIME', 0.05)),
normal_runtime_seconds=float(os.getenv('INITIAL_NORMAL_RUNTIME', 360.0)),
rr_runtime_seconds=float(os.getenv('INITIAL_RAPID_RESPONSE_RUNTIME', 120.0))):
rr_runtime_seconds=float(os.getenv('INITIAL_RAPID_RESPONSE_RUNTIME', 120.0)),
simulation_opensearch_index=os.getenv('SIMULATION_OPENSEARCH_INDEX', '')):
self.dry_run = dry_run
self.no_weather = no_weather
self.no_singles = no_singles
Expand Down Expand Up @@ -92,6 +93,7 @@ def __init__(self,
self.opensearch_excluded_observatories = opensearch_excluded_observatories.split(',')
else:
self.opensearch_excluded_observatories = []
self.simulation_opensearch_index = simulation_opensearch_index


class SchedulingInputFactory(object):
Expand Down
63 changes: 63 additions & 0 deletions adaptive_scheduler/simulation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Adaptive Scheduler Simulator Orchestrator

The orchestrator allows for running the adaptive scheduler in a simulated environment in order to facilitate testing.
It allows the user to dump input request data to the [Observation Portal](https://github.com/observatorycontrolsystem/observation-portal)
which is then passed to the scheduler. The orchestrator runs the scheduler and passes off the scheduler result to a
metric calculation file, which calculates metrics to send to an OpenSearch database. Work is still being done to enable the
orchestrator to step through a time range and run the scheduler repeatedly on different points of the input data.

## Overview of Metrics
The available metrics center around priority distributions, utilization, and miscellaneous data including airmass data
and slew distance. Certain metrics sent to OpenSearch are pre-binned by priority level. To get the best understanding of
the data structures, inspect the raw JSON in OpenSearch directly.

## Prerequisites
* Python 3.9
* A running [Configuration Database](https://github.com/observatorycontrolsystem/configdb) with instruments
* A running [Observation Portal](https://github.com/observatorycontrolsystem/observation-portal) with requests
* A running OpenSearch with index created to store scheduler simulation results

## Environment Variables
Consult the adaptive scheduler README for general environment variables related to the scheduler. Additional environment
variables specific to the orchestrator are as follows:
| Variable | Description | Default |
|----------------------------------|---------------------------------------------------------------------------------------------|-------------------------|
| `SIMULATION_RUN_ID` | The run ID of the scheduler. This will be saved as `simulation_id` in OpenSearch | `1` |
| `SIMULATION_START_TIME` | The simulation start time, which allows the orchestrator to step through a time range (WIP) | `2022-06-23` |
| `SIMULATION_END_TIME` | The end time of the time range. This should match the start time if only a single run is desired. | `2022-06-23` |
| `SIMULATION_TIME_STEP_MINUTES` | The time step in minutes for the time range (WIP) | `60` |
| `SIMULATION_AIRMASS_COEFFICIENT` | The airmass optimization weighting value | `0.1` |
| `SIMULATION_OPENSEARCH_INDEX` | The OpenSearch index where metrics will be saved to to | `scheduler-simulations` |
| `OPENSEARCH_URL` | OpenSearch endpoint (needed for the plotting interface) | _`Empty_string`_ |
| | | |

## How to Run
When running in a Docker container, the entry point can be modified to point to the orchestrator instead of the scheduler,
e.g. `sh -c "sleep 20s; simulation-orchestrator"`. The twenty second wait time is to ensure all the relevant services (configdb, redis, etc.) are
spun up and available. Otherwise, run the orchestrator locally on a machine with `poetry run simulation-orchestrator`

## Simulation Process
The general workflow for running a scheduler simulation is as follows:
1. Make changes to the adaptive scheduler. If running with Docker, build the image using the suggested build command in the adaptive scheduler README.
2. If necessary, adjust the `metrics.py` file to conform with the tests you are running, such as adjusting binning for priority values.
3. Modify environment variables accordingly, making sure to set and verify the run ID.
4. Run the orchestrator.

## Plotting
A plotting interface is included with the simulator to facilitate data visualization. The interface features OpenSearch searching by
either OpenSearch ID or `simulation_id`, the ability to save plots in various formats, and zsh-style TAB autocompletion.
Note that the environment variable `OPENSEARCH_URL` must be set on whatever machine you are running the plots from.
To use the plotting interface, run `python -m adaptive_scheduler.simulation.plots`
(`-h` to show the available command line arguments).

## Creating Your Own Plots
The plotting framework provides a `Plot` class defined in `plotutils.py` to help initialize plots and get data from OpenSearch.
`Plot` is initialized with a user-defined plotting function to generate the plot, the plot title, and either a single string or a list
of strings. It searches the `_id` or `simulation_id` field in OpenSearch for the strings and plots the data. To write your own plotting
functions, follow the example functions in `plotfuncs.py`. Plotting functions should take in either a list of datasets
or a single dataset (to match the initialization in `plots.py`). The plot title should be passed into the plotting function as well.
This title is used to generate the descriptions for the command-line interface of the plotting framework.

The plot creation process is as simple as:
1. Creating a function (e.g. `plot_my_plot`) in `plotfuncs.py`
2. Adding the plot to the list of plots in `plots.py`, e.g. `Plot(plotfuncs.plot_my_plot, 'My Plot Title', 'some-data-id')`
Empty file.
Loading