Skip to content

Commit

Permalink
OA-Systems: Online Adaptive Systems #612
Browse files Browse the repository at this point in the history
  • Loading branch information
laxmikantbaheti committed May 29, 2023
1 parent ce303f9 commit 627ca30
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 101 deletions.
1 change: 1 addition & 0 deletions src/mlpro/bf/ml/systems/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def __init__(self,
p_visualize = p_visualize,
p_logging = p_logging)

Model.__init__(self, p_ada= p_adaptivity)

self._fct_strans = p_fct_strans
self._fct_broken = p_fct_broken
Expand Down
2 changes: 1 addition & 1 deletion src/mlpro/bf/systems/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ def register_system(self,

## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
class System (Task, FctSTrans, FctSuccess, FctBroken, Mode, Plottable, Persistent, ScientificObject):
class System (FctSTrans, FctSuccess, FctBroken, Task, Mode, Plottable, Persistent, ScientificObject):
"""
Base class for state based systems.
Expand Down
216 changes: 116 additions & 100 deletions src/mlpro/oa/systems/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _run( self,

## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
class OAFctSTrans(AFctSTrans):
class OAFctSTrans(FctSTrans, Model):
"""
Parameters
Expand Down Expand Up @@ -190,28 +190,28 @@ def __init__(self,
p_logging=Log.C_LOG_ALL,
**p_kwargs):

if p_afct_cls is not None:
if (p_state_space is None) or (p_action_space is None):
raise ParamError("Please provide mandatory parameters state and action space.")

AFctSTrans.__init__(self,
p_afct_cls = p_afct_cls,
p_state_space=p_state_space,
p_action_space=p_action_space,
p_input_space_cls=p_input_space_cls,
p_output_space_cls=p_output_space_cls,
p_output_elem_cls=p_output_elem_cls,
p_threshold=p_threshold,
p_buffer_size=p_buffer_size,
p_ada=p_ada,
p_visualize=p_visualize,
p_logging=p_logging,
**p_kwargs)

else:
FctSTrans.__init__(self,
p_logging = p_logging)
# if p_afct_cls is not None:
# if (p_state_space is None) or (p_action_space is None):
# raise ParamError("Please provide mandatory parameters state and action space.")
#
# AFctSTrans.__init__(self,
# p_afct_cls = p_afct_cls,
# p_state_space=p_state_space,
# p_action_space=p_action_space,
# p_input_space_cls=p_input_space_cls,
# p_output_space_cls=p_output_space_cls,
# p_output_elem_cls=p_output_elem_cls,
# p_threshold=p_threshold,
# p_buffer_size=p_buffer_size,
# p_ada=p_ada,
# p_visualize=p_visualize,
# p_logging=p_logging,
# **p_kwargs)
#
# else:
FctSTrans.__init__(self, p_logging = p_logging)

Model.__init__(self)
# OAFctBase.__init__(self)
self._wf = p_wf
# self._strans_task:StreamTask = None
Expand Down Expand Up @@ -381,7 +381,7 @@ def _setup_fct_workflow(self):

## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
class OAFctSuccess(AFctSuccess):
class OAFctSuccess(FctSuccess, Model):
"""
Parameters
Expand Down Expand Up @@ -416,29 +416,28 @@ def __init__(self,
p_logging=Log.C_LOG_ALL,
**p_kwargs):

if p_afct_cls is not None:
if (p_state_space is None) or (p_action_space is None):
raise ParamError("Please provide mandatory parameters state and action space.")

AFctSuccess.__init__(self,
p_afct_cls=p_afct_cls,
p_state_space=p_state_space,
p_action_space=p_action_space,
p_input_space_cls=p_input_space_cls,
p_output_space_cls=p_output_space_cls,
p_output_elem_cls=p_output_elem_cls,
p_threshold=p_threshold,
p_buffer_size=p_buffer_size,
p_ada=p_ada,
p_visualize=p_visualize,
p_logging=p_logging,
**p_kwargs)

else:
FctSuccess.__init__(self,
p_logging=p_logging)

# if p_afct_cls is not None:
# if (p_state_space is None) or (p_action_space is None):
# raise ParamError("Please provide mandatory parameters state and action space.")
#
# AFctSuccess.__init__(self,
# p_afct_cls=p_afct_cls,
# p_state_space=p_state_space,
# p_action_space=p_action_space,
# p_input_space_cls=p_input_space_cls,
# p_output_space_cls=p_output_space_cls,
# p_output_elem_cls=p_output_elem_cls,
# p_threshold=p_threshold,
# p_buffer_size=p_buffer_size,
# p_ada=p_ada,
# p_visualize=p_visualize,
# p_logging=p_logging,
# **p_kwargs)
#
# else:
FctSuccess.__init__(self, p_logging=p_logging)

Model.__init__(self)
self._wf_success = p_wf_success
# self._shared = p_class_shared
self._success_task = None
Expand Down Expand Up @@ -600,7 +599,7 @@ def _setup_fct_workflow(self):

## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
class OAFCtBroken(AFctBroken):
class OAFctBroken(FctBroken, Model):
"""
Parameters
Expand All @@ -614,7 +613,7 @@ class OAFCtBroken(AFctBroken):
"""


## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
def __init__(self,
p_afct_cls = None,
p_state_space: MSpace = None,
Expand All @@ -635,29 +634,28 @@ def __init__(self,
p_logging=Log.C_LOG_ALL,
**p_kwargs):

if p_afct_cls is not None:
if (p_state_space is None) or (p_action_space is None):
raise ParamError("Please provide mandatory parameters state and action space.")

AFctSuccess.__init__(self,
p_afct_cls=p_afct_cls,
p_state_space=p_state_space,
p_action_space=p_action_space,
p_input_space_cls=p_input_space_cls,
p_output_space_cls=p_output_space_cls,
p_output_elem_cls=p_output_elem_cls,
p_threshold=p_threshold,
p_buffer_size=p_buffer_size,
p_ada=p_ada,
p_visualize=p_visualize,
p_logging=p_logging,
**p_kwargs)

else:
FctBroken.__init__(self,
p_logging=p_logging)

# if p_afct_cls is not None:
# if (p_state_space is None) or (p_action_space is None):
# raise ParamError("Please provide mandatory parameters state and action space.")
#
# AFctSuccess.__init__(self,
# p_afct_cls=p_afct_cls,
# p_state_space=p_state_space,
# p_action_space=p_action_space,
# p_input_space_cls=p_input_space_cls,
# p_output_space_cls=p_output_space_cls,
# p_output_elem_cls=p_output_elem_cls,
# p_threshold=p_threshold,
# p_buffer_size=p_buffer_size,
# p_ada=p_ada,
# p_visualize=p_visualize,
# p_logging=p_logging,
# **p_kwargs)
#
# else:
FctBroken.__init__(self, p_logging=p_logging)

Model.__init__(self)
# self._broken_task:StreamTask = None
self._wf_broken = p_wf_broken
# self._shared = p_class_shared
Expand Down Expand Up @@ -821,7 +819,7 @@ def _setup_fct_workflow(self):

## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
class OASystem(ASystem, OAFctSTrans, OAFctSuccess, OAFCtBroken):
class OASystem(OAFctBroken, OAFctSTrans, OAFctSuccess, ASystem):
"""
Parameters
Expand All @@ -837,33 +835,33 @@ class OASystem(ASystem, OAFctSTrans, OAFctSuccess, OAFCtBroken):
"""


## -------------------------------------------------------------------------------------------------
## -------------------------------------------------------------------------------------------------
def __init__(self,
p_mode = Mode.C_MODE_SIM,
p_latency = None,
p_fct_strans : FctSTrans = None,
p_fct_success : FctSuccess = None,
p_fct_broken : FctBroken = None,
p_wf : OAWorkflow = None,
p_wf_success : OAWorkflow = None,
p_wf_broken : OAWorkflow = None,
p_visualize : bool = False,
p_logging = Log.C_LOG_ALL):
p_mode = Mode.C_MODE_SIM,
p_latency = None,
p_fct_strans : FctSTrans = None,
p_fct_success : FctSuccess = None,
p_fct_broken : FctBroken = None,
p_wf : OAWorkflow = None,
p_wf_success : OAWorkflow = None,
p_wf_broken : OAWorkflow = None,
p_visualize : bool = False,
p_logging = Log.C_LOG_ALL):

ASystem.__init__(self,
p_mode = p_mode,
p_latency = p_latency,
p_fct_strans = p_fct_strans,
p_fct_success = p_fct_success,
p_fct_broken = p_fct_broken,
p_visualize = p_visualize,
p_logging = p_logging)
p_mode = p_mode,
p_latency = p_latency,
p_fct_strans = p_fct_strans,
p_fct_success = p_fct_success,
p_fct_broken = p_fct_broken,
p_visualize = p_visualize,
p_logging = p_logging)

OAFctSTrans.__init__(self, p_wf=p_wf)

OAFctSuccess.__init__(self, p_wf=p_wf_success)

OAFCtBroken.__init__(self, p_wf_broken=p_wf_broken)
OAFctBroken.__init__(self, p_wf_broken=p_wf_broken)



Expand Down Expand Up @@ -901,7 +899,35 @@ def _adapt(self, **p_kwargs) -> bool:
-------
"""
pass
adapted = False

try:
adapted = self._wf.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._wf_success.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._wf_broken.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._fct_strans.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._fct_success.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._fct_broken.adapt(**p_kwargs)
except:
adapted = adapted or False

return adapted



## -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -934,13 +960,3 @@ def _adapt_on_event(self, p_event_id:str, p_event_object:Event) -> bool:
"""
pass


## -------------------------------------------------------------------------------------------------
def _run_processing_wf(self):
"""
Returns
-------
"""
pass

0 comments on commit 627ca30

Please sign in to comment.