| name | add-passive-algorithm |
| description | Add a new passive learning algorithm to AMLGym. Use when the user wants to integrate an algorithm that learns from pre-collected trajectory files. |
Add a Passive Algorithm
Create a new passive algorithm adapter in amlgym/algorithms/.
Steps
-
Create amlgym/algorithms/$ARGUMENTS.py (class name must match filename, PascalCase, case-insensitive)
-
Inherit from PassiveAlgorithmAdapter and implement learn():
from dataclasses import dataclass
from typing import List
from amlgym.algorithms.PassiveAlgorithmAdapter import PassiveAlgorithmAdapter
@dataclass
class $ARGUMENTS(PassiveAlgorithmAdapter):
"""Docstring with paper reference and usage example."""
my_param: float = 1.0
def learn(self,
domain_path: str,
trajectory_paths: List[str]) -> str:
...
-
Add external dependencies to requirements.txt if needed
-
No registration needed — amlgym/algorithms/__init__.py auto-discovers all algorithm files
Reference implementation
Study amlgym/algorithms/SAM.py for the canonical passive adapter pattern:
- Preprocessing trajectories into algorithm-specific format
- Invoking the learning algorithm
- Cleaning up temp files
- Returning the learned PDDL model as a string
Trajectory format
Trajectory files use PDDL-like format with alternating (:state ...) and (:action ...) blocks.
See amlgym/benchmarks/trajectories/ for examples.
Testing
from amlgym.algorithms import get_algorithm
from amlgym.benchmarks import get_domain_path, get_trajectories_path
from amlgym.util.util import empty_domain
from amlgym.metrics import syntactic_precision, syntactic_recall
domain = 'blocksworld'
agent = get_algorithm('$ARGUMENTS')
domain_path = get_domain_path(domain)
input_domain = empty_domain(domain_path)
traj_paths = get_trajectories_path(domain)
model = agent.learn(input_domain, traj_paths)
with open('learned.pddl', 'w') as f:
f.write(model)
print("Precision:", syntactic_precision('learned.pddl', domain_path))
print("Recall:", syntactic_recall('learned.pddl', domain_path))