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

SYNTHESIZER: Add quick filter into goto-synthesizer #7973

Merged
merged 2 commits into from
Nov 22, 2023

Conversation

qinheping
Copy link
Collaborator

The quick filter check if a candidate invariant (predicates of type exprt) is consistent with the previous seen examples by evaluating the candidate on the examples (valuations of variables collected from CBMC trace). The idea is that the quick filter is more efficient than CBMC for checking if a candidate is incorrect.

So the synthesizer can use the quick filter to rule out incorrect candidates in an early stage before sending them to CBMC.

In detail, we say a candidate is consistent with a positive (negative) example if the evaluation of the candidate on it is true (false). If a candidate is inconsistent with any example, it cannot be a valid loop invariant predicate.

Examples are collected in the verification stage. In a CBMC trace, the valuations of variables upon the entry of the loop (loop_entry) must satisfy the loop invariants, so that they are positive examples. Oppositely, valuations of variables in the havoced iteration must not satisfy the loop invariants, so that they are negative examples.

The quick filter significantly reduce the number of candidate sent to CBMC. As an example, in the benchmark loop_contracts_synthesis_04, 60 out of 67 bad candidates
are ruled out be the quick filter.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@qinheping qinheping added aws Bugs or features of importance to AWS CBMC users Synthesis Invariant synthesis labels Oct 21, 2023
@qinheping qinheping force-pushed the features/quick-filter branch from 44e2221 to fdaf2b5 Compare October 23, 2023 17:31
@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

Attention: 45 lines in your changes are missing coverage. Please review.

Comparison is base (44e53c8) 79.09% compared to head (195a296) 79.09%.

Files Patch % Lines
src/goto-synthesizer/cegis_evaluator.cpp 58.33% 45 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop    #7973    +/-   ##
=========================================
  Coverage    79.09%   79.09%            
=========================================
  Files         1699     1701     +2     
  Lines       196503   196625   +122     
=========================================
+ Hits        155419   155527   +108     
- Misses       41084    41098    +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@qinheping qinheping force-pushed the features/quick-filter branch 2 times, most recently from c38511c to 052df4a Compare October 26, 2023 19:54
@qinheping
Copy link
Collaborator Author

I also modify the benchmark loop_contracts_synthesis_03 to avoid long running time due to the bug reported in #7978.

Comment on lines +304 to +307
// Typecast `result` to the type of `expr`.
auto tmp_expr = from_integer(result, expr.type());
to_integer(tmp_expr, result);
return result;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This piece of code (repeated below) looks strange. Are you really just doing a modulo operation here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The result is the evaluation of expr. result may be larger than the max of the type of expr and hence overflow. So I use from_integer and to_integer here to typecast the result to the type of expr to avoid overflow.

src/goto-synthesizer/cegis_evaluator.h Outdated Show resolved Hide resolved
The function should scan all sub-expressions `it` of the given expression `expr` and check if `*it` has a given prefix.
The quick filter check if a candidate is consistent with the previous seen examples by evaluating the candidate on the examples.
The idea is that quick filter is more efficient than CBMC for checking if a candidate is incorrect.
So the synthesizer can use the quick filter to rule out incorrect candidates in an early stage before sending them to CBMC.

In detail, we say a candidate is consistent with a positive (negative) example if the evaluation of the candidate on it is true (false).
If a candidate is inconsistent with any example, it cannot be a valid loop invariant predicate.

Examples are collected in the verification stage. In a CBMC trace, the valuations of variables upon the entry of the loop (loop_entry)
must satisfy the loop invariants, so that they are positive examples. Oppositely, valuations of variables in the havoced iteration must not satisfy
the loop invariants, so that they are negative examples.

The quick filter sinificantly reduce the number of candidate sent to CBMC. As an example, in the benchmark `loop_contracts_synthesis_04`, 61 out of 67 bad candidates
are ruled out be the quick filter.
@qinheping qinheping force-pushed the features/quick-filter branch from c4da2a9 to 195a296 Compare November 22, 2023 05:00
@qinheping qinheping enabled auto-merge November 22, 2023 05:01
@qinheping qinheping merged commit 52688d7 into diffblue:develop Nov 22, 2023
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users aws-high Synthesis Invariant synthesis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants