Skip to content

Commit 66c49c1

Browse files
committed
Add disk read/write test and fix
1 parent 7c42864 commit 66c49c1

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

pyk/src/pyk/proof/proof.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Proof(Generic[PS, SR]):
4040
:param SR: Step result: data produced by executing a PS with `Prover.step_proof` used to update the `Proof`
4141
"""
4242

43-
_PROOF_TYPES: Final = {'APRProof', 'EqualityProof', 'RefutationProof'}
43+
_PROOF_TYPES: Final = {'APRProof', 'EqualityProof', 'RefutationProof', 'MultiProof'}
4444

4545
id: str
4646
proof_dir: Path | None
@@ -247,6 +247,7 @@ def read_proof(cls: type[Proof], id: str, proof_dir: Path) -> Proof:
247247
def read_proof_data(proof_dir: Path, id: str) -> Proof:
248248
# these local imports allow us to call .to_dict() based on the proof type we read from JSON
249249
from .implies import EqualityProof, RefutationProof # noqa
250+
from .proof import MultiProof # noqa
250251
from .reachability import APRProof # noqa
251252

252253
proof_path = proof_dir / id / 'proof.json'
@@ -303,12 +304,18 @@ def can_progress(self) -> bool:
303304
def commit(self, result: None) -> None: ...
304305

305306
@classmethod
306-
def from_dict(cls: type[Proof], dct: Mapping[str, Any], proof_dir: Path | None = None) -> Proof:
307+
def from_dict(cls: type[Proof], dct: Mapping[str, Any], proof_dir: Path | None = None) -> MultiProof:
307308
_id = dct['id']
308309
_subproof_ids = dct['subproof_ids']
309310
_admitted = dct['admitted']
310311
return MultiProof(id=_id, subproof_ids=_subproof_ids, proof_dir=proof_dir, admitted=_admitted)
311312

313+
@property
314+
def dict(self) -> dict[str, Any]:
315+
dct = super().dict
316+
dct['type'] = 'MultiProof'
317+
return dct
318+
312319
def get_steps(self) -> Iterable[None]:
313320
"""Return all currently available steps associated with this Proof. Should not modify `self`."""
314321
return []
@@ -317,6 +324,15 @@ def get_steps(self) -> Iterable[None]:
317324
def own_status(self) -> ProofStatus:
318325
return ProofStatus.PASSED
319326

327+
@staticmethod
328+
def read_proof_data(proof_dir: Path, id: str) -> MultiProof:
329+
proof_path = proof_dir / id / 'proof.json'
330+
if Proof.proof_data_exists(id, proof_dir):
331+
proof_dict = json.loads(proof_path.read_text())
332+
return MultiProof.from_dict(proof_dict, proof_dir)
333+
334+
raise ValueError(f'Could not load Proof from file {id}: {proof_path}')
335+
320336
def write_proof_data(self) -> None:
321337
super().write_proof_data()
322338
if not self.proof_dir:

pyk/src/tests/integration/proof/test_multi_proof.py

+39-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _update_symbol_table(symbol_table: SymbolTable) -> None:
4848
MULTIPROOF_TEST_DATA,
4949
ids=[test_id for test_id, *_ in MULTIPROOF_TEST_DATA],
5050
)
51-
def test_multiproof_pass(
51+
def test_multiproof_status(
5252
self,
5353
kprove: KProve,
5454
kcfg_explore: KCFGExplore,
@@ -58,7 +58,6 @@ def test_multiproof_pass(
5858
claim_id_2: str,
5959
proof_status: ProofStatus,
6060
) -> None:
61-
6261
spec_file = K_FILES / 'imp-simple-spec.k'
6362
spec_module = 'IMP-FUNCTIONAL-SPEC'
6463

@@ -92,3 +91,41 @@ def test_multiproof_pass(
9291
equality_prover.advance_proof(equality_proof_2)
9392

9493
assert mproof.status == proof_status
94+
95+
def test_multiproof_write(
96+
self,
97+
kprove: KProve,
98+
kcfg_explore: KCFGExplore,
99+
proof_dir: Path,
100+
) -> None:
101+
spec_file = K_FILES / 'imp-simple-spec.k'
102+
spec_module = 'IMP-FUNCTIONAL-SPEC'
103+
104+
claim_id_1 = 'concrete-addition'
105+
claim_id_2 = 'concrete-identity'
106+
107+
claim_1 = single(
108+
kprove.get_claims(
109+
Path(spec_file), spec_module_name=spec_module, claim_labels=[f'{spec_module}.{claim_id_1}']
110+
)
111+
)
112+
claim_2 = single(
113+
kprove.get_claims(
114+
Path(spec_file), spec_module_name=spec_module, claim_labels=[f'{spec_module}.{claim_id_2}']
115+
)
116+
)
117+
118+
equality_proof_1 = EqualityProof.from_claim(claim_1, kprove.definition, proof_dir=proof_dir)
119+
equality_proof_2 = EqualityProof.from_claim(claim_2, kprove.definition, proof_dir=proof_dir)
120+
121+
equality_proof_1.write_proof_data()
122+
equality_proof_2.write_proof_data()
123+
124+
mproof = MultiProof(
125+
id='multiproof1', subproof_ids=[equality_proof_1.id, equality_proof_2.id], proof_dir=proof_dir
126+
)
127+
128+
mproof.write_proof_data()
129+
130+
disk_mproof = MultiProof.read_proof_data(proof_dir=proof_dir, id='multiproof1')
131+
assert disk_mproof.dict == mproof.dict

0 commit comments

Comments
 (0)