SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.01575 · 2024

Contextual Bilevel Reinforcement Learning for Incentive Alignment

arXiv · PDF · Open in the Atlas

Code that ran

8 of 13 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; 2 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 6 failures of our instrument; 5 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/2406.01575.json · badge: /api/ran/2406.01575.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
lasgroup/hpgd canonical (classifier label)
classifier basis: census
8 ran · 5 no recorded run
FunctionStatusWhere it lives
apply_greedy_policy Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
lasgroup/hpgd/train_stochastic_bilevel_opt.py
code served (permissive licence) · get_code("90bf283f158bfaef")
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 tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 distrax
import numpy as np

# Set random seed for reproducibility
np.random.seed(0)
key = jax.random.PRNGKey(0)

# Define tiny dimensions
n_envs = 2  # number of environments
obs_dim = 4  # observation dimension
n_coords = 3  # number of state coordinates
n_actions = 5  # number of actions

# Create train_state_params dict with best_response_policy
# Shape should be (n_coords, n_actions) based on how it's used:
# mask_position.T has shape (n_envs, n_coords)
# best_response_policy should have shape (n_coords, n_actions)
# so dot product gives (n_envs, n_actions)
best_response_policy = np.random.randn(n_coords, n_actions).astype(np.float32)
train_state_params = {
    'best_response_policy': best_response_policy
}

# Create obs tensor
# Shape: (n_envs, obs_dim) where first 2 elements are position coordinates
obs = np.random.randn(n_envs, obs_dim).astype(np.float32)
obs = jnp.array(obs)

# Create state_coords tensor
# Shape: (n_coords, 2) - coordinates in 2D space
state_coords = np.array([
    [0.1, 0.2],
    [0.3, 0.4],
    [0.5, 0.6]
], dtype=np.float32)
state_coords = jnp.array(state_coords)

# Convert train_state_params values to jnp arrays
train_state_params = {
    'best_response_policy': jnp.array(train_state_params['best_response_policy'])
}

ARGS = {
    'train_state_params': train_state_params,
    'obs': obs,
    'state_coords': state_coords
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
distrax, jax, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
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
default_reward_function Ran
ran; our contract draft was wrong, not the code
lasgroup/hpgd/src/environments/utils.py
code served (permissive licence) · get_code("fcab5c91a12d6c1e")
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 (2,) 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.

from flax import struct
from jax import numpy as jnp
import jax

@struct.dataclass
class State:
    pos: jnp.ndarray
    goal: jnp.ndarray

@struct.dataclass
class Params:
    pass

# Create small test tensors with batch_size=2, dim=4
pos = jnp.array([[1.0, 2.0, 3.0, 4.0],
                  [1.0, 2.0, 3.0, 4.0]], dtype=jnp.float32)

goal = jnp.array([[1.0, 2.0, 3.0, 4.0],
                   [5.0, 6.0, 7.0, 8.0]], dtype=jnp.float32)

state = State(pos=pos, goal=goal)

action = jnp.array([[0.1, 0.2, 0.3, 0.4],
                    [0.5, 0.6, 0.7, 0.8]], dtype=jnp.float32)

params = Params()

ARGS = {
    "state": state,
    "action": action,
    "params": params
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, jax — 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 (2,) — shape (2,) 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
incentive_transform Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
lasgroup/hpgd/src/models/IncentiveModel.py
code served (permissive licence) · get_code("e1d1608d2719c09d")
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 (4,) 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.nn

ARGS = {
    'weights': jnp.array([0.5, -0.3, 1.2, -0.8], dtype=jnp.float32),
    'activation_function': 'sigmoid',
    'range': jnp.array([0.0, 1.0], dtype=jnp.float32),
    'temperature': 1.0
}
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 ArrayImpl, ndim 1, dtype family float, shape (4,) — shape (4,) 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
normalize_discounted_rewards Ran
ran, honoured the contract we drafted
lasgroup/hpgd/src/algorithms/utils.py
code served (permissive licence) · get_code("1fa8c23d22d4dd92")
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, 4) 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 numpy as np

# Create a small array of discounted rewards
# Using a 2D array with shape (2, 4) for batch size 2 and 4 reward values
discounted_rewards = jnp.array([
    [1.0, 2.0, 3.0, 4.0],
    [5.0, 6.0, 7.0, 8.0]
], dtype=jnp.float32)

ARGS = {
    "discounted_rewards": discounted_rewards
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
random_normal_perturbations Ran
ran; our contract draft was wrong, not the code
lasgroup/hpgd/train_tax_design_zero_order.py
code served (permissive licence) · get_code("cf39e222b919e4f0")
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

# Create a small stand-in TrainState class that mimics what the function expects
class TrainState:
    def __init__(self, params):
        self.params = params

# Create sample train_states dict with the structure expected by the function
# The function accesses: ts.params['params']['weights']
train_states = {
    'state_1': TrainState(params={
        'params': {
            'weights': jnp.ones((4, 3), dtype=jnp.float32)
        }
    }),
    'state_2': TrainState(params={
        'params': {
            'weights': jnp.ones((5, 2), dtype=jnp.float32)
        }
    })
}

# Create a random key for JAX
rng_key = jax.random.PRNGKey(0)

ARGS = {
    'rng_key': rng_key,
    'train_states': train_states
}
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
random_split_like_tree Ran
ran; our contract draft was wrong, not the code
lasgroup/hpgd/train_zero_order.py
code served (permissive licence) · get_code("8aaaff5f138c1764")
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 nested tree structure with JAX arrays
# The function uses jax.tree_util.tree_structure() and tree_unflatten()
# so we need to pass target and/or treedef

# Example 1: Using target parameter (treedef will be inferred)
target_tree = {
    'a': jnp.zeros((2, 4)),
    'b': jnp.zeros((3, 4)),
    'c': {
        'd': jnp.zeros((4,)),
        'e': jnp.zeros((2, 3))
    }
}

# Create an RNG key
rng_key = jr.PRNGKey(0)

# Define ARGS with all parameters
ARGS = {
    'rng_key': rng_key,
    'target': target_tree,
    'treedef': None
}
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
regularized_softmax Ran
ran, honoured the contract we drafted
lasgroup/hpgd/train_stochastic_bilevel_opt.py
code served (permissive licence) · get_code("5e8fb421a069c1de")
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, 4) 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

# Set seeds for reproducibility
np.random.seed(0)

# Create a small Q-value table: (n_states, n_actions)
# Using distinct dimensions: 2 states, 4 actions
Q = jnp.array([
    [1.0, 2.0, 3.0, 4.0],
    [5.0, 6.0, 7.0, 8.0]
], dtype=jnp.float32)

# Create regularization parameter (scalar)
reg_lambda = jnp.array(1.0, dtype=jnp.float32)

ARGS = {
    "Q": Q,
    "reg_lambda": reg_lambda
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
sample_array Ran
ran; our contract draft was wrong, not the code
lasgroup/hpgd/src/environments/utils.py
code served (permissive licence) · get_code("6a60b610c1b46d4e")
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 tuple. 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 distrax

# Set seed for reproducibility
key = jax.random.PRNGKey(0)

# Create a small array to sample from
array = jnp.arange(4).reshape(4, 1)  # Shape (4, 1) - 4 elements with 1 feature each

# Create logits for categorical distribution over 4 categories
logits = jnp.array([1.0, 2.0, 0.5, 1.5])  # Shape (4,) - logits for 4 categories

ARGS = {
    "key": key,
    "array": array,
    "logits": logits,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
distrax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
clip_norm Not yet run
unverified (harvested, no recorded run)
lasgroup/hpgd/train_stochastic_bilevel_opt.py
code served (permissive licence) · get_code("75b917a4731eaf8a")
How it ran

no invocation recorded.

get_actions_from_q_values Not yet run
unverified (harvested, no recorded run)
lasgroup/hpgd/src/algorithms/Regularized_DQN.py
code served (permissive licence) · get_code("d811aaa5f794375d")
How it ran

no invocation recorded.

string_to_bool_map Not yet run
unverified (harvested, no recorded run)
lasgroup/hpgd/src/environments/utils.py
code served (permissive licence) · get_code("caa8707bc43176db")
How it ran

no invocation recorded.

tree_random_normal_like Not yet run
unverified (harvested, no recorded run)
lasgroup/hpgd/train_zero_order.py
code served (permissive licence) · get_code("a944954ab6dc61d0")
How it ran

no invocation recorded.

update_value_functions Not yet run
unverified (harvested, no recorded run)
lasgroup/hpgd/train_amd.py
code served (permissive licence) · get_code("45825551bc380031")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 13 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.

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 optimal policy in various real-world strategic decision-making problems depends both on the environmental configuration and exogenous events. For these settings, we introduce Contextual Bilevel Reinforcement Learning (CB-RL), a stochastic bilevel decision-making model, where the lower level consists of solving a contextual Markov Decision Process (CMDP). CB-RL can be viewed as a Stackelberg Game where the leader and a random context beyond the leader's control together decide the setup of many MDPs that potentially multiple followers best respond to. This framework extends beyond traditional bilevel optimization and finds relevance in diverse fields such as RLHF, tax design, reward shaping, contract theory and mechanism design. We propose a stochastic Hyper Policy Gradient Descent (HPGD) algorithm to solve CB-RL, and demonstrate its convergence. Notably, HPGD uses stochastic hypergradient estimates, based on observations of the followers' trajectories. Therefore, it allows followers to use any training procedure and the leader to be agnostic of the specific algorithm, which aligns with various real-world scenarios. We further consider the setting when the leader can influence the training of followers and propose an accelerated algorithm. We empirically demonstrate the performance of our algorithm for reward shaping and tax design.

For agents

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

get_harvested_code_for_paper("2406.01575")
get_code_for_paper("2406.01575")
have("2406.01575")

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

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

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

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

Connect an agent — have() is free.