# Understanding VerificationContext in VERONA's Pipeline: A Complete Technical Guide

> Master VERONA's verification pipeline by understanding VerificationContext. This guide details how it manages models, data, and properties from VNNLib to results.

- Repository: [ADA research/verona](https://github.com/ada-research/verona)
- Tags: deep-dive
- Published: 2026-02-23

---

**VerificationContext is the central data carrier in VERONA's robustness verification pipeline that encapsulates the neural network model, input data point, temporary workspace, and property generator, serving as the single source of truth from VNNLib property creation through result persistence.**

VERONA, developed by ADA Research, is an open-source framework designed for rigorous neural network robustness verification. At the heart of this system lies the `VerificationContext` class, which orchestrates the entire verification workflow by binding together models, data, and temporary artefacts. Understanding how `VerificationContext` functions within VERONA's pipeline is essential for developers seeking to extend the framework, integrate custom verifiers, or reproduce experiments reliably.

## What Is VerificationContext in VERONA?

`VerificationContext` is instantiated once per data point and persists through the entire VERONA pipeline. According to the source code in [`ada_verona/database/verification_context.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/verification_context.py), this class acts as the core data carrier that ties together **model**, **input**, **property generation**, and **temporary artefacts** for every verification run.

Key responsibilities include:

- **Holding the model**: Stores the concrete `Network` implementation (ONNX, PyTorch, etc.) in `self.network`, initialized in `__init__` (lines 34-56 of [`verification_context.py`](https://github.com/ada-research/verona/blob/main/verification_context.py)).
- **Holding the data point**: Maintains the image tensor, label, and identifier in `self.data_point`.
- **Providing a temporary workspace**: Manages intermediate files (`.vnnlib`, CSV logs) through `self.tmp_path`, created automatically if missing during initialization and in `save_vnnlib_property()`.
- **Encapsulating property generation**: Contains a `PropertyGenerator` instance in `self.property_generator` that creates VNNLib properties from the image, class, and epsilon value.
- **Persisting artefacts**: Saves VNNLib files, epsilon-status CSVs, and optional result CSVs via `save_vnnlib_property()`, `save_status_list()`, and `save_result()`.
- **Enabling serialization**: Supports checkpointing and experiment replay through `to_dict()` and `from_dict()` methods.

## How VerificationContext Fits Into the VERONA Pipeline Flow

The context orchestrates data flow across five distinct stages while keeping file-system side-effects confined to a single temporary directory per run.

1. **Experiment Repository** ([`ada_verona/database/experiment_repository.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/experiment_repository.py)): Creates a fresh `VerificationContext` for each data point and stores it if needed for later retrieval.
2. **Property Generator** (`ada_verona/verification_module/property_generator/*.py`): Receives the raw image and epsilon value from the context, returning a `VNNLibProperty` object.
3. **Verification Module** (e.g., `AutoVerifyModule` in [`ada_verona/verification_module/auto_verify_module.py`](https://github.com/ada-research/verona/blob/main/ada_verona/verification_module/auto_verify_module.py)): Consumes the context to write the VNNLib file via `save_vnnlib_property()`, runs the external verifier, and parses counter-examples.
4. **Epsilon-Value Estimator** (`ada_verona/epsilon_value_estimator/*.py`): Reads the `VerificationContext` (usually via its dictionary form from `to_dict()`) to decide which epsilon value to test next based on previous verification outcomes.
5. **Result Reporting** ([`ada_verona/analysis/report_creator.py`](https://github.com/ada-research/verona/blob/main/ada_verona/analysis/report_creator.py)): Reads the CSV artefacts saved by the context to generate comprehensive robustness reports.

## Practical Code Examples for VerificationContext

### Creating a VerificationContext Instance

The constructor in [`ada_verona/database/verification_context.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/verification_context.py) (lines 34-56) automatically creates the temporary directory if it does not exist.

```python
from pathlib import Path
from ada_verona.database.verification_context import VerificationContext
from ada_verona.database.machine_learning_model.onnx_network import ONNXNetwork
from ada_verona.database.dataset.data_point import DataPoint
from ada_verona.verification_module.property_generator.one2any_property_generator import One2AnyPropertyGenerator

# Load model and data point

network = ONNXNetwork.load(Path("models/resnet.onnx"))
data_point = DataPoint.from_numpy(image_array, label=3, id="img_001")
tmp_path = Path("/tmp/verona_run_001")
property_gen = One2AnyPropertyGenerator()

# Assemble the context

verification_context = VerificationContext(
    network=network,
    data_point=data_point,
    tmp_path=tmp_path,
    property_generator=property_gen,
    save_epsilon_results=True,
)

```

### Using Context with AutoVerifyModule

The `AutoVerifyModule` in [`ada_verona/verification_module/auto_verify_module.py`](https://github.com/ada-research/verona/blob/main/ada_verona/verification_module/auto_verify_module.py) (lines 62-66 and 81-82) extracts the image, generates properties, and persists files through the context.

```python
from ada_verona.verification_module.auto_verify_module import AutoVerifyModule
from autoverify.verifier.verifier import Verifier

# Initialize verifier

verifier = Verifier(name="verinet")
module = AutoVerifyModule(verifier, timeout=300.0)

# Execute verification

epsilon = 0.02
result = module.verify(verification_context, epsilon)

print("Verification outcome:", result.result)  # Outputs: SAT or UNSAT

```

Internally, `module.verify` flattens the image tensor via `verification_context.data_point.data.reshape(-1).detach().numpy()`, requests a VNNLib property from `verification_context.property_generator.create_vnnlib_property()`, and writes it to disk using `verification_context.save_vnnlib_property()`.

### Persisting Verification Results

After verification, persist results using methods from [`ada_verona/database/verification_context.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/verification_context.py) (lines 98-108 and 110-125).

```python
from ada_verona.database.epsilon_status import EpsilonStatus

# Create status record

status = EpsilonStatus(
    epsilon=epsilon,
    result=result.result,
    runtime=result.duration,
    obtained_labels=result.obtained_labels,
)

# Append single result to CSV

verification_context.save_result(status)

# Or write entire list at once

verification_context.save_status_list([status])

```

The resulting `epsilon_results.csv` resides in the context's `tmp_path` and is subsequently consumed by epsilon-value estimators to guide adaptive robustness analysis.

### Serializing and Restoring Context

For checkpointing or distributed experiments, use the serialization methods in [`ada_verona/database/verification_context.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/verification_context.py) (lines 126-140 and 141-165).

```python

# Serialize to dictionary

context_dict = verification_context.to_dict()

# Persist as JSON

import json
Path("checkpoint.json").write_text(json.dumps(context_dict))

# Later: reconstruct

restored_ctx = VerificationContext.from_dict(context_dict)

```

All nested objects—including `Network`, `DataPoint`, and `PropertyGenerator`—implement their own `to_dict()` and `from_dict()` methods, enabling lossless round-trip serialization for experiment reproducibility.

## Key Source Files in the VERONA Repository

| File | Role | Source Link |
|------|------|-------------|
| [`ada_verona/database/verification_context.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/verification_context.py) | Central context class holding model, data point, temp path, property generator, and persistence helpers. | [View on GitHub](https://github.com/ada-research/verona/blob/main/ada_verona/database/verification_context.py) |
| [`ada_verona/verification_module/property_generator/property_generator.py`](https://github.com/ada-research/verona/blob/main/ada_verona/verification_module/property_generator/property_generator.py) | Abstract base for property generators; consumed by the context to create VNNLib properties. | [View on GitHub](https://github.com/ada-research/verona/blob/main/ada_verona/verification_module/property_generator/property_generator.py) |
| [`ada_verona/verification_module/auto_verify_module.py`](https://github.com/ada-research/verona/blob/main/ada_verona/verification_module/auto_verify_module.py) | Concrete verification module that consumes `VerificationContext`, writes VNNLib files, and executes external verifiers. | [View on GitHub](https://github.com/ada-research/verona/blob/main/ada_verona/verification_module/auto_verify_module.py) |
| [`ada_verona/verification_module/verification_module.py`](https://github.com/ada-research/verona/blob/main/ada_verona/verification_module/verification_module.py) | Minimal abstract interface that all verification modules implement. | [View on GitHub](https://github.com/ada-research/verona/blob/main/ada_verona/verification_module/verification_module.py) |
| [`ada_verona/database/experiment_repository.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/experiment_repository.py) | Factory for creating and persisting `VerificationContext` objects during experiment orchestration. | [View on GitHub](https://github.com/ada-research/verona/blob/main/ada_verona/database/experiment_repository.py) |
| `ada_verona/epsilon_value_estimator/*.py` | Estimators that read `VerificationContext` (via its dict form) to guide epsilon search. | [View on GitHub](https://github.com/ada-research/verona/tree/main/ada_verona/epsilon_value_estimator) |
| [`ada_verona/analysis/report_creator.py`](https://github.com/ada-research/verona/blob/main/ada_verona/analysis/report_creator.py) | Reads CSV artefacts saved by the context to generate robustness reports. | [View on GitHub](https://github.com/ada-research/verona/blob/main/ada_verona/analysis/report_creator.py) |

## Summary

- **VerificationContext** acts as the central orchestration object in VERONA's pipeline, instantiated once per data point to maintain state throughout the verification lifecycle.
- The class encapsulates the **neural network model** (`network`), **input data** (`data_point`), **temporary workspace** (`tmp_path`), and **property generation logic** (`property_generator`).
- It provides **persistence methods** including `save_vnnlib_property()`, `save_status_list()`, and `save_result()` to manage intermediate artefacts and CSV logs.
- **Serialization support** via `to_dict()` and `from_dict()` enables checkpointing and experiment reproducibility across distributed runs.
- Located in [`ada_verona/database/verification_context.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/verification_context.py), this class bridges the experiment repository, property generators, verification modules like `AutoVerifyModule`, and epsilon-value estimators.

## Frequently Asked Questions

### What is the primary purpose of VerificationContext in VERONA?

The primary purpose of **VerificationContext** is to serve as the single source of truth for a single verification run. It binds together the model, input data, property generator, and temporary file workspace, ensuring that all components of VERONA's pipeline—from the experiment repository to the epsilon estimator—access consistent, serialized state throughout the robustness verification process.

### How does VerificationContext handle temporary files during verification?

The context manages temporary files through its `tmp_path` attribute, which is automatically created during instantiation if it does not exist. When verification modules like `AutoVerifyModule` generate VNNLib properties, they call `save_vnnlib_property()` to write `.vnnlib` files to this directory, while epsilon status CSVs are persisted via `save_result()` or `save_status_list()`, keeping all artefacts isolated per run.

### Can VerificationContext be serialized for checkpointing?

Yes, the class implements `to_dict()` and `from_dict()` methods (lines 126-165 in [`verification_context.py`](https://github.com/ada-research/verona/blob/main/verification_context.py)) to support full serialization. These methods recursively serialize nested objects including the `Network`, `DataPoint`, and `PropertyGenerator`, enabling developers to dump the entire verification state to JSON or YAML and later reconstruct it for experiment replay or fault tolerance.

### Where is VerificationContext instantiated in the VERONA codebase?

`VerificationContext` is instantiated in multiple locations: primarily in [`ada_verona/database/experiment_repository.py`](https://github.com/ada-research/verona/blob/main/ada_verona/database/experiment_repository.py) during experiment orchestration, in test fixtures within [`tests/test_verification_module/conftest.py`](https://github.com/ada-research/verona/blob/main/tests/test_verification_module/conftest.py) (lines 23-28), and in utility scripts. The constructor signature requires `network`, `data_point`, `tmp_path`, and `property_generator` arguments, with an optional `save_epsilon_results` flag to control CSV logging.