Skip to main content

rddl2tf Build Status Documentation Status License: GPL v3

RDDL2TensorFlow compiler in Python3.

Quickstart

rddl2tf is a Python 3.5+ package available in PyPI.

$ pip3 install rddl2tf

Usage

rddl2tf 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_pics3

Programmatic mode

import rddlgym

from rddl2tf.compilers import DefaultCompiler


# parse RDDL into an AST
model_id = 'Reservoir-8'
model = rddlgym.make(model_id, mode=rddlgym.AST)

# create a RDDL-to-TF compiler
compiler = DefaultCompiler(model, batch_size=256)
compiler.init()

# compile initial state and default action fluents
state = compiler.initial_state()
action = compiler.default_action()

# compile state invariants and action preconditions
invariants = compiler.state_invariants(state)
preconditions = compiler.action_preconditions(state, action)

# compile action bounds
bounds = compiler.action_bound_constraints(state)

# compile intermediate fluents and next state fluents
interms, next_state = compiler.cpfs(state, action)

# compile reward function
reward = compiler.reward(state, action, next_state)

# save and visualize the computation graph
logdir = 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))

Compiler

Core API methods

  • rddl2tf.Compiler.initial_state
  • rddl2tf.Compiler.default_action
  • rddl2tf.Compiler.cpfs
  • rddl2tf.Compiler.reward
  • rddl2tf.Compiler.state_action_constraints
  • rddl2tf.Compiler.action_preconditions
  • rddl2tf.Compiler.state_invariants
  • rddl2tf.Compiler.action_bound_constraints

Parameterized Variables (pvariables)

Each RDDL fluent is compiled to a rddl2tf.TensorFluent after instantiation.

A rddl2tf.TensorFluent object wraps a tf.Tensor object. The arity and the number of objects corresponding to the type of each parameter of a fluent are reflected in a rddl2tf.TensorFluentShape object (the rank of a rddl2tf.TensorFluent corresponds to the fluent arity and the size of its dimensions corresponds to the number of objects of each type). Also, a rddl2tf.TensorFluentShape manages batch sizes when evaluating operations in batch mode.

Additionally, a rddl2tf.TensorFluentkeeps information about the ordering of the fluent parameters in a rddl2tf.TensorScope object.

The rddl2tf.TensorFluent abstraction 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 a tf.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 a tf.Graph by recursively compiling the expressions in a CPF into wrapped operations and functions implemented at the rddl2tf.TensorFluent level.

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 the rddl2tf.Simulator.

Documentation

Please refer to https://rddl2tf.readthedocs.io/ for the code documentation.

Support

If you are having issues with rddl2tf, please let me know at: thiago.pbueno@gmail.com.

License

Copyright (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, see http://www.gnu.org/licenses/.

Metadata

Release files for rddl2tf 0.5.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rddl2tf 0.5.13
File Size Uploaded Provenance
rddl2tf-0.5.13.tar.gz 27.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for rddl2tf 0.5.13
File Interpreter ABI Platform
rddl2tf-0.5.13-py3-none-any.whl Python 3 none any Details

Total release size: 79.5 kB

Release files / rddl2tf-0.5.13.tar.gz

Download URL rddl2tf-0.5.13.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a829c29da2c84ac91a1d9490ca49c3a2cbd08f8b4327a7467cdbc0907f1926cf
BLAKE2b-256 checksum
How to use checksums
618125f740d6d092f580f7bfabd466b0ab1c6b2547de19cb8f609a094467485e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.8

Release files / rddl2tf-0.5.13-py3-none-any.whl

Download URL rddl2tf-0.5.13-py3-none-any.whl
Size 51.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78f8b520a2622664076f8f03feb91ebf62ed91f5f92665cd136170519ca3e34e
BLAKE2b-256 checksum
How to use checksums
36d2a2f9c915ebfd31bfd9fb47df20fff97290dfa79512dfcf1e91f4d93fe0f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.8

Security for rddl2tf 0.5.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.13 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page