Reject Unknown Derivative Bindings

This tutorial shows the Torch input validation error for a derivative binding whose project key is absent from keys.

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_unknown/run.py
"""Reject a derivative binding for an unknown Project Key."""

import torch

import jcmsuite
from jcmsuite.torch import RealDerivative

try:
    jcmsuite.torch.solve(
        "project.jcmp",
        keys={"width": torch.tensor(31.0)},
        key_derivative_map={"unknown": RealDerivative("unknown")},
    )
except ValueError as error:
    assert "Unknown Project Key derivative bindings" in str(error)
    print(error)
else:
    raise AssertionError("Unknown Project Key binding was accepted")

Project File

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