Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions ada_verona/database/verification_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from pathlib import Path

import numpy as np
import pandas as pd

from ada_verona.database.dataset.data_point import DataPoint
Expand Down Expand Up @@ -88,15 +89,22 @@ def save_vnnlib_property(self, vnnlib_property: VNNLibProperty) -> None:
f.write(vnnlib_property.content)
vnnlib_property.path = save_path

if vnnlib_property.image is not None or vnnlib_property.image_class is not None:
meta_path = self.tmp_path / f"{vnnlib_property.name}.npz"
np.savez_compressed(
meta_path,
image=vnnlib_property.image,
image_class=-1 if vnnlib_property.image_class is None else vnnlib_property.image_class,
epsilon=-1.0 if vnnlib_property.epsilon is None else vnnlib_property.epsilon,
)

def delete_tmp_path(self) -> None:
"""
Delete the temporary path and its contents.
"""


self.tmp_path.unlink()


def save_status_list(self, epsilon_status_list: list[EpsilonStatus]) -> None:
"""
Save the list of epsilon statuses to a CSV file.
Expand Down Expand Up @@ -153,7 +161,7 @@ def from_dict(cls, data: dict) -> "VerificationContext":
"""
# Recreate the network from its dictionary representation

network = ONNXNetwork.from_dict(data["network"])
network = ONNXNetwork.from_dict(data["network"])
data_point = DataPoint.from_dict(data["data_point"])
tmp_path = Path(data["tmp_path"])
property_generator = PropertyGenerator.from_dict(data["property_generator"])
Expand All @@ -164,4 +172,4 @@ def from_dict(cls, data: dict) -> "VerificationContext":
tmp_path=tmp_path,
property_generator=property_generator,
save_epsilon_results=save_epsilon_results,
)
)
5 changes: 5 additions & 0 deletions ada_verona/database/vnnlib_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from dataclasses import dataclass
from pathlib import Path

import numpy as np


@dataclass
class VNNLibProperty:
Expand All @@ -24,3 +26,6 @@ class VNNLibProperty:
name: str
content: str
path: Path = None
epsilon: float | None = None
image: np.ndarray | None = None
image_class: int | None = None
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ def create_vnnlib_property(self, image: np.array, image_class: int, epsilon: flo

property_name = f"property_{image_class}_{str(epsilon).replace('.', '_')}"

return VNNLibProperty(name=property_name, content=result)
return VNNLibProperty(
name=property_name,
content=result,
epsilon=epsilon,
image=image,
image_class=image_class,
)

def get_dict_for_epsilon_result(self) -> dict:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ def create_vnnlib_property(self, image: np.array, image_class: int, epsilon: flo

property_name = f"property_{image_class}_{str(epsilon).replace('.', '_')}"

return VNNLibProperty(name=property_name, content=result)
return VNNLibProperty(
name=property_name,
content=result,
epsilon=epsilon,
image=image,
image_class=image_class,
)

def get_dict_for_epsilon_result(self) -> dict:
"""
Expand Down