Package: rddl2tf
rddl2tfRDDL2TensorFlow compiler in Python3.Quickstartrddl2tfis a Python 3.5+ package available in PyPI.$ pip3 install rddl2tfUsagerddl2tf can be used as a standalone script or programmatically.Script mode$ rddl2tf --help
usage: rddl2tf [-h] [-b BATCH_SIZE] [--logdir LOGDIR] rddl

rddl2tf (v0.5.1): RDDL2TensorFlow compiler in Python3.

positional arguments:
  rddl                  path to RDDL file or rddlgym problem id

optional arguments:
  -h, --help            show this help message and exit
  -b BATCH_SIZE, --batch-size BATCH_SIZE
                        number of fluents in a batch (default=256)
  --logdir LOGDIR       log directory for tensorboard graph visualization
                        (default=/tmp/rddl2tf)Examples$ rddl2tf Reservoir-8 --batch-size=1024 --logdir=/tmp/rddl2tf
tensorboard --logdir /tmp/rddl2tf/reservoir/inst_reservoir_res8$ rddl2tf Mars_Rover --batch-size=1024 --logdir=/tmp/rddl2tf
tensorboard --logdir /tmp/rddl2tf/simple_mars_rover/inst_simple_mars_rover_pics3Programmatic modeimportrddlgymfromrddl2tf.compilersimportDefaultCompiler# parse RDDL into an ASTmodel_id='Reservoir-8'model=rddlgym.make(model_id,mode=rddlgym.AST)# create a RDDL-to-TF compilercompiler=DefaultCompiler(model,batch_size=256)compiler.init()# compile initial state and default action fluentsstate=compiler.initial_state()action=compiler.default_action()# compile state invariants and action preconditionsinvariants=compiler.state_invariants(state)preconditions=compiler.action_preconditions(state,action)# compile action boundsbounds=compiler.action_bound_constraints(state)# compile intermediate fluents and next state fluentsinterms,next_state=compiler.cpfs(state,action)# compile reward functionreward=compiler.reward(state,action,next_state)# save and visualize the computation graphlogdir=os.path.join(args.logdir,model.domain.name,model.instance.name)file_writer=tf.summary.FileWriter(logdir,compiler.graph)print('tensorboard --logdir{}\n'.format(logdir))CompilerCore API methodsrddl2tf.Compiler.initial_staterddl2tf.Compiler.default_actionrddl2tf.Compiler.cpfsrddl2tf.Compiler.rewardrddl2tf.Compiler.state_action_constraintsrddl2tf.Compiler.action_preconditionsrddl2tf.Compiler.state_invariantsrddl2tf.Compiler.action_bound_constraintsParameterized Variables (pvariables)Each RDDL fluent is compiled to arddl2tf.TensorFluentafter instantiation.Arddl2tf.TensorFluentobject wraps atf.Tensorobject. The arity and the number of objects corresponding to the type of each parameter of a fluent are reflected in arddl2tf.TensorFluentShapeobject (the rank of arddl2tf.TensorFluentcorresponds to the fluent arity and the size of its dimensions corresponds to the number of objects of each type). Also, arddl2tf.TensorFluentShapemanages batch sizes when evaluating operations in batch mode.Additionally, arddl2tf.TensorFluentkeeps information about the ordering of the fluent parameters in arddl2tf.TensorScopeobject.Therddl2tf.TensorFluentabstraction is necessary in the evaluation of RDDL expressions due the broadcasting rules of operations in TensorFlow.Conditional Probability Functions (CPFs)Each CPF expression is compiled into an operation in atf.Graph, possibly composed of many other operations. Typical RDDL operations, functions, and probability distributions are mapped to equivalent TensorFlow ops. These operations are added to atf.Graphby recursively compiling the expressions in a CPF into wrapped operations and functions implemented at therddl2tf.TensorFluentlevel.Note that the RDDL2TensorFlow compiler currently only supports element-wise operations (e.g.a(?x, ?y) = b(?x) * c(?y)is not allowed). However, all compiled operations are vectorized, i.e., computations are done simultaneously for all object instantiations of a pvariable.Optionally, during simulation operations can be evaluated in batch mode. In this case, state-action trajectories are generated in parallel by therddl2tf.Simulator.DocumentationPlease refer tohttps://rddl2tf.readthedocs.io/for the code documentation.SupportIf you are having issues withrddl2tf, please let me know at:thiago.pbueno@gmail.com.LicenseCopyright (c) 2018-2020 Thiago Pereira Bueno All Rights Reserved.rddl2tf is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.rddl2tf is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.You should have received a copy of the GNU Lesser General Public License
along with rddl2tf. If not, seehttp://www.gnu.org/licenses/.