Open In Colab

3. Active Algorithms

AMLGym implements a random baseline for active learning in fully observable and deterministic environments.

[ ]:
!pip install amlgym

Get an input domain with predicate/operator signatures and no preconditions and effects.

[ ]:
from amlgym.benchmarks import get_domain_path
from amlgym.util.util import empty_domain

domain = 'blocksworld'
domain_ref_path = get_domain_path(domain)
input_domain_path = empty_domain(domain_ref_path)

Create a simulator of a fully observable and deterministic environment.

[ ]:
from unified_planning.shortcuts import SequentialSimulator
from unified_planning.io import PDDLReader
from amlgym.benchmarks import get_problems_path

problem_path = get_problems_path(domain, kind='learning')[0]
problem = PDDLReader().parse_problem(domain_ref_path, problem_path)

env = SequentialSimulator(problem=problem)

Instantiate a random agent and learns a model by acting in the simulated environment for a maximum number of 100 steps. At each step, the agent attempts to execute an action and observes the resulting environment state. Notice that action executions can fail.

[ ]:
from amlgym.algorithms import get_algorithm

learner = get_algorithm('RandomAgent', max_steps=40)
model, trajectory = learner.learn(env, input_domain_path)

Print the learned model and produced trajectory.

[ ]:
print("##################### Learned model #####################")
print(model)

print("################# Generated trajectory ##################")
print(trajectory)