Skip to content

Commit

Permalink
pre-commit :p
Browse files Browse the repository at this point in the history
  • Loading branch information
joshc-slac committed Oct 18, 2024
1 parent f4535b4 commit 885ddb0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
7 changes: 4 additions & 3 deletions beams/behavior_tree/ActionNode.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import time
import atexit
import logging
import os
import time
from multiprocessing import Event, Queue, Value
from typing import Callable

import py_trees

from beams.typing_helper import Evaluatable, ActionNodeWorkFunction, ActionNodeWorkLoop
from beams.behavior_tree.ActionWorker import ActionWorker
from beams.behavior_tree.VolatileStatus import VolatileStatus
from beams.typing_helper import (ActionNodeWorkFunction, ActionNodeWorkLoop,
Evaluatable)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -37,7 +38,7 @@ def work_wrapper(
logger.debug(f"WAITING FOR INIT from node: {name}")
work_gate.wait()
work_gate.clear()

# Set to running
volatile_status.set_value(py_trees.common.Status.RUNNING)
while not completion_condition():
Expand Down
13 changes: 7 additions & 6 deletions beams/behavior_tree/ActionWorker.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
"""
A worker specialized to execute ActionNode work functions
The primary utility of this "wrapper" class is to maintain the extensibility of the base Worker class.
This is done by using this class to enumerate the "add_args" required by an ActioNode work function
The primary utility of this "wrapper" class is to maintain the extensibility of the base Worker class.
This is done by using this class to enumerate the "add_args" required by an ActioNode work function
not required by work functions in general. The add_args are as follows:
* proc_name: names spawned process *and* generated BT node
* work_gate: IPC signalling mechanism to spawned work that py_trees initialise() has been called by parent
* volatile_status: IPC signalling mechanism that contains multiproccesing safe BT status
* comp_cond: the Evaluatable function that determines success or failure of BT node
* LOGGER_QUEUE: instance of the logging queue
* LOGGER_QUEUE: instance of the logging queue
* worker_logging_configurer: utility functuon to register log queue with handler
"""
from typing import Any, Callable, Optional
from multiprocessing import Event
from typing import Any, Callable, Optional

from epics.multiproc import CAProcess

from beams.behavior_tree.VolatileStatus import VolatileStatus
Expand All @@ -37,9 +38,9 @@ def __init__(
proc_type=CAProcess,
add_args=(proc_name,
work_gate,
volatile_status,
volatile_status,
comp_cond,
LOGGER_QUEUE,
LOGGER_QUEUE,
worker_logging_configurer)
)

Expand Down
4 changes: 2 additions & 2 deletions beams/sequencer/helpers/Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
else:
self.work_func = work_func
# Critical Note: This makes assumptions of the work_func signature in that it takes a Value argument in position 0
self.work_proc = proc_type(target=self.work_func,
self.work_proc = proc_type(target=self.work_func,
name=self.proc_name,
args=(self.do_work, *self.add_args,))
self.stop_func = stop_func
Expand Down Expand Up @@ -58,7 +58,7 @@ def stop_work(self):

logger.debug(f"Ending work, calling join on {self.proc_name}")
self.work_proc.join()
logger.debug(f"Worker process joined from {self.proc_name}" )
logger.debug(f"Worker process joined from {self.proc_name}")

def work_func(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion beams/tests/artifacts/im2l0_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@
]
}
}
}
}
1 change: 1 addition & 0 deletions beams/tests/mock_iocs/IM2L0.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
from enum import Enum
from textwrap import dedent

from caproto.server import PVGroup, ioc_arg_parser, pvproperty, run


Expand Down
2 changes: 1 addition & 1 deletion beams/tests/test_tree_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_stop_hitting_yourself(request):

ct = 0
while (
ct == 0 # simulate a constantly monitoring tree
ct == 0 # simulate a constantly monitoring tree
or
tree.root.status
not in (py_trees.common.Status.SUCCESS, py_trees.common.Status.FAILURE)
Expand Down
4 changes: 2 additions & 2 deletions beams/tree_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from py_trees.common import ComparisonExpression, ParallelPolicy, Status
from py_trees.composites import Parallel, Selector, Sequence

from beams.typing_helper import Evaluatable
from beams.behavior_tree.ActionNode import ActionNode, wrapped_action_work
from beams.behavior_tree.CheckAndDo import CheckAndDo
from beams.behavior_tree.ConditionNode import ConditionNode
from beams.serialization import as_tagged_union
from beams.typing_helper import Evaluatable

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -146,7 +146,7 @@ def get_condition_function(self) -> Evaluatable:
op = getattr(operator, self.operator.value)

def cond_func():
# Note: this bakes EPICS into how Conditions work.
# Note: this bakes EPICS into how Conditions work.
# Further implictly now relies of type of "value" to determine whether to get as_string
val = caget(self.pv, as_string=isinstance(self.value, str))
if val is None:
Expand Down
15 changes: 7 additions & 8 deletions beams/typing_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,39 @@
"""


from multiprocessing import Event, Queue, Value
from typing import Callable
from multiprocessing import Queue, Event, Value

import py_trees

from beams.behavior_tree.VolatileStatus import VolatileStatus


'''
Evaluatable: function handle that returns a boolean , accpeting arbitrary arugments
Evaluatable: function handle that returns a boolean , accpeting arbitrary arugments
'''
Evaluatable = Callable[..., bool]

'''
Defines signature for an ActionNode work loop function handle.
This is neccisated by how beams.behavior_tree.ActionWoker expects to spawn the work process via base class beams.sequencer.helpers.Worker
Parameter Types:
Parameter Types:
Value: volatile indicating work remains to be performed (tree is still ticking, program still running)
str: name of process
Event: work gate reflecting py_trees state of node with respect to tree
VolatileStatus: mechanism to signal from this process to other processes what the py_trees.common.Status of this node is
Evaluatable: this is a completion condition that allows exit of the while loop within the work loop which will wait for a py_trees "initialise"
call to reset the Event (work gate) such that meaningful work can resume on this process
Queue: logging queue
Queue: logging queue
Callable: mechanism to get logger
Return Types:
Return Types:
None
'''
ActionNodeWorkLoop = Callable[[Value, str, Event, VolatileStatus, Evaluatable, Queue, Callable], None]

'''
Work function handle of function to be called during the RUNNING state of an ActionNode
Work function handle of function to be called during the RUNNING state of an ActionNode
Parameter Types:
Evaluatable: determines what py_trees.common.Status to return
Evaluatable: determines what py_trees.common.Status to return
Return Types:
py_trees.common.Status: reflects return type from this node with respect to tree logic
'''
Expand Down

0 comments on commit 885ddb0

Please sign in to comment.