SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2307.07176 · ICLR · 2024

SAFEDREAMER: SAFE REINFORCEMENT LEARNING WITH WORLD MODEL

Yaodong Yang, Jiaming Ji, Weidong Huang, Chunhe Xia, Borong Zhang

arXiv · PDF · Open in the Atlas

Code that ran

8 of 12 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 2 violated it and 0 have no contract verdict; 6 failures of our instrument; 4 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2307.07176.json · badge: /api/ran/2307.07176.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
PKU-Alignment/SafeDreamer canonical (classifier label)
classifier basis: census
8 ran · 4 no recorded run
FunctionStatusWhere it lives
cast_to_compute Ran
ran; our contract draft was wrong, not the code
PKU-Alignment/SafeDreamer/SafeDreamer/jaxutils.py
code served (permissive licence) · get_code("24fe13b4f847da6b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import jax
import jax.numpy as jnp
import numpy as np

tree_map = jax.tree_util.tree_map

COMPUTE_DTYPE = jnp.float32

def cast_to_compute(values):
    return tree_map(lambda x: x.astype(COMPUTE_DTYPE), values)

# Create test data with various nested structures and data types
# The function uses tree_map to apply astype conversion to all leaves

# Single array
single_array = jnp.array([1.0, 2.0, 3.0, 4.0], dtype=jnp.float64)

# Nested structure: dict of arrays
nested_dict = {
    "tensor1": jnp.array([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=jnp.int32),
    "tensor2": jnp.array([1.5, 2.5, 3.5, 4.5], dtype=jnp.float64),
    "nested": {
        "tensor3": jnp.array([[1.0, 2.0], [3.0, 4.0]], dtype=jnp.float64)
    }
}

# List of arrays
list_arrays = [
    jnp.array([1, 2, 3, 4], dtype=jnp.int32),
    jnp.array([1.1, 2.2, 3.3, 4.4], dtype=jnp.float64)
]

# Tuple of arrays
tuple_arrays = (
    jnp.array([1.0, 2.0, 3.0, 4.0], dtype=jnp.float64),
    jnp.array([[5.0, 6.0], [7.0, 8.0]], dtype=jnp.float64)
)

ARGS = {
    "values": nested_dict
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
convert Ran
ran, violated the contract we drafted
PKU-Alignment/SafeDreamer/SafeDreamer/embodied/core/basics.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from hggforget/PIGDreamer, is pointer only (licence: NONE) · get_code("4b830637b16db4c8")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from hggforget/PIGDreamer, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

cost_from_state Ran
ran; our contract draft was wrong, not the code
PKU-Alignment/SafeDreamer/SafeDreamer/behaviors.py
code served (permissive licence) · get_code("1b40546e7c4ffe56")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ArrayImpl, ndim 2, dtype family float, shape (2, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import jax.numpy as jnp
import jax
import torch
import torch.nn as nn

torch.manual_seed(0)

class MockDistribution:
    def __init__(self, value):
        self.value = value
    
    def mode(self):
        return self.value

class MockDecoder(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(8, 50)
    
    def forward(self, state):
        # state is a JAX array, convert to torch, process, convert back
        state_np = jnp.asarray(state)
        # Dummy decoder that outputs observation with shape (batch, time, 50)
        # We'll construct it to have the right shape for the cost function
        batch_size = state_np.shape[0] if len(state_np.shape) > 0 else 1
        time_steps = state_np.shape[1] if len(state_np.shape) > 1 else 1
        
        # Create observation output: (batch_size, time_steps, 50)
        # where indices 9:25 contain hazard positions (16 dims = 8 hazards * 2 coords)
        obs_array = jnp.ones((batch_size, time_steps, 50))
        
        return {'observation': MockDistribution(obs_array)}

class MockWorldModel:
    def __init__(self):
        self.heads = {'decoder': MockDecoder()}

# Create a mock state - JAX array with shape (batch=2, time=3, latent_dim=8)
mock_state = jnp.ones((2, 3, 8))

# Create mock world model with decoder head
mock_wm = MockWorldModel()

ARGS = {
    'wm': mock_wm,
    'state': mock_state
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ArrayImpl, ndim 2, dtype family float, shape (2, 3) — shape (2, 3) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_act Ran
ran; our contract draft was wrong, not the code
PKU-Alignment/SafeDreamer/SafeDreamer/nets.py
code served (permissive licence) · get_code("03dd934385b4d240")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned custom_jvp. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import jax
import jax.numpy as jnp

def get_act(name):
    if callable(name):
        return name
    elif name == 'none':
        return lambda x: x
    elif name == 'mish':
        return lambda x: x * jnp.tanh(jax.nn.softplus(x))
    elif hasattr(jax.nn, name):
        return getattr(jax.nn, name)
    else:
        raise NotImplementedError(name)

# Test with string name 'relu'
ARGS = {
    'name': 'relu'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type custom_jvp — a custom_jvp output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a custom_jvp output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
pure Ran
ran; our contract draft was wrong, not the code
PKU-Alignment/SafeDreamer/SafeDreamer/ninjax.py
code served (permissive licence) · get_code("bbd25fa32893729e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned function. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import jax
import jax.numpy as jnp

# Define a simple impure function that uses the global context
def sample_impure_fn(x, y):
    """A simple impure function that accesses and modifies state."""
    ctx = context()
    
    # Access state
    if 'counter' not in ctx:
        ctx['counter'] = jnp.array(0)
    
    # Modify state
    ctx['counter'] = ctx['counter'] + 1
    
    # Use rng
    key = rng()
    noise = jax.random.normal(key, x.shape)
    
    return x + y + noise

# Create tiny example tensors
x = jnp.ones((2, 3))
y = jnp.ones((2, 3))

# Create initial state dict
initial_state = {
    'weight': jnp.array([1.0, 2.0, 3.0]),
    'bias': jnp.array(0.5)
}

# Create an RNG key
rng_key = jax.random.PRNGKey(42)

# Define ARGS mapping all parameters of pure()
ARGS = {
    'fun': sample_impure_fn,
    'nested': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
subsample Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
PKU-Alignment/SafeDreamer/SafeDreamer/jaxutils.py
code served (permissive licence) · get_code("e5b1910ea05891b1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ArrayImpl, ndim 1, dtype family float, shape (8,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import jax
import jax.numpy as jnp
import numpy as np

# Mock nj module since the function references nj.rng()
class MockNJ:
    @staticmethod
    def rng():
        return jax.random.PRNGKey(0)

nj = MockNJ()

# Create test data
values = jnp.array([[1.0, 2.0, 3.0, 4.0],
                    [5.0, 6.0, 7.0, 8.0]])

ARGS = {
    "values": values,
    "amount": 1024
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ArrayImpl, ndim 1, dtype family float, shape (8,) — shape (8,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
symexp Ran
ran, violated the contract we drafted
PKU-Alignment/SafeDreamer/SafeDreamer/agent.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from alvaro-serra/pompc, is pointer only (licence: NONE) · get_code("d241520c8a517f0a")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from alvaro-serra/pompc, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

tensorstats Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
PKU-Alignment/SafeDreamer/SafeDreamer/jaxutils.py
code served (permissive licence) · get_code("67c6d2355562342f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import jax
import jax.numpy as jnp
import jax.random as jr

# Create a simple RNG key for JAX
key = jr.PRNGKey(0)

# Create a small test tensor (2x4 = 8 elements)
tensor = jnp.array([[1.0, 2.0, 3.0, 4.0],
                     [5.0, 6.0, 7.0, 8.0]])

# Define ARGS with all parameters for tensorstats
ARGS = {
    'tensor': tensor,
    'prefix': 'test'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
format_ Not yet run
unverified (harvested, no recorded run)
PKU-Alignment/SafeDreamer/SafeDreamer/embodied/core/basics.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from hggforget/PIGDreamer, is pointer only (licence: NONE) · get_code("3360b32511bc42d4")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from hggforget/PIGDreamer, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

grad Not yet run
unverified (harvested, no recorded run)
PKU-Alignment/SafeDreamer/SafeDreamer/ninjax.py
code served (permissive licence) · get_code("1ad869363216c281")
How it ran

no invocation recorded.

rng Not yet run
unverified (harvested, no recorded run)
PKU-Alignment/SafeDreamer/SafeDreamer/ninjax.py
code served (permissive licence) · get_code("45b97b51433849a7")
How it ran

no invocation recorded.

treemap Not yet run
unverified (harvested, no recorded run)
PKU-Alignment/SafeDreamer/SafeDreamer/embodied/core/basics.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from hggforget/PIGDreamer, is pointer only (licence: NONE) · get_code("5ba274a4e18b46f3")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from hggforget/PIGDreamer, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 11 are also present in other papers whose code we hold (10 with at least one paper dated earlier, 0 the same month, 11 later) and 1 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_act 9 other papers
3 dated earlier, 6 later
2303.03226 (2023-03)
Safe Reinforcement Learning via Probabilistic Logic Shields
2305.14343 (2023-05)
Video Prediction Models as Rewards for Reinforcement Learning
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
and 6 more not named here
grad 6 other papers
3 dated earlier, 3 later
2303.03226 (2023-03)
Safe Reinforcement Learning via Probabilistic Logic Shields
2305.14343 (2023-05)
Video Prediction Models as Rewards for Reinforcement Learning
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
and 3 more not named here
pure 6 other papers
3 dated earlier, 3 later
2303.03226 (2023-03)
Safe Reinforcement Learning via Probabilistic Logic Shields
2305.14343 (2023-05)
Video Prediction Models as Rewards for Reinforcement Learning
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
and 3 more not named here
rng 6 other papers
3 dated earlier, 3 later
2303.03226 (2023-03)
Safe Reinforcement Learning via Probabilistic Logic Shields
2305.14343 (2023-05)
Video Prediction Models as Rewards for Reinforcement Learning
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
and 3 more not named here
cast_to_compute 5 other papers
3 dated earlier, 2 later
2303.03226 (2023-03)
Safe Reinforcement Learning via Probabilistic Logic Shields
2305.14343 (2023-05)
Video Prediction Models as Rewards for Reinforcement Learning
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
and 2 more not named here
format_ 5 other papers
1 dated earlier, 4 later
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
2310.05167 (2023-10)
Hieros: Hierarchical Imagination on Structured State Space Sequence World Models
2403.04253 (2024-03)
Mastering Memory Tasks with World Models
and 2 more not named here
subsample 5 other papers
2 dated earlier, 3 later
2305.14343 (2023-05)
Video Prediction Models as Rewards for Reinforcement Learning
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
2310.00344 (2023-10)
HarmonyDream: Task Harmonization Inside World Models
and 2 more not named here
tensorstats 5 other papers
2 dated earlier, 3 later
2305.14343 (2023-05)
Video Prediction Models as Rewards for Reinforcement Learning
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
2310.00344 (2023-10)
HarmonyDream: Task Harmonization Inside World Models
and 2 more not named here
treemap 5 other papers
1 dated earlier, 4 later
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
2310.05167 (2023-10)
Hieros: Hierarchical Imagination on Structured State Space Sequence World Models
2403.04253 (2024-03)
Mastering Memory Tasks with World Models
and 2 more not named here
convert 4 other papers
1 dated earlier, 3 later
2306.11488 (2023-06)
Informed POMDP: Leveraging Additional Information in Model-Based RL
2403.04253 (2024-03)
Mastering Memory Tasks with World Models
2403.12309 (2024-03)
Reinforcement Learning from Delayed Observations via World Models
and 1 more not named here
symexp 1 other paper
1 later
2510.04280 (2025-10)
A KL-regularization Framework for Learning to Plan with Adaptive Priors

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

The deployment of Reinforcement Learning (RL) in real-world applications is constrained by its failure to satisfy safety criteria. Existing Safe Reinforcement Learning (SafeRL) methods, which rely on cost functions to enforce safety, often fail to achieve zero-cost performance in complex scenarios, especially vision-only tasks. These limitations are primarily due to model inaccuracies and inadequate sample efficiency. The integration of the world model has proven effective in mitigating these shortcomings. In this work, we introduce SafeDreamer, a novel algorithm incorporating Lagrangian-based methods into world model planning processes within the superior Dreamer framework. Our method achieves nearly zero-cost performance on various tasks, spanning low-dimensional and vision-only input, within the Safety-Gymnasium benchmark, showcasing its efficacy in balancing performance and safety in RL tasks. Further details can be found in the code repository: https://github.com/PKU-Alignment/SafeDreamer. A challenge in the real-world deployment of RL agents is to prevent unsafe situations (Feng et al., 2023; Ji et al., 2023a). SafeRL proposes a practical solution by defining a constrained Markov decision process (CMDP) (Altman, 1999) and integrating an additional cost function to quantify potential hazardous behaviors. In this process, agents aim to maximize rewards while maintaining costs below predefined constraint thresholds. Several remarkable algorithms have been developed on this foundation (

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2307.07176")
get_code_for_paper("2307.07176")
have("2307.07176")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2307.07176.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2307.07176.svg)](https://syntology.ai/paper/2307.07176)

Connect an agent — have() is free.