from fastrl.torch_core import *
from fastrl.agents.dqn.basic import *
from fastrl.agents.core import *
from fastrl.agents.discrete import *
from fastrl.data.block import *
from fastrl.envs.gym import *
from fastrl.loggers.vscode_visualizers import *
Learner Core
Core DataPipes for building Learners
LearnerBase
LearnerBase (*args, **kwds)
Combines models,dataloaders, and optimizers together for running a training pipeline.
LearnerHead
LearnerHead (*args, **kwds)
Initialize self. See help(type(self)) for accurate signature.
Warning: Pickling the LearnerBase will exclude the ’_dls’,‘opt’,‘iterable’ fields since these aren’t easily picklable (yet).
# Setup up the core NN
0)
torch.manual_seed(= DQN(4,2)
model # Setup the agent
= AgentBase(model,[])
agent = StepFieldSelector(agent,field='state')
agent # All the things that make this agent unique and special
# In this instance, all this module does is pass the action directly through to the model.
= SimpleModelRunner(agent)
agent = ArgMaxer(agent,only_idx=True)
agent = NumpyConverter(agent)
agent = PyPrimativeConverter(agent)
agent # Bring everything together into the AgentHead where actions will be passed and then run through the pipeline
= AgentHead(agent) agent
# Setup the DataBlock
= DataBlock(
block =agent,nsteps=1,nskips=1,firstlast=False,n=100,bs=1),
GymTransformBlock(agent=agent,nsteps=1,nskips=1,firstlast=False,n=100,bs=1,include_images=True),VSCodeTransformBlock())
(GymTransformBlock(agent
)
= L(block.dataloaders(['CartPole-v1']*1,num_workers=0)) dls
def TestLearner(model,dls):
= LearnerBase(model,dls)
learner = LearnerHead(learner)
learner return learner
= TestLearner(model,dls) learner
StepBatcher
StepBatcher (*args, **kwds)
Converts multiple StepType
into a single StepType
with the fields concated.