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

Provide way to debug delta relations and expose iteration counter #2414

Merged
merged 10 commits into from
Jun 5, 2023

Conversation

julienhenry
Copy link
Member

@julienhenry julienhenry commented Jun 2, 2023

Introducing new way to debug fix point computation on recursive relations: .debug_delta.

Example:

.decl R(x:number)
.output R()
.decl D = debug_delta(R)

This produces a new output by storing each tuples from the @delta_R relation after each main fix point loop iteration, adding the iteration number where this tuple was produced.

To obtain the iteration number, I introduce some new RAM nodes (Assign and Variable) to be able to talk about a variable and modify its value. I used these new nodes to introduce a variable storing the iteration number for each LOOP node.

Now that we have an iteration counter for main iteration loops, we can expose this to the user with the recursive_iteration_cnt() intrinsic functor. This has some use cases e.g. when someone wants to control the convergence of the fix point loop :

R(x + 1) :-
    R(x),
    recursive_iteration_cnt() < 100.

@julienhenry julienhenry requested a review from quentin June 2, 2023 08:12
@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

Merging #2414 (eb41198) into master (2914f7b) will increase coverage by 0.00%.
The diff coverage is 77.93%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #2414    +/-   ##
========================================
  Coverage   77.75%   77.75%            
========================================
  Files         474      479     +5     
  Lines       31164    31364   +200     
========================================
+ Hits        24232    24388   +156     
- Misses       6932     6976    +44     
Impacted Files Coverage Δ
src/ast/analysis/typesystem/Type.cpp 47.37% <0.00%> (-0.47%) ⬇️
src/ast/analysis/typesystem/Type.h 50.00% <ø> (ø)
...c/ast/analysis/typesystem/TypeConstrainsAnalysis.h 100.00% <ø> (ø)
src/ast2ram/seminaive/ValueTranslator.h 100.00% <ø> (ø)
src/ast2ram/utility/TranslatorContext.h 100.00% <ø> (ø)
src/include/souffle/utility/SubProcess.h 55.00% <0.00%> (ø)
src/interpreter/Node.h 96.95% <ø> (ø)
src/ram/Variable.h 45.45% <45.45%> (ø)
src/ram/Assign.h 50.00% <50.00%> (ø)
src/ast/transform/SemanticChecker.cpp 95.96% <53.84%> (-1.08%) ⬇️
... and 22 more

... and 2 files with indirect coverage changes

src/parser/scanner.ll Outdated Show resolved Hide resolved
src/ram/Assign.h Outdated Show resolved Hide resolved
src/ram/Variable.h Outdated Show resolved Hide resolved
src/ast/IterationCounter.h Outdated Show resolved Hide resolved
@quentin
Copy link
Member

quentin commented Jun 5, 2023

As discussed offline, an alternative syntax would be: .decl IDENT = debug_delta(RELATION).

.decl R(x:number)
R(x) :- ... x ... R(y).

// declare a relation as being the "debug_delta" of another.
// the new relation has the signature of the original one 
// with one additional tail element that is the iteration counter. 
.decl R_debug = debug_delta(R)
.output R_debug()

.decl use_R_debug(x:number, min_iter:unsigned)
use_R_debug(x,min_iter) :-
  R_debug(x, _),
  min_iter = min iter : R_debug(x, iter).

That would be equivalent to:

.decl R_debug(x:number, iter:unsigned)
R_debug(x, relation_iteration_cnt()), R(x) :- ... x ... R(y).

For a non-recursive rule R, the debug_delta(R) would contains all facts of R and the iteration counter element value 0?

quentin
quentin previously approved these changes Jun 5, 2023
Copy link
Member

@quentin quentin left a comment

Choose a reason for hiding this comment

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

Interesting debug feature.
Shall we document the new syntax on Souffle's web page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants