Output-property DSL API
The property guide explains strictness, Boolean composition, input coordinates and certification. The tutorial constructs and trains a complete example.
Represent input-output specifications through affine comparisons and Boolean formulas.
A PropertySpec associates an output formula with closed input boxes. Affine comparisons define satisfaction margins; conjunction and disjunction combine them using minimum and maximum. These formulas can be compiled into fixed computation graphs for auto_LiRPA bound propagation.
Outputs
Construct symbolic references to network output coordinates.
For example, y = Outputs() followed by And(y[0] >= -0.75, y[0] <= 0.75) defines an output-range property. Use And and Or to combine comparisons; Python's and, or and chained comparisons do not construct symbolic formulas.
Source code in CTRAIN/properties/__init__.py
113 114 115 116 117 118 119 120 121 | |
Affine
dataclass
Bases: _Symbolic
Represent an affine expression over network outputs.
The expression is the sum of coefficient-weighted outputs plus an offset. Arithmetic and comparison operators construct formulas without evaluating a network. Use Outputs()[i] to select an output coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
tuple
|
Unique nonnegative output indices paired with finite coefficients. |
()
|
offset
|
float
|
Finite constant added to the weighted outputs. |
0.0
|
Source code in CTRAIN/properties/__init__.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
evaluate(output)
Evaluate the affine expression on a batch of network outputs.
Source code in CTRAIN/properties/__init__.py
103 104 105 106 | |
tensors(output)
Return dense affine coefficients and offset in the output tensor's device and dtype.
Source code in CTRAIN/properties/__init__.py
93 94 95 96 97 98 99 100 101 | |
Box
dataclass
Define a closed input region through coordinatewise lower and upper endpoints.
Endpoints must be finite, ordered and have matching nonempty shapes. They are stored as detached float64 CPU tensors; bounding routines convert them to model coordinates with outward rounding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lower
|
Tensor or sequence
|
Lower endpoint, excluding the batch dimension. |
required |
upper
|
Tensor or sequence
|
Upper endpoint with the same shape. |
required |
Source code in CTRAIN/properties/__init__.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
to_dict()
Return the input endpoints as lists for manifests and checkpoints.
Source code in CTRAIN/properties/__init__.py
287 288 289 | |
PropertySpec
dataclass
Associate an output formula with the input regions where it must hold.
The specification requires the formula to hold for every input in every supplied box. Task examples and property regions are independent inputs to training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Nonempty specification name, unique within a wrapper. |
required |
formula
|
Comparison or Junction
|
Affine or Boolean output formula. |
required |
domains
|
Iterable[Box]
|
Nonempty collection of closed input regions. |
required |
Source code in CTRAIN/properties/__init__.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
to_dict()
Return the specification name, formula and input boxes as serialisable data.
Source code in CTRAIN/properties/__init__.py
317 318 319 320 | |
PropertyGraph
Bases: Module
Append a fixed satisfaction-margin computation to a network.
The composed graph shares the original network's trainable weights and adds no trainable parameters. Bounding its output gives a lower satisfaction margin over an input region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Network whose outputs the formula references. |
required |
formula
|
Comparison or Junction
|
Output specification to compile. |
required |
relu
|
bool
|
Whether to express minimum and maximum through ReLU operations. |
False
|
output_width
|
int
|
Number of network outputs; required when it cannot be inferred from the last layer. |
None
|
Source code in CTRAIN/properties/__init__.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
forward(inputs)
Evaluate the network and return its compiled satisfaction margin.
Source code in CTRAIN/properties/__init__.py
442 443 444 | |
OutputIndex(output, index)
Return an affine expression selecting one network output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Outputs
|
Symbolic output collection. |
required |
index
|
int
|
Nonnegative output coordinate. |
required |
Returns:
| Type | Description |
|---|---|
Affine
|
Expression with coefficient one at the selected coordinate. |
Source code in CTRAIN/properties/__init__.py
124 125 126 127 128 129 130 131 132 133 134 135 136 | |
Ge(lhs, rhs, scale=1.0)
Construct lhs >= rhs with satisfaction margin (lhs - rhs) / scale.
Source code in CTRAIN/properties/__init__.py
180 181 182 | |
Le(lhs, rhs, scale=1.0)
Construct lhs <= rhs with satisfaction margin (rhs - lhs) / scale.
Source code in CTRAIN/properties/__init__.py
185 186 187 | |
Gt(lhs, rhs, scale=1.0)
Construct lhs > rhs with satisfaction margin (lhs - rhs) / scale.
Source code in CTRAIN/properties/__init__.py
190 191 192 | |
Lt(lhs, rhs, scale=1.0)
Construct lhs < rhs with satisfaction margin (rhs - lhs) / scale.
Source code in CTRAIN/properties/__init__.py
195 196 197 | |
And(*children)
Construct a conjunction of at least two output formulas.
Source code in CTRAIN/properties/__init__.py
246 247 248 | |
Or(*children)
Construct a disjunction of at least two output formulas.
Source code in CTRAIN/properties/__init__.py
251 252 253 | |
load_vnnlib_property is documented in the
loader reference.
For lower-level integrations, see property bounds,
certification and counterexample search, and
task/property losses.