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

Add call graph breadth first search to solve graphs actions #9

Merged
merged 17 commits into from
Dec 15, 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 .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ repos:
hooks:
- id: pytest-fast-check
name: pytest-fast-check
entry: ./venv/Scripts/python.exe -m pytest -m "not slow"
stages: ["commit"]
entry: pytest -m "not slow"
stages: ["pre-commit"]
language: system
pass_filenames: false
always_run: true
- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: ./venv/Scripts/python.exe -m pytest
stages: ["push"]
entry: pytest
stages: ["pre-push"]
language: system
pass_filenames: false
always_run: true
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Here is an example to show how could we hierarchicaly build an explanable behavi
def __init__(self, hand) -> None:
super().__init__(name="Is hand near the cat ?")
self.hand = hand
def __call__(self, observation):
def __call__(self, observation) -> int:
# Could be a very complex function that returns 1 is the hand is near the cat else 0.
if observation["cat"] == observation[self.hand]:
return int(True) # 1
Expand Down Expand Up @@ -119,7 +119,7 @@ Here is an example to show how could we hierarchicaly build an explanable behavi
class IsThereACatAround(FeatureCondition):
def __init__(self) -> None:
super().__init__(name="Is there a cat around ?")
def __call__(self, observation):
def __call__(self, observation) -> int:
# Could be a very complex function that returns 1 is there is a cat around else 0.
if "cat" in observation:
return int(True) # 1
Expand Down Expand Up @@ -217,7 +217,7 @@ Will generate the code bellow:
# Require 'Look for a nearby cat' behavior to be given.
# Require 'Move slowly your hand near the cat' behavior to be given.
class PetTheCat(GeneratedBehavior):
def __call__(self, observation):
def __call__(self, observation) -> Any:
edge_index = self.feature_conditions['Is there a cat around ?'](observation)
if edge_index == 0:
return self.known_behaviors['Look for a nearby cat'](observation)
Expand Down
1 change: 1 addition & 0 deletions commands/coverage.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest --cov=src --cov-report=html --cov-report=term
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from setuptools import setup


setup()
2 changes: 1 addition & 1 deletion src/hebg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# HEBGraph for explainable hierarchical reinforcement learning
# Copyright (C) 2021-2022 Mathïs FEDERICO <https://www.gnu.org/licenses/>
# Copyright (C) 2021-2024 Mathïs FEDERICO <https://www.gnu.org/licenses/>

"""A structure for explainable hierarchical reinforcement learning"""

Expand Down
8 changes: 4 additions & 4 deletions src/hebg/behavior.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# HEBGraph for explainable hierarchical reinforcement learning
# Copyright (C) 2021-2022 Mathïs FEDERICO <https://www.gnu.org/licenses/>
# Copyright (C) 2021-2024 Mathïs FEDERICO <https://www.gnu.org/licenses/>

"""Module for base Behavior."""

Expand All @@ -17,11 +17,11 @@
class Behavior(Node):
"""Abstract class for a Behavior as Node"""

def __init__(self, name: str, image=None) -> None:
super().__init__(name, "behavior", image=image)
def __init__(self, name: str, image=None, **kwargs) -> None:
super().__init__(name, "behavior", image=image, **kwargs)
self._graph = None

def __call__(self, observation, *args, **kwargs):
def __call__(self, observation, *args, **kwargs) -> None:
"""Use the behavior to get next actions.

By default, uses the HEBGraph if it can be built.
Expand Down
Loading
Loading