Skip to content

Commit

Permalink
Merge pull request #8 from simonsobs/multi-platform
Browse files Browse the repository at this point in the history
add sat policy and support config preset
  • Loading branch information
guanyilun authored Nov 6, 2023
2 parents 11856de + 122b672 commit fac2529
Show file tree
Hide file tree
Showing 8 changed files with 1,560 additions and 8,844 deletions.
38 changes: 12 additions & 26 deletions src/scheduler_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@
import traceback

from . import handler, utils
from .configs import get_default_config
from .configs import get_config

import logging
logging.basicConfig(level=logging.DEBUG)

SUPPORTED_POLICIES = ['dummy', 'basic']
POLICY_HANDLERS = {
'dummy': handler.dummy_policy,
'basic': handler.basic_policy
}

app = flask.Flask(__name__)

# Allow CORS for all domains.
Expand Down Expand Up @@ -62,7 +56,7 @@ def schedule():
return response

# policy is a json string, so parse it now. The json
# has the form {"policy": "name", "config": {...}}
# has the form {"policy": "name", "preset": "config_preset_name", "config": {...}, }
try:
policy_dict = json.loads(policy)
except json.JSONDecodeError:
Expand All @@ -75,27 +69,25 @@ def schedule():

policy_name = policy_dict.get('policy', 'dummy')
user_policy_config = policy_dict.get('config', {})
# unless specified, use policy_name to find default config for policy
config_preset_name = policy_dict.get('preset', policy_name)

# check policy is supported
if policy_name not in SUPPORTED_POLICIES:
if policy_name not in handler.HANDLERS:
response = flask.jsonify({
'status': 'error',
'message': f'Invalid policy. Supported policies are: {SUPPORTED_POLICIES}'
'message': f'Invalid policy {policy_name}'
})
response.status_code = 400
return response

try:
# load policy config: first check if a custom policy config has been provided
# it will be inside app.config['policy_configs'][policy_name]
if 'policy_configs' in app.config and policy_name in app.config['policy_configs']:
policy_config = app.config['policy_configs'][policy_name]
else:
policy_config = get_default_config(policy_name)
# load policy config preset and merge with user config
policy_config = get_config(config_preset_name)
utils.nested_update(policy_config, user_policy_config, new_keys_allowed=True)

# merge user config with default config
utils.nested_update(policy_config, user_policy_config, new_keys_allowed=False)
commands = POLICY_HANDLERS[policy_name](t0, t1, policy_config, app.config)
# get scheduler commands
commands = handler.get_handler(policy_name)(t0, t1, policy_config)
except Exception as e:
response = flask.jsonify({
'status': 'error',
Expand All @@ -111,10 +103,4 @@ def schedule():
'message': 'Success'
})
response.status_code = 200
return response

# load config
config_file = os.environ.get('SCHEDULER_CONFIG')
if config_file is not None and os.path.exists(config_file):
config = utils.load_config(config_file)
app.config.update(config)
return response
10 changes: 7 additions & 3 deletions src/scheduler_server/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from .basic import config as basic_config
from .flex import config as flex_config
from .sat import config_satp1

CONFIGS = {
'basic': basic_config,
'flex': flex_config
'flex': flex_config,
'satp1': config_satp1,
}
def get_default_config(name):
return CONFIGS.get(name, {})
def get_config(preset):
if preset not in CONFIGS:
raise ValueError(f'Unknown config preset {preset}')
return CONFIGS[preset]
2 changes: 1 addition & 1 deletion src/scheduler_server/configs/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
hour = 60 * minute

config = {
'master_schedule': op.dirname(__file__) + '/schedule_sat.txt',
'master_schedule': op.join(op.dirname(__file__),'data/satp1_baseline_20231031.txt'),
'rules': {
'sun-avoidance': {
'min_angle_az': 6, # deg
Expand Down
1,385 changes: 1,385 additions & 0 deletions src/scheduler_server/configs/data/satp1_baseline_20231031.txt

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions src/scheduler_server/configs/sat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import os.path as op

geometries_satp1 = {
'full': {
'left': {
'ws6': {
'center': [-10.9624, 6.46363],
'radius': 6,
},
'ws5': {
'center': [-10.9624, -6.46363],
'radius': 6,
},
},
'middle': {
'ws1': {
'center': [0, 12.634],
'radius': 6,
},
'ws0': {
'center': [0, 0],
'radius': 6,
},
'ws4': {
'center': [0, -12.634],
'radius': 6,
},
},
'right': {
'ws2': {
'center': [10.9624, 6.46363],
'radius': 6,
},
'ws3': {
'center': [10.9624, -6.46363],
'radius': 6,
},
},
},
'bottom' : {
'ws4': {
'center': [0, -12.634],
'radius': 6,
},
'ws3': {
'center': [10.9624, -6.46363],
'radius': 6,
},
'ws5': {
'center': [-10.9624, -6.46363],
'radius': 6,
},
}
}

blocks = {
'calibration': {
'saturn': {
'type' : 'source',
'name' : 'saturn',
},
'moon': {
'type' : 'source',
'name' : 'moon',
},
},
'baseline': {
'cmb': {
'type': 'toast',
'file': op.join(op.dirname(__file__), 'data/satp1_baseline_20231031.txt'),
}
}
}

config_satp1 = {
'blocks': blocks,
'geometries': geometries_satp1,
'rules': {
'sun-avoidance': {
'min_angle_az': 45,
'min_angle_alt': 45,
},
'min-duration': {
'min_duration': 600
},
'az-range': {
'az_range': [-90, 450],
'trim': True
}
},
'cal_targets': [
# (source, array_query, el_bore, tag)
('saturn', 'left', 50, 'left_focal_plane'),
('saturn', 'mid', 50, 'mid_focal_plane'),
('saturn', 'right', 50, 'right_focal_plane'),
],
'merge_order': ['calibration', 'baseline'],
'time_costs': {
'det_setup': 40*60,
'bias_step': 60,
'ufm_relock': 120,
},
'ufm_relock': True,
}
Loading

0 comments on commit fac2529

Please sign in to comment.