Reject Missing Derivative Bindings

This tutorial shows the Torch input validation error for a gradient-enabled project key without a derivative binding.

Experimental feature

The jcmsuite.torch integration is experimental. Its API and behavior can change in future releases. Do not depend on its current interface for production workflows without testing each package update.

Run it from demos/documentation_tutorials:

python derivatives/torch/validation_missing/run.py
"""Reject a gradient-enabled Project Key without a binding."""

import torch

import jcmsuite

try:
    jcmsuite.torch.solve(
        "project.jcmp",
        keys={"width": torch.tensor(31.0, requires_grad=True)},
        key_derivative_map={},
    )
except ValueError as error:
    assert "Each gradient-enabled Project Key requires" in str(error)
    print(error)
else:
    raise AssertionError("Missing Project Key binding was accepted")

Project File

project.jcmp
Project {
  Derivatives {
    Order = 1
  }
}