Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing backend information to construct KCFGs more efficiently #4590

Merged
merged 31 commits into from
Aug 19, 2024

Conversation

PetarMax
Copy link
Contributor

@PetarMax PetarMax commented Aug 14, 2024

This PR leverages information provided by the backend as part of an execute request to construct more than one KCFG element: specifically, vacuous nodes, stuck nodes, edges resulting from cut-nodes, branches, and non-deterministic branches.

In addition, it moves the associated printing to the KCFG class, allowing for more informative prints: for example, we can now print the target nodes of edges and branches, the absence of which (personally) was making debugging of large proofs slightly more difficult.

The PR also removes the always_check_subsumption flag, which was not used and was made obsolete by the subsumption logic in step_proof.

@PetarMax PetarMax self-assigned this Aug 14, 2024
@rv-jenkins rv-jenkins changed the base branch from master to develop August 14, 2024 21:32
@PetarMax PetarMax closed this Aug 15, 2024
@PetarMax PetarMax force-pushed the petar/streamlining-branching branch from 687ccda to 079be45 Compare August 15, 2024 11:08
@PetarMax PetarMax reopened this Aug 15, 2024
@PetarMax
Copy link
Contributor Author

I need some help with this PR, @ehildenb, @tothtamas28, @nwatson22, if you can. I've left comments throughout, please advise.

@PetarMax PetarMax changed the title More immediate branching Reusing backend information to construct KCFGs more efficiently Aug 15, 2024
@PetarMax PetarMax requested review from tothtamas28, nwatson22 and ehildenb and removed request for tothtamas28 August 15, 2024 17:10
@PetarMax
Copy link
Contributor Author

I will now run some engagement proofs using this and check for speedups.

@PetarMax PetarMax requested a review from tothtamas28 August 16, 2024 17:14
@PetarMax PetarMax marked this pull request as ready for review August 16, 2024 18:35
pyk/src/pyk/kcfg/explore.py Outdated Show resolved Hide resolved
pyk/src/pyk/kcfg/explore.py Outdated Show resolved Hide resolved
@@ -1306,7 +1321,8 @@ def read_node_data(cfg_dir: Path, node_id: int) -> KCFG.Node:
return KCFG.Node.from_dict(store.read_node_data(node_id))


class KCFGExtendResult(ABC): ...
class KCFGExtendResult(ABC):
info: str = field(default='')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider

Suggested change
info: str = field(default='')
info: str

and adding the info: str = field(default='') to each dataclass subclass.

Alternatively, do not make it an abstract attribute, since the value is not used for most subclasses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be ok to just have it in the ones where it's needed? The compilation does not seem to complain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but then it shouldn't be present in the abstract class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I removed it from there.

pyk/src/pyk/kcfg/semantics.py Show resolved Hide resolved
extend_result: KCFGExtendResult
"""Holds the description of how an APRProof should be extended.

Fields:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fields:
Attributes:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 51 to 52
to_cache: Holds an indicator of whether or not the provided extension
should be cached instead of being applied.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean for an extension to be cached?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extend_cterm can now return two extensions, the first of which is a Step, and the second of which is a cut-rule, branch, or NDBranch. When that happens, the first one is to be applied, and the second one is to be cached so that it can be automatically applied instead of recomputed when we explore from the node created by that first Step.

Comment on lines 217 to 218
assert len(result.extend_results) == 0
assert result.use_cache in self._next_steps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, all these assertions indicate that APRProofExtendResult could be broken up into multiple subclasses with stronger typing guarantees.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100%. I will think about this a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've redesigned them now.

@PetarMax PetarMax requested a review from tothtamas28 August 19, 2024 10:46
Copy link
Contributor

@tothtamas28 tothtamas28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please test on evm-semantics and kontrol before merging.

pyk/src/pyk/proof/reachability.py Outdated Show resolved Hide resolved
@@ -12,15 +12,28 @@ class KCFGSemantics(ABC):
@abstractmethod
def is_terminal(self, c: CTerm) -> bool: ...

"""Checks whether or not a given CTerm is terminal."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Checks whether or not a given CTerm is terminal."""
"""Check whether or not a given ``CTerm`` is terminal."""

node_id=step.node.id,
)
# If the step has already been cached, do not invoke the backend and only send a signal back to the proof to use the cache
if step.use_cache is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the prover is terminated with cached results not yet applied? Is it still possible to continue extending the KCFG?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is, and cached results should be re-used if the proof has survived. If they are lost, there is no loss for the KCFG, since they are only a snapshot of guaranteed future extension results.

@PetarMax
Copy link
Contributor Author

Yes, it has been extensively tested with Kontrol and engagement tests.

PetarMax and others added 2 commits August 19, 2024 13:42
@PetarMax PetarMax merged commit c8738d6 into develop Aug 19, 2024
17 checks passed
@PetarMax PetarMax deleted the petar/streamlining-branching branch August 19, 2024 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants