Skip to content

Commit

Permalink
Add variable_names_mapping to APRProof, counterexample generation
Browse files Browse the repository at this point in the history
  • Loading branch information
palinatolmach committed Aug 6, 2024
1 parent e72b530 commit 87036cd
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pyk/src/pyk/proof/reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class APRProof(Proof[APRProofStep, APRProofResult], KCFGExploration):
_exec_time: float
error_info: Exception | None
prior_loops_cache: dict[int, tuple[int, ...]]
variable_names_mapping: dict[str, str] | None

_checked_for_bounded: set[int]

Expand All @@ -118,6 +119,7 @@ def __init__(
_exec_time: float = 0,
error_info: Exception | None = None,
prior_loops_cache: dict[int, tuple[int, ...]] | None = None,
variable_names_mapping: dict[str, str] | None = None,
):
Proof.__init__(self, id, proof_dir=proof_dir, subproof_ids=subproof_ids, admitted=admitted)
KCFGExploration.__init__(self, kcfg, terminal)
Expand All @@ -134,6 +136,7 @@ def __init__(
self.kcfg._kcfg_store = KCFGStore(self.proof_subdir / 'kcfg') if self.proof_subdir else None
self._exec_time = _exec_time
self.error_info = error_info
self.variable_names_mapping = variable_names_mapping

self._checked_for_bounded = set()

Expand Down Expand Up @@ -537,6 +540,7 @@ def read_proof_data(proof_dir: Path, id: str) -> APRProof:
terminal = proof_dict['terminal']
logs = {int(k): tuple(LogEntry.from_dict(l) for l in ls) for k, ls in proof_dict['logs'].items()}
subproof_ids = proof_dict['subproof_ids']
variable_names_mapping = proof_dict.get('variable_names_mapping', None)
node_refutations = {
kcfg._resolve(int(node_id)): proof_id for node_id, proof_id in proof_dict['node_refutations'].items()
}
Expand All @@ -559,6 +563,7 @@ def read_proof_data(proof_dir: Path, id: str) -> APRProof:
node_refutations=node_refutations,
prior_loops_cache=prior_loops_cache,
_exec_time=exec_time,
variable_names_mapping=variable_names_mapping,
)

def write_proof_data(self) -> None:
Expand Down Expand Up @@ -591,6 +596,8 @@ def write_proof_data(self) -> None:

dct['loops_cache'] = self.prior_loops_cache

dct['variable_names_mapping'] = self.variable_names_mapping

proof_json.write_text(json.dumps(dct))
_LOGGER.info(f'Wrote proof data for {self.id}: {proof_json}')
self.kcfg.write_cfg_data()
Expand Down Expand Up @@ -868,7 +875,11 @@ def __init__(
)

@staticmethod
def from_proof(proof: APRProof, kcfg_explore: KCFGExplore, counterexample_info: bool = False) -> APRFailureInfo:
def from_proof(
proof: APRProof,
kcfg_explore: KCFGExplore,
counterexample_info: bool = False,
) -> APRFailureInfo:
target = proof.kcfg.node(proof.target)
pending_nodes = {node.id for node in proof.pending}
failing_nodes = {node.id for node in proof.failing}
Expand All @@ -889,7 +900,12 @@ def from_proof(proof: APRProof, kcfg_explore: KCFGExplore, counterexample_info:
for var, term in model_subst.to_dict().items():
term_kast = KInner.from_dict(term)
term_pretty = kcfg_explore.pretty_print(term_kast)
model.append((var, term_pretty))
var_name = (
proof.variable_names_mapping.get(var, var)
if proof.variable_names_mapping is not None
else var
)
model.append((var_name, term_pretty))
models[node.id] = model
return APRFailureInfo(
failing_nodes=failing_nodes,
Expand Down

0 comments on commit 87036cd

Please sign in to comment.