SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.10238 · ICML · 2021

Nonparametric Hamiltonian Monte Carlo

Carol Mak, Fabian Zaiser, Luke Ong

arXiv · PDF · Open in the Atlas

Code that ran

4 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 2 failures of our instrument; 4 no recorded run), measured 2026-11-23; 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/2106.10238.json · badge: /api/ran/2106.10238.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
fzaiser/nonparametric-hmc canonical (classifier label)
classifier basis: classifier_2025
4 ran · 4 no recorded run
FunctionStatusWhere it lives
ProbCtx Ran
ran on a synthesized input · constructed an object; no result was computed
fzaiser/nonparametric-hmc/infer.py
code served (permissive licence) · get_code("ff94237e7f7393ab")
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 an instance of its own class, ProbCtx: the run constructed the object and did not call it, so no result was computed. 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 torch
import math

torch.manual_seed(0)

# The ProbCtx.__init__ takes a single parameter: trace (torch.Tensor)
# Looking at the usage:
# - trace.clone().detach() is called
# - trace.requires_grad_(True) is called on the clone
# - self.samples.shape is used to create is_cont tensor
# So trace should be a simple 1D or multi-dimensional tensor

# Create a small trace tensor
trace = torch.randn(4)

ARGS = {
    "trace": trace
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ProbCtx — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ProbCtx 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
ProbRun Ran
ran on a synthesized input · constructed an object; no result was computed
fzaiser/nonparametric-hmc/infer.py
code served (permissive licence) · get_code("39c29a03698ae55c")
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 an instance of its own class, ProbRun: the run constructed the object and did not call it, so no result was computed. 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 torch
import math
from typing import Generic, TypeVar

torch.manual_seed(0)

class ProbCtx:
    """Probabilistic context: keeps track of a probabilistic execution (samples, weight, etc.)"""

    def __init__(self, trace: torch.Tensor) -> None:
        self.idx = 0
        self.samples = trace.clone().detach()
        self.samples.requires_grad_(True)
        self.is_cont: torch.Tensor = torch.ones(self.samples.shape, dtype=torch.bool)
        self.log_weight = torch.tensor(0.0, requires_grad=True)
        self.log_score = torch.tensor(0.0, requires_grad=True)

    def constrain(self, sample, geq: float=None, lt: float=None) -> None:
        if lt is not None:
            if sample >= lt:
                self.score_log(torch.tensor(-math.inf))
        if geq is not None:
            if sample <= geq:
                self.score_log(torch.tensor(-math.inf))

    def sample(self, dist: torch.distributions.Distribution, is_cont: bool) -> torch.Tensor:
        samples = self.sample_n(1, dist, is_cont)
        return samples[0]

    def sample_n(self, n: int, dist: torch.distributions.Distribution, is_cont: bool) -> torch.Tensor:
        needed = self.idx + n - len(self.samples)
        if needed > 0:
            values = dist.sample((needed,))
            values.requires_grad_(True)
            self.samples = torch.cat((self.samples, values))
            self.is_cont = torch.cat((self.is_cont, torch.ones(needed, dtype=torch.bool)))
        for i in range(self.idx, self.idx + n):
            if math.isnan(self.samples[i]):
                self.samples[i] = dist.sample(())
        values = self.samples[self.idx:self.idx + n]
        self.is_cont[self.idx:self.idx + n] = torch.tensor(is_cont).repeat(n)
        try:
            self.log_weight = self.log_weight + torch.sum(dist.log_prob(values))
        except ValueError:
            self.log_weight = torch.tensor(-math.inf)
        self.idx += n
        return values

    def score(self, weight: torch.Tensor) -> None:
        assert torch.is_tensor(weight), 'weight is not a tensor'
        self.score_log(torch.log(weight))

    def score_log(self, log_weight: torch.Tensor) -> None:
        assert torch.is_tensor(log_weight), 'weight is not a tensor'
        self.log_weight = self.log_weight + log_weight
        self.log_score = self.log_score + log_weight

    def observe(self, obs: torch.Tensor, dist: torch.distributions.Distribution) -> None:
        self.score_log(dist.log_prob(obs))

T = TypeVar('T')

class ProbRun(Generic[T]):
    """Result of a probabilistic run"""

    def __init__(self, ctx: ProbCtx, value: T) -> None:
        self._gradU: torch.Tensor = None
        self.log_weight = ctx.log_weight
        self.log_score = ctx.log_score
        self.samples = ctx.samples
        self.len = ctx.idx
        self.is_cont = ctx.is_cont


# Create setup arguments
trace = torch.randn(3)
ctx = ProbCtx(trace)

# Simulate some sampling to populate the context
dist = torch.distributions.Normal(0.0, 1.0)
ctx.sample(dist, is_cont=True)
ctx.sample(dist, is_cont=True)

return_value = {"result": 42, "data": torch.tensor([1.0, 2.0, 3.0])}

ARGS = {
    "ctx": ctx,
    "value": return_value
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ProbRun — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ProbRun 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
parse_anglican_timings Ran
ran; our contract draft was wrong, not the code
fzaiser/nonparametric-hmc/evaluation.py
code served (permissive licence) · get_code("cde8a094fa42f427")
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) 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 tempfile
import os

# Create a temporary file with Anglican timing data
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_filename = temp_file.name

# Write sample Anglican timing data
temp_file.write("method1\n")
temp_file.write("100 msecs\n")
temp_file.write("150 msecs\n")
temp_file.write("method2\n")
temp_file.write("200 msecs\n")
temp_file.write("250 msecs\n")
temp_file.write("300 msecs\n")

temp_file.close()

ARGS = {
    "filename": temp_filename
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
matplotlib, seaborn — 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
thin_runs Ran
ran; our contract draft was wrong, not the code
fzaiser/nonparametric-hmc/evaluation.py
code served (permissive licence) · get_code("f5813ce313755a26")
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) and returned list, 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 torch
import numpy as np

# Construct valid arguments for thin_runs function

# Create sample data structure matching what the function expects
# The function iterates through runs, accessing run[method]['samples']
# where method is from all_methods list

# Build a single run dict with samples for each method
run = {
    'hmc': {'samples': list(range(100))},  # 100 samples
    'is': {'samples': list(range(100))},
    'lmh': {'samples': list(range(100))},
    'pgibbs': {'samples': list(range(100))},
    'rmh': {'samples': list(range(100))},
    'ipmcmc': {'samples': list(range(100))}
}

# Create a list of runs (function iterates through multiple runs)
runs = [run]

# Define all_methods parameter
all_methods_param = ['hmc', 'is', 'lmh', 'pgibbs', 'rmh', 'ipmcmc']

# Construct ARGS dict with all required parameters
ARGS = {
    'all_methods': all_methods_param,
    'runs': runs
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
matplotlib, numpy, seaborn, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list 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
coord_integrator Not yet run
unverified (harvested, no recorded run)
fzaiser/nonparametric-hmc/infer.py
code served (permissive licence) · get_code("54ae7f011c24d8ff")
How it ran

no invocation recorded.

integrator_step Not yet run
unverified (harvested, no recorded run)
fzaiser/nonparametric-hmc/infer.py
code served (permissive licence) · get_code("4817d57b7ebcf4f0")
How it ran

no invocation recorded.

np_dhmc Not yet run
unverified (harvested, no recorded run)
fzaiser/nonparametric-hmc/infer.py
code served (permissive licence) · get_code("68c352586edf0684")
How it ran

no invocation recorded.

thin_list Not yet run
unverified (harvested, no recorded run)
fzaiser/nonparametric-hmc/evaluation.py
code served (permissive licence) · get_code("8a6993df81cb7c27")
How it ran

no invocation recorded. this sample carries JSON test cases instead of a setup block; get_reference_implementation serves them with the level they back.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 3 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 3 later) and 5 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
parse_anglican_timings 1 other paper
1 later
2211.01100 (2022-11)
Nonparametric Involutive Markov Chain Monte Carlo
thin_list 1 other paper
1 later
2211.01100 (2022-11)
Nonparametric Involutive Markov Chain Monte Carlo
thin_runs 1 other paper
1 later
2211.01100 (2022-11)
Nonparametric Involutive Markov Chain Monte Carlo

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-23.

Repositories linked to this paper

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

Abstract

Probabilistic programming uses programs to express generative models whose posterior probability is then computed by built-in inference engines. A challenging goal is to develop general purpose inference algorithms that work out-of-the-box for arbitrary programs in a universal probabilistic programming language (PPL). The densities defined by such programs, which may use stochastic branching and recursion, are (in general) nonparametric, in the sense that they correspond to models on an infinite-dimensional parameter space. However standard inference algorithms, such as the Hamiltonian Monte Carlo (HMC) algorithm, target distributions with a fixed number of parameters. This paper introduces the Nonparametric Hamiltonian Monte Carlo (NP-HMC) algorithm which generalises HMC to nonparametric models. Inputs to NP-HMC are a new class of measurable functions called "tree representable", which serve as a language-independent representation of the density functions of probabilistic programs in a universal PPL. We provide a correctness proof of NP-HMC, and empirically demonstrate significant performance improvements over existing approaches on several nonparametric examples.

For agents

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

get_harvested_code_for_paper("2106.10238")
get_code_for_paper("2106.10238")
have("2106.10238")

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

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

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

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

Connect an agent — have() is free.