SchedulerCSC#
- class lsst.ts.scheduler.SchedulerCSC(index, config_dir=None, initial_state=State.STANDBY, simulation_mode=0)#
Bases:
ConfigurableCscThis class is a reactive component which is SAL aware and delegates work.
The SchedulerCSC is the only layer that is exposed to SAL communication. All commands recieved are by the SchedulerCSC then delegated to the responsible objects. Along with this the SchedulerCSC maintains a statemachine which is taken care of by the inherited class
base_csc.BaseCsc.- Parameters:
index (
int) –Scheduler SAL component index. This also defines the index of the ScriptQueue the Scheduler will communicate with.
1 for the Main telescope.
2 for AuxTel.
Any allowed value (see
Raises) for unit tests.
- log#
Logging mechanism for the SchedulerCSC.
- Type:
logging.Log
- summary_state#
Enume type, OFFLINE = 4 STANDBY = 5 DISABLED = 1 ENABLED = 2 FAULT = 3.
- Type:
salobj.base_csc.State
- parameters#
Object to contain parameter values to configure the SchedulerCSC.
- Type:
lsst.ts.scheduler.scheduler_csc.SchedulerCscParameters
- configuration_path#
Absolute path to the configuration location for the validSettings event.
- Type:
- configuration_repo#
String of comma delimated Git repos that exist at configuration_path. ex; “origin/master,origin/develop”
- Type:
- valid_settings#
Shortened and listed names of configuration_repo. ex; [master, develop].
- models#
Dictionary of the models necessary for the SchedulerCSC to fulfill SAL commands. -
location: lsst.ts.datelo.ObservatoryLocation -observatory_model: lsst.ts.observatory.model.ObservatoryModel -observatory_state: lsst.ts.observatory.model.ObservatoryState -sky: lsst.ts.astrosky.model.AstronomicalSkyModel -seeing: rubin_scheduler.site_models.SeeingModel -downtime: rubin_scheduler.site_models.DowntimeModel- Type:
- raw_telemetry#
Raw, as in unparsed data that is recieved over SAL. The SchedulerCSC parses self.raw_telemtry and formats the data into self.models.
- Type:
{
str: :object:}
- driver#
A worker class that does much of the lower level computation called by the SchedulerCSC.
- Type:
lsst.ts.scheduler.driver.Driver
Notes
Simulation Modes
Supported simulation modes:
SchedulerModes.NORMAL: Regular operationSchedulerModes.MOCKS3: Semi-operation mode. Normal operation but mocks3 bucket for large file object.
SchedulerModes.SIMULATION: Simulation mode. Do not initialize driverand other operational components.
Error Codes
- 300: Could not connect to the queue. This error code is published
if the Scheduler CSC can not connect to the queue.
301: Failed to put target on the queue.
- 400: Unspecified error on the simple target generation loop. This error
code is published if there is an unspecified error while running the simple target generation loop. For instance, if a user defined scheduling algorithm throws an exception after a call to
Driver.select_next_targetthis error code will, most likely, be issued (along with the traceback message).
401: Unspecified error on advanced target generation loop.
500: Error updating observatory state.
Attributes Summary
Access the remote for the camera.
Check if we need to generate target queue.
Access the remote for the pointing component.
Access the remote for the script queue.
Methods Summary
Advance target production loop.
Assert detailed state is idle.
Assert detailed state is running.
begin_disable(data)Transition from
State.ENABLEDtoState.DISABLED.begin_enable(data)Begin do_enable.
begin_start(data)Begin do_start; configure the CSC before changing state.
Loop through the scheduled targets list, check status and tell driver of completed observations.
check_script_info(data)A callback method to check script info.
Check targets queue condition.
close()Shut down, clean up resources and set done_task done.
compute_predicted_schedule(*args, **kwargs)configure(config)This method is responsible for configuring the scheduler models and the scheduler algorithm, given the input setting.
current_scheduler_state(publish_lfoa[, ...])A context manager to handle storing the current scheduler state, performing some operations on it and then resetting it to the previous state.
detailed_state(detailed_state)Context manager to set the detailed state for an operation then return it to the initial value after it executes.
do_addBlock(data)Implement add block command.
Compute and publish the predicted schedule.
do_flush(data)Implement validate flush command.
do_getBlockStatus(data)Implement get block status command.
do_load(data)Load user-defined schedule definition from URI.
do_removeBlock(data)Implement remove block command.
do_reschedule(data)Implement validate reschedule command.
do_resume(data)Resume target production loop.
do_stop(data)Stop target production loop.
Implement the update observatory status command.
do_validateBlock(data)Implement validate block command.
end_start(data)End do_start; called after state changes but before command acknowledged.
Estimate how long until the next target become available.
Execute an individual block when the Scheduler is not running.
fault(code, report[, traceback])Override default fault state method.
generate_status_note([user_note, system_note])Construct a descriptive string summarizing the current system health.
generate_target_queue(*args, **kwargs)Get the name of the configuration package, e.g. "ts_config_ocs".
Get observing scripts configuration validator.
get_queue([request])Utility method to get the queue.
Handle condition when there are no more targets on the queue.
Handle observatory state.
Handle summary state.
Context manager to handle transitioning from idle to running then back to idle.
Monitor and set the observatory status.
put_on_queue(targets)Given a list of targets, append them on the queue to be observed.
queue_targets(*args, **kwargs)register_observation(target)Register observation.
remove_from_queue(targets)Given a list of targets, remove them from the queue.
Reset conditions that no targets on queue were handled.
save_scheduler_state(publish_lfoa)Save scheduler state to S3 bucket and publish event.
set_observatory_status(status, note)Set observatory status.
Transition the observatory status to a FAULT state.
This coroutine implements the simple target production loop.
start()Override the start method to publish some additional events at startup time.
Stop target production loop execution.
Scheduler telemetry loop.
Attempt to clear the observatory FAULT status.
Remove the OPERATIONAL flag from the observatory status.
validate_observatory_status(status)Given an input status, check if it is a valid new status.
Validate observing blocks.
Attributes Documentation
- camera#
Access the remote for the camera.
- need_to_generate_target_queue#
Check if we need to generate target queue.
The condition in which we have to generate a target queue is when the
targets_queue_conditionfuture is done and its result isNone. If the future is not done, the task that checks the queue is still ongoing. If the results is different thanNoneit means the queue is ok and it does not need to be generated.Note that this is also the initial condition, so the target list is generated the first time the loop runs.
- ptg#
Access the remote for the pointing component.
- queue_remote#
Access the remote for the script queue.
- valid_simulation_modes: Sequence[int] = (0, 1, 2)#
- version = '?'#
Methods Documentation
- async advance_target_production_loop()#
Advance target production loop.
This method will schedule targets ahead of time and send them to the ScriptQueue according to the configuration parameters. This initial implementation is simply blindly scheduling targets ahead of time and not checking for post conditions. Further improvements will involve dealing with different post conditions, generating the predicted queue and further verifying that the schedule is keeping up.
- assert_idle()#
Assert detailed state is idle.
- assert_running()#
Assert detailed state is running.
- async begin_disable(data)#
Transition from
State.ENABLEDtoState.DISABLED. This transition will be made in a gentle way, meaning that it will wait for the target production loop to finalize before making the transition. If a more drastic approach is need, the scheduler must be sent toState.FAULTwith anabortcommand.- Parameters:
data (
DataType) – Command data
- async begin_enable(data)#
Begin do_enable.
Called before state transition from
State.DISABLEDtoState.ENABLED. This method will start the selected target production loop (SIMPLE, ADVANCED or DRY) or raise an exception if the mode is unrecognized.- Parameters:
data (
DataType) – Command data
- async begin_start(data)#
Begin do_start; configure the CSC before changing state.
- Parameters:
data (
cmd_start.DataType) – Command data
Notes
The
overridefield must be one of:The name of a config label or config file
The name and version of a config file, formatted as
<file_name>:<version>, where the version is a git reference, such as a git tag or commit hash. This form does not support labels.
- async check_scheduled_targets()#
Loop through the scheduled targets list, check status and tell driver of completed observations.
- async check_script_info(data)#
A callback method to check script info.
This method will first update the model with the incoming script info then check the scheduled targets. This should allow the Scheduler to cleanup remaining scripts from the ScriptQueue when one Script of a block fails.
- Parameters:
data (
BaseDdsDataType) – Script info topic data.- Return type:
- async check_targets_queue_condition()#
Check targets queue condition.
For now the check is only verifying if more targets need to be added to the internal queue. In the future this method will be responsible for verifying that the predicted schedule is still fine and requesting a re-scheduling if needed.
- async close()#
Shut down, clean up resources and set done_task done.
May be called multiple times. The first call closes the Controller; subsequent calls wait until the Controller is closed.
Subclasses should override
close_tasksinstead ofclose, unless you have a good reason to do otherwise.- Parameters:
exception (
Exception, optional) – The exception that caused stopping, if any, in which case theself.done_taskexception is set to this value. SpecifyNonefor a normal exit, in which case theself.done_taskresult is set toNone.cancel_start (
bool, optional) – Cancel the start task? Leave this true unless calling this from the start task.
Notes
Removes the SAL log handler, calls
close_tasksto stop all background tasks, pauses briefly to allow final SAL messages to be sent, then closes the domain.
- async compute_predicted_schedule(*args, **kwargs)#
- async configure(config)#
This method is responsible for configuring the scheduler models and the scheduler algorithm, given the input setting. It will raise an exception if the input setting is not valid.
- Parameters:
config (
types.SimpleNamespace) – Configuration, as described byschema/Scheduler.yaml- Return type:
None
- current_scheduler_state(publish_lfoa, reset_state=True, keep_state=True)#
A context manager to handle storing the current scheduler state, performing some operations on it and then resetting it to the previous state.
- detailed_state(detailed_state)#
Context manager to set the detailed state for an operation then return it to the initial value after it executes.
This method will acquire a lock to prevent executing a detailed state operation inside another.
- Parameters:
detailed_state (
DetailedState) – Detailed state value.
- async do_addBlock(data)#
Implement add block command.
- Parameters:
data (
DataType) – Command data.- Raises:
NotImplementedError – Command not implemented yet.
- async do_computePredictedSchedule(data)#
Compute and publish the predicted schedule.
This command can only be executed if the Scheduler is idle. It is currently running, the command will be rejected.
- Parameters:
data (
DataType) – Command data.
- async do_flush(data)#
Implement validate flush command.
- Parameters:
data (
DataType) – Command data.- Raises:
NotImplementedError – Command not implemented yet.
- async do_getBlockStatus(data)#
Implement get block status command.
- Parameters:
data (
DataType) – Command data.- Raises:
NotImplementedError – Command not implemented yet.
- async do_load(data)#
Load user-defined schedule definition from URI.
The file is passed on to the driver to load. It must be compatible with the currently configured scheduling algorithm or the load will fail, and the command will be rejected.
- Parameters:
data (
DataType) – Command data
- async do_removeBlock(data)#
Implement remove block command.
- Parameters:
data (
DataType) – Command data.- Raises:
NotImplementedError – Command not implemented yet.
- async do_reschedule(data)#
Implement validate reschedule command.
- Parameters:
data (
DataType) – Command data.- Raises:
NotImplementedError – Command not implemented yet.
- async do_resume(data)#
Resume target production loop.
- Parameters:
data (
DataType) – Command data- Raises:
RuntimeError – If target production loop is already running.
- async do_stop(data)#
Stop target production loop.
- Parameters:
data (
DataType) – Command data
- async do_updateObservatoryStatus(data)#
Implement the update observatory status command.
- Parameters:
data (
DataType) – Command data.- Raises:
NotImplementedError – Command not implemented yet.
- async do_validateBlock(data)#
Implement validate block command.
- Parameters:
data (
DataType) – Command data.- Raises:
NotImplementedError – Command not implemented yet.
- async end_start(data)#
End do_start; called after state changes but before command acknowledged.
- Parameters:
data (
DataType) – Command data
- async estimate_next_target()#
Estimate how long until the next target become available.
- async execute_block()#
Execute an individual block when the Scheduler is not running.
This method will transition the Scheduler from idle to running, queue a single target and go back to idle.
- async fault(code, report, traceback='')#
Override default fault state method.
Before transitioning to FAULT, try to cleanup the queue.
- Parameters:
code (
int) – Error code for theerrorCodeevent. IfNonethenerrorCodeis not output and you should output it yourself. SpecifyingNoneis deprecated; please always specify an integer error code.report (
str) – Description of the error.traceback (
str, optional) – Description of the traceback, if any.
- Return type:
- generate_status_note(user_note=None, system_note=None)#
Construct a descriptive string summarizing the current system health.
This method aggregates an optional user-provided message with an automatically generated list of all components currently reporting a FAULT state.
- Parameters:
- Returns:
note – A combined string containing the user note (if provided) and the list of components in a FAULT state.
- Return type:
Notes
The method iterates through
self._components_summary_stateto identify components where the state matchessalobj.State.FAULT. The resulting string uses the formal representation (r) of thesalobj.Stateenumeration for clarity.User notes are stored and persisted over if not updated, whereas system notes are cleared if not provided.
- async generate_target_queue(*args, **kwargs)#
- static get_config_pkg()#
Get the name of the configuration package, e.g. “ts_config_ocs”.
- async get_observing_scripts_config_validator()#
Get observing scripts configuration validator.
- Returns:
observing_scripts_config_validator – Dictionary with the script name and a boolean indicating if the script is standard or external as key and a configuration validator as value.
- Return type:
ValidationRules
- async get_queue(request=True)#
Utility method to get the queue.
- Parameters:
request (
bool) – Issue request for queue state?- Returns:
queue – SAL Topic with information about the queue.
- Return type:
ScriptQueue_logevent_queueC
- async handle_no_targets_on_queue()#
Handle condition when there are no more targets on the queue.
- async handle_observatory_state()#
Handle observatory state.
- async handle_observatory_status_daytime()#
- async handle_observatory_status_nighttime()#
- async handle_summary_state()#
Handle summary state.
If the component is DISABLED or ENABLED, it will make sure the telemetry loop is running. Shutdown the telemetry loop if in STANDBY.
- idle_to_running()#
Context manager to handle transitioning from idle to running then back to idle.
- async lock_target_loop_and_check_targets()#
- async monitor_observatory_status()#
Monitor and set the observatory status.
- async put_on_queue(targets)#
Given a list of targets, append them on the queue to be observed. Each target sal_index attribute is updated with the unique identifier value (salIndex) returned by the queue.
- async queue_targets(*args, **kwargs)#
- async register_observation(target)#
Register observation.
- Parameters:
observation (Observation) – Observation to be registered.
target (
DriverTarget)
- Return type:
- async remove_from_queue(targets)#
Given a list of targets, remove them from the queue.
- async reset_handle_no_targets_on_queue()#
Reset conditions that no targets on queue were handled.
- async save_scheduler_state(publish_lfoa)#
Save scheduler state to S3 bucket and publish event.
- async set_observatory_status(status, note)#
Set observatory status.
- async set_observatory_status_fault()#
Transition the observatory status to a FAULT state.
This method modifies the current observatory status by removing the OPERATIONAL flag (if present) and ensuring the FAULT flag is set. It then publishes the updated status and a generated status note.
See also
generate_status_noteGenerates the descriptive text for the status update.
set_observatory_statusThe underlying method that publishes the status change.
unset_observatory_status_faultThe inverse operation to clear fault states.
Notes
The status management uses bitwise flags from
SchedulerObservatoryStatus:Bitwise XOR (`^`): Used to flip the
OPERATIONALbit to 0 if it was previously 1.Bitwise OR (`|`): Used to set the
FAULTbit to 1.Bitwise AND (`&`): Used to check the current state of specific flags before applying changes.
- async simple_target_production_loop()#
This coroutine implements the simple target production loop. It will query the status of the queue and, if there is nothing running, it will add an observation to the back of the queue. Once Scheduler is enabled with simple mode, this coroutine will be added to the event loop as a future. While running it will checking the queue and put targets to it. If the queue is paused or there is a running script, it will not add any target to it. If the Scheduler is disabled this method will be cancelled.
Also, note that the target production loop does not care about if it is day or night. It is up to the scheduling algorithm to decide whether there is something to observe or not given the input telemetry. A target produced by the scheduler can have a start time. In this case, the task will be sent to the queue and it is up to the queue or the running script to wait for the specified time. If the scheduling algorithm does not produce any target, then the Scheduler will keep updating telemetry and requesting targets until something is returned to be executed.
NOTE: This method may either run in the main event loop or in an event loop of a thread. If it is the first case, we need to make sure long running tasks are sent to a thread or a process. If the latter, then it should be ok to simple execute long running tasks and block the thread event loop.
- async start()#
Override the start method to publish some additional events at startup time.
- async stop_next_target_timer_task()#
- async telemetry_loop()#
Scheduler telemetry loop.
This method will monitor and process the observatory state and publish the information to SAL.
- async unset_observatory_status_fault()#
Attempt to clear the observatory FAULT status.
This method evaluates if the observatory-level FAULT flag can be safely removed. It checks the internal state of all components; if any single component remains in a FAULT state, the global FAULT status is preserved. Otherwise, the FAULT flag is cleared.
See also
set_observatory_status_faultThe inverse operation to set the fault state.
_monitor_component_stateUpdates the component states evaluated here.
Notes
The clearing logic follows a specific hierarchy:
If the FAULT bit is already 0, no change is made.
A list comprehension scans
self._components_summary_state. If any component has a state equal tosalobj.State.FAULT, the clearing process is aborted to ensure safety.If no components are in FAULT, the bitwise XOR (
^) operator is used to flip theFAULTbit to 0.
- async unset_observatory_status_operational()#
Remove the OPERATIONAL flag from the observatory status.
This method is a no-op if OPERATIONAL is not enabled.
- validate_observatory_status(status)#
Given an input status, check if it is a valid new status.
- Parameters:
status (
int) – Status to validate.- Raises:
InvalidStatusError – If input status is invalid.
UpdateStatusError – If applying the input status cannot be applied. For example if input status clears the fault flags but there are systems still in fault and, as such, flag cannot be cleared.