SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2104.12225 · ICLR · 2021

DC3: A learning method for optimization with hard constraints

J Zico Kolter, Priya Donti, David Rolnick

arXiv · PDF · Open in the Atlas

Code that ran

3 of 4 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, 0 violated it and 1 has no contract verdict; 2 failures of our instrument; 1 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/2104.12225.json · badge: /api/ran/2104.12225.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
locuslab/DC3 canonical (classifier label)
classifier basis: classifier_2025
3 ran · 1 no recorded run
FunctionStatusWhere it lives
NNSolver Ran
ran on a synthesized input
locuslab/DC3/method.py
code served (permissive licence) · get_code("92bbc476b92ba4aa")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 2, 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 torch.nn as nn
import operator
from functools import reduce

class MockData:
    def __init__(self, xdim, ydim, nknowns, neq):
        self.xdim = xdim
        self.ydim = ydim
        self.nknowns = nknowns
        self.neq = neq
    
    def complete_partial(self, x, out):
        return out
    
    def process_output(self, x, out):
        return out

class NNSolver(nn.Module):

    def __init__(self, data, args):
        super().__init__()
        self._data = data
        self._args = args
        layer_sizes = [data.xdim, self._args['hiddenSize'], self._args['hiddenSize']]
        layers = reduce(operator.add, [[nn.Linear(a, b), nn.BatchNorm1d(b), nn.ReLU(), nn.Dropout(p=0.2)] for a, b in zip(layer_sizes[0:-1], layer_sizes[1:])])
        output_dim = data.ydim - data.nknowns
        if self._args['useCompl']:
            layers += [nn.Linear(layer_sizes[-1], output_dim - data.neq)]
        else:
            layers += [nn.Linear(layer_sizes[-1], output_dim)]
        for layer in layers:
            if type(layer) == nn.Linear:
                nn.init.kaiming_normal_(layer.weight)
        self.net = nn.Sequential(*layers)

    def forward(self, x):
        out = self.net(x)
        if self._args['useCompl']:
            if 'acopf' in self._args['probType']:
                out = nn.Sigmoid()(out)
            return self._data.complete_partial(x, out)
        else:
            return self._data.process_output(x, out)

data = MockData(xdim=4, ydim=7, nknowns=2, neq=1)

INIT_ARGS = {
    'data': data,
    'args': {
        'hiddenSize': 8,
        'useCompl': True,
        'probType': 'acopf_test'
    }
}

ARGS = {
    'x': torch.randn(2, 4)
}

solver = NNSolver(**INIT_ARGS)
output = solver(**ARGS)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
eval_net Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
locuslab/DC3/method.py
code served (permissive licence) · get_code("383d8beb89292055")
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 torch
import torch.nn as nn
import numpy as np

torch.manual_seed(0)

# Create a minimal data object with required methods
class MinimalData:
    def obj_fn(self, Y):
        # Returns a scalar loss per sample
        return torch.sum(Y ** 2, dim=1)
    
    def ineq_dist(self, X, Y):
        # Returns inequality constraint distances (batch_size, num_ineq)
        batch_size = X.shape[0]
        return torch.abs(Y[:, :2])  # 2 inequality constraints
    
    def eq_resid(self, X, Y):
        # Returns equality constraint residuals (batch_size, num_eq)
        batch_size = X.shape[0]
        return Y[:, 2:3]  # 1 equality constraint
    
    def ineq_grad(self, X, Y):
        # Returns gradient w.r.t. inequality constraints
        return torch.ones_like(Y) * 0.1
    
    def eq_grad(self, X, Y):
        # Returns gradient w.r.t. equality constraints
        return torch.ones_like(Y) * 0.05
    
    def ineq_partial_grad(self, X, Y):
        # Returns partial gradient for inequality constraints
        return torch.ones_like(Y) * 0.08

# Create a minimal solver network
class MinimalSolverNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, X):
        # Returns predicted Y with same shape as X
        return self.linear(X)

# Create minimal args dictionary
args = {
    'softWeight': 1.0,
    'softWeightEqFrac': 0.3,
    'useTrainCorr': True,
    'corrLr': 0.01,
    'corrTrainSteps': 2,
    'corrMomentum': 0.9,
    'useCompl': False,
    'corrMode': 'full',
    'useTestCorr': True,
    'corrEps': 1e-4,
    'corrTestMaxSteps': 5,
}

# Create instances
data = MinimalData()
X = torch.randn(2, 4)  # batch_size=2, input_dim=4
solver_net = MinimalSolverNet()
prefix = 'test'
stats = {}

ARGS = {
    'data': data,
    'X': X,
    'solver_net': solver_net,
    'args': args,
    'prefix': prefix,
    'stats': stats,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — 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
total_loss Ran
ran; our contract draft was wrong, not the code
locuslab/DC3/method.py
code served (permissive licence) · get_code("a22b77b7cfabf9f3")
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 Tensor, 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.

import torch
import torch.nn as nn

torch.manual_seed(0)

class DataModule(nn.Module):
    def __init__(self):
        super().__init__()
    
    def obj_fn(self, Y):
        # Returns a scalar cost for objective
        return torch.sum(Y ** 2)
    
    def ineq_dist(self, X, Y):
        # Returns inequality constraint distances, shape (batch, num_constraints)
        batch_size = X.shape[0]
        num_constraints = 3
        return torch.randn(batch_size, num_constraints)
    
    def eq_resid(self, X, Y):
        # Returns equality constraint residuals, shape (batch, num_eq_constraints)
        batch_size = X.shape[0]
        num_eq = 2
        return torch.randn(batch_size, num_eq)

# Create data module
data = DataModule()

# Create small tensors: batch size 2, dimension 4
X = torch.randn(2, 4)
Y = torch.randn(2, 4)

# Create args dict with required hyperparameters
args = {
    'softWeight': 1.0,
    'softWeightEqFrac': 0.5
}

ARGS = {
    'data': data,
    'X': X,
    'Y': Y,
    'args': args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, 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
train_net Not yet run
unverified (harvested, no recorded run)
locuslab/DC3/method.py
code served (permissive licence) · get_code("c8419695db89b99f")
How it ran

no invocation recorded.

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 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 4 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

Large optimization problems with hard constraints arise in many settings, yet classical solvers are often prohibitively slow, motivating the use of deep networks as cheap "approximate solvers." Unfortunately, naive deep learning approaches typically cannot enforce the hard constraints of such problems, leading to infeasible solutions. In this work, we present Deep Constraint Completion and Correction (DC3), an algorithm to address this challenge. Specifically, this method enforces feasibility via a differentiable procedure, which implicitly completes partial solutions to satisfy equality constraints and unrolls gradient-based corrections to satisfy inequality constraints. We demonstrate the effectiveness of DC3 in both synthetic optimization tasks and the real-world setting of AC optimal power flow, where hard constraints encode the physics of the electrical grid. In both cases, DC3 achieves near-optimal objective values while preserving feasibility.

For agents

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

get_harvested_code_for_paper("2104.12225")
get_code_for_paper("2104.12225")
have("2104.12225")

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

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

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

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

Connect an agent — have() is free.