Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize ray in scos-sensor #112

Merged
merged 18 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 scos_actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "8.0.0"
__version__ = "8.0.1"
10 changes: 7 additions & 3 deletions scos_actions/actions/acquire_sea_data_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@
env = Env()
logger = logging.getLogger(__name__)

if not ray.is_initialized():
# Dashboard is only enabled if ray[default] is installed
ray.init()

# Define parameter keys
RF_PATH = "rf_path"
Expand Down Expand Up @@ -507,6 +504,13 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int):
"""This is the entrypoint function called by the scheduler."""
self._sensor = sensor
action_start_tic = perf_counter()
# Ray should have already been initialized within scos-sensor,
# but check and initialize just in case.
if not ray.is_initialized():
logger.info("Initializing ray.")
logger.info("Set RAY_INIT=true to avoid initializing within " + __name__)
# Dashboard is only enabled if ray[default] is installed
ray.init()

_ = psutil.cpu_percent(interval=None) # Initialize CPU usage monitor
self.test_required_components()
Expand Down
1 change: 1 addition & 0 deletions scos_actions/actions/acquire_single_freq_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import logging

from numpy import float32, ndarray

from scos_actions.actions.interfaces.measurement_action import MeasurementAction
from scos_actions.hardware.mocks.mock_gps import MockGPS
from scos_actions.metadata.structs import ntia_algorithm
Expand Down
4 changes: 2 additions & 2 deletions scos_actions/actions/acquire_single_freq_tdomain_iq.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
import logging

from numpy import complex64

from scos_actions import utils
from scos_actions.actions.interfaces.measurement_action import MeasurementAction
from scos_actions.hardware.mocks.mock_gps import MockGPS
from scos_actions.utils import get_parameter

from scos_actions import utils

logger = logging.getLogger(__name__)

# Define parameter keys
Expand Down
4 changes: 2 additions & 2 deletions scos_actions/actions/acquire_stepped_freq_tdomain_iq.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import logging

import numpy as np

from scos_actions import utils
from scos_actions.actions.acquire_single_freq_tdomain_iq import (
CAL_ADJUST,
DURATION_MS,
Expand All @@ -51,8 +53,6 @@
from scos_actions.signals import measurement_action_completed
from scos_actions.utils import get_parameter

from scos_actions import utils

logger = logging.getLogger(__name__)


Expand Down
4 changes: 2 additions & 2 deletions scos_actions/actions/calibrate_y_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import numpy as np
from scipy.constants import Boltzmann
from scipy.signal import sosfilt

from scos_actions import utils
from scos_actions.actions.interfaces.action import Action
from scos_actions.hardware.sensor import Sensor
from scos_actions.hardware.sigan_iface import SIGAN_SETTINGS_KEYS
Expand All @@ -92,8 +94,6 @@
from scos_actions.signals import trigger_api_restart
from scos_actions.utils import ParameterException, get_parameter

from scos_actions import utils

logger = logging.getLogger(__name__)

# Define parameter keys
Expand Down
1 change: 1 addition & 0 deletions scos_actions/actions/interfaces/measurement_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Optional

import numpy as np

from scos_actions.actions.interfaces.action import Action
from scos_actions.hardware.sensor import Sensor
from scos_actions.metadata.structs import ntia_sensor
Expand Down
28 changes: 28 additions & 0 deletions scos_actions/actions/runtime_error_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""A simple example action that raises a RuntimeError."""

import logging
from typing import Optional

from scos_actions.actions.interfaces.action import Action
from scos_actions.hardware.sensor import Sensor

logger = logging.getLogger(__name__)


class RuntimeErrorAction(Action):
"""
Raise a runtime error.
This is useful for testing and debugging. Note: this action
is currently not loaded in any scenario and must be manually
added to use.

"""

def __init__(self):
super().__init__(parameters={"name": "RuntimeErrorAction"})

def __call__(self, sensor: Optional[Sensor], schedule_entry: dict, task_id: int):
msg = "Raising RuntimeError {name}/{tid}"
schedule_entry_name = schedule_entry["name"]
logger.log(msg=msg.format(name=schedule_entry_name, tid=task_id))
raise RuntimeError("RuntimeError from RuntimeErrorAction")
28 changes: 28 additions & 0 deletions scos_actions/actions/system_exit_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""A simple action that raises SystemExit"""

import logging
from typing import Optional

from scos_actions.actions.interfaces.action import Action
from scos_actions.hardware.sensor import Sensor

logger = logging.getLogger(__name__)


class SystemExitAction(Action):
"""
Raise a SystemExit.
This is useful for testing and debugging. Note: this action
is currently not loaded in any scenario and must be manually
added to use.

"""

def __init__(self):
super().__init__(parameters={"name": "SystemExitAction"})

def __call__(self, sensor: Optional[Sensor], schedule_entry: dict, task_id: int):
msg = "Raising SystemExit {name}/{tid}"
schedule_entry_name = schedule_entry["name"]
logger.log(msg=msg.format(name=schedule_entry_name, tid=task_id))
raise SystemExit("SystemExit produced by SystemExitAction. ")
4 changes: 3 additions & 1 deletion scos_actions/discover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from scos_actions.discover.yaml import load_from_yaml
from scos_actions.settings import ACTION_DEFINITIONS_DIR

actions = {"logger": Logger()}
actions = {
"logger": Logger(),
}
test_actions = {
"test_sync_gps": SyncGps(parameters={"name": "test_sync_gps"}),
"test_monitor_sigan": MonitorSignalAnalyzer(
Expand Down
1 change: 1 addition & 0 deletions scos_actions/hardware/sigan_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Dict, Optional

from its_preselector.web_relay import WebRelay

from scos_actions.calibration.calibration import Calibration
from scos_actions.hardware.utils import power_cycle_sigan
from scos_actions.utils import convert_string_to_millisecond_iso_format
Expand Down
1 change: 1 addition & 0 deletions scos_actions/signal_processing/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
from its_preselector.preselector import Preselector
from scipy.constants import Boltzmann

from scos_actions.signal_processing.unit_conversion import (
convert_celsius_to_fahrenheit,
convert_celsius_to_kelvins,
Expand Down
Loading