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

Phase saving, restarts, and heuristic performance logs #202

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

AntoniusW
Copy link
Collaborator

@AntoniusW AntoniusW commented Oct 7, 2019

This is a preview PR adding two standard SAT/ASP techniques.
Restarts in conjunction with the restricted guessing on applicable rules (in order to compute computation sequences as in other lazy-grounding ASP systems), however, have a negative impact on search performance. Unless further advances for lazy-grounding search to remedy that performance impact are available, this PR shall not be merged.

- Assignment provides getLastValue (i.e. phase).
- VSIDSWithPhaseSaving is VSIDS but uses saved phase from Assignment.
- BranchingHeuristicFactory knows new VSIDSWithPhaseSaving heuristics.
- HeapOfActiveAtoms polished, growForMaxAtomId added.
- TrailAssignment saves the phase (last truth value) of variables.
- CommandLineParser and SystemConfig have option to enable restarts.
- DefaultSolver runs restarts if enabled.
- Add MixedRestartStrategy combining Luby and dynamic (EMA) restarts.
- Enhanced performance logs for conflicts and restarts
- ChainedBranchingHeuristics gives access to first-run heuristics.
- HeapOfActiveAtoms reports activity increment for normalization.
- VSIDSWithPhaseSaving logs
  * the overall, normalized decrease in activity of the seelected atoms,
  * the number of most-active choices thrown away because they were not
    active choice points at the time.
- PerformanceLog prints heuristics information if DefaultSolver is
  runnning with VSIDSWithPhaseSaving
with phase saving.

- CommandLineParser and SystemConfig accept initial phase settings.
- AtomChoiceRelation stores relation between ordinary atoms and the
  choice points that influence them.
- NaiveGrounder and ProgramAnalyzingGrounder provide AtomChoiceRelation.
- NoGoodGenerator fills AtomChoiceRelation.
- BranchingHeuristicFactory sets AtomChoiceRelation for
  VSIDSWithPhaseSaving.
- PhaseInitializerFactory provides different initial phase settings.
- VSIDSWithPhaseSaving uses AtomChoiceRelation for activity increments.
- SolverFactory sets chosen phase initializer.
- TrailAssignment considers initial phase value, if phase was not set.
- Tests set a phase initializer if needed.
@codecov
Copy link

codecov bot commented Oct 23, 2019

Codecov Report

Merging #202 (fcd2436) into master (21d074a) will increase coverage by 0.00%.
The diff coverage is 70.64%.

Impacted file tree graph

@@            Coverage Diff             @@
##             master     #202    +/-   ##
==========================================
  Coverage     69.51%   69.51%            
- Complexity     2092     2159    +67     
==========================================
  Files           182      188     +6     
  Lines          8006     8261   +255     
  Branches       1416     1443    +27     
==========================================
+ Hits           5565     5743   +178     
- Misses         2086     2152    +66     
- Partials        355      366    +11     
Impacted Files Coverage Δ
.../java/at/ac/tuwien/kr/alpha/commons/util/Util.java 9.09% <0.00%> (-0.29%) ⬇️
.../at/ac/tuwien/kr/alpha/core/common/Assignment.java 86.66% <ø> (ø)
.../tuwien/kr/alpha/core/grounder/ChoiceRecorder.java 89.74% <0.00%> (+10.19%) ⬆️
...ien/kr/alpha/core/solver/MixedRestartStrategy.java 0.00% <0.00%> (ø)
...olver/heuristics/AlphaHeadMustBeTrueHeuristic.java 0.00% <0.00%> (ø)
...ore/solver/heuristics/PhaseInitializerFactory.java 23.52% <23.52%> (ø)
.../ac/tuwien/kr/alpha/core/solver/DefaultSolver.java 64.84% <40.00%> (-1.22%) ⬇️
.../tuwien/kr/alpha/core/solver/heuristics/VSIDS.java 91.48% <71.42%> (-0.18%) ⬇️
.../tuwien/kr/alpha/app/config/CommandLineParser.java 82.26% <76.19%> (-0.63%) ⬇️
...a/core/solver/heuristics/VSIDSWithPhaseSaving.java 76.92% <76.92%> (ø)
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21d074a...fcd2436. Read the comment docs.

- In HeapOfActiveAtoms several members/methods package-private now to
  allow overriding.
- Add HeapOfRelatedChoiceAtoms using AtomChoiceRelation to only record
  and initialize choice points.
- Moved ChoiceManager update in DefaultSolver to correctly know which
  atoms are choice points.
- Improved logging in VSIDSWithPhaseSaving and PerformanceLog.
- Move getAtomChoiceRelation() from NaiveGrounder to Grounder, implement
  method also in DummyGrounder and ChoiceGrounder.
- HeapOfActiveAtoms keeps track of literals occurring in the heap.
- More logging stats from VSIDSWithPhaseSaving.
- ChoiceInfluenceManager: simplified callbackOnChange
rtaupe and others added 5 commits February 12, 2020 09:25
# Conflicts:
#	src/main/java/at/ac/tuwien/kr/alpha/config/CommandLineParser.java
#	src/main/java/at/ac/tuwien/kr/alpha/config/SystemConfig.java
#	src/main/java/at/ac/tuwien/kr/alpha/grounder/NaiveGrounder.java
#	src/test/java/at/ac/tuwien/kr/alpha/grounder/NaiveGrounderTest.java
#	src/test/java/at/ac/tuwien/kr/alpha/solver/LearnedNoGoodDeletionTest.java
…e_master

Merge master into phase_saving_and_restarts
# Conflicts:
#	src/main/java/at/ac/tuwien/kr/alpha/config/CommandLineParser.java
…e_master

Merge master into phase_saving_and_restarts
@AntoniusW AntoniusW removed the blocked label Apr 15, 2020
@AntoniusW AntoniusW requested a review from rtaupe April 15, 2020 14:14
@rtaupe
Copy link
Collaborator

rtaupe commented Apr 24, 2020

Now #239 pops up also here. We should really fix this issue ...

Copy link
Collaborator

@rtaupe rtaupe left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution!
I have commented upon some issues that should, in my opinion, be addressed before merging.
So far I have only read the code, a second review concerned with performance will follow.
Please also address the Codecov report.

*
* Copyright (c) 2019, the Alpha Team.
*/
public class HeapOfRelatedChoiceAtoms extends HeapOfActiveAtoms {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this an improved version of, and thus a replacement for HeapOfActiveChoicePoints? If yes, this fact should be documented and HeapOfActiveChoicePoints should be deprecated or removed.

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 main reason for this class to exists is the initialization of variables. In HeapOfActiveAtoms a new nogood leads to activities of literals occuring in the nogood to be updated, while here, not the literals themselves are updated, but the related choice atoms of those literals occurring in the nogood. This seems to be much more in line with the idea of having good values for choice atoms (and not the "useless" ordinary atoms).

Note that HeapOfActiveChoicePoints works in a different direction, namely by referring to related atoms when activities are incremented. For that class, atoms are related whenever they appear in the same nogood. The VSIDSWithPhaseSaving heuristic, however, uses the knowledge of atom relationships that it obtains from the grounder via the AtomChoiceRelation. (I currently do however not remember whether the obtained information in both cases is the same or different. The information flow in VSIDSWithPhaseSaving and HeapOfRelatedChoiceAtoms seems to be more direct.)

I think, it is worthwhile to consider merging both approaches. If I recall correctly, I did not do it, because there were some differences and I did not want to change all the other heuristics we have so far without any discussion.

for (Integer relatedChoiceAtom : atomChoiceRelation.getRelatedChoiceAtoms(atomOf(literal))) {
if (!incrementedActivityScores[relatedChoiceAtom]) { // update initial value as long as not incremented yet by VSIDS
double score = moms.getScore(relatedChoiceAtom);
if (score > 0.0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please re-use the existing code in at.ac.tuwien.kr.alpha.solver.heuristics.HeapOfActiveAtoms#initActivityMOMs instead of just copying it.

@@ -0,0 +1,226 @@
/**
* Copyright (c) 2018-2019 Siemens AG
Copy link
Collaborator

Choose a reason for hiding this comment

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

In my opinion, this implementation is independent from VSIDS enough for the copyright attribution to Siemens not to be necessary.

- Extend Util.join with toString method parameter.
- Change initial phase values from strings to enum.
- Add PhaseInitializer for RULESTRUEATOMSFALSE.
Copy link
Collaborator

@rtaupe rtaupe left a comment

Choose a reason for hiding this comment

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

Some more change requests.
One of them (the NullPointerException) is critical!

.desc("enable the usage of (dynamic and static) restarts (default: "
+ SystemConfig.DEFAULT_ENABLE_RESTARTS + ")")
.build();
private static final Option OPT_INITIAL_PHASE = Option.builder("ph").longOpt("initialPhase").hasArg(true).argName("initializer")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this option is only meaningful if the VSIDS_PHASE_SAVING heuristic is used, a warning should be issued if it is used in conjunction with any other heuristic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a good point and touches on a larger issue: what we would need is to check whether the whole set of given options actually makes sense. For the time being, I'll change the description so that it becomes clear that this only works for the VSIDS_WITH_PHASE_SAVING heuristic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added to issue #302 as a condition to check eventually.

@rtaupe
Copy link
Collaborator

rtaupe commented May 26, 2020

There is a bug: #255
(I don´t know if it is related to this pull request, but it occurs on this branch.)

# Conflicts:
#	src/main/java/at/ac/tuwien/kr/alpha/AnswerSetToXlsxWriter.java
#	src/main/java/at/ac/tuwien/kr/alpha/Main.java
#	src/main/java/at/ac/tuwien/kr/alpha/api/mapper/AnswerSetToWorkbookMapper.java
#	src/main/java/at/ac/tuwien/kr/alpha/config/CommandLineParser.java
#	src/main/java/at/ac/tuwien/kr/alpha/config/InputConfig.java
#	src/main/java/at/ac/tuwien/kr/alpha/config/SystemConfig.java
#	src/main/java/at/ac/tuwien/kr/alpha/grounder/NaiveGrounder.java
#	src/main/java/at/ac/tuwien/kr/alpha/grounder/NoGoodGenerator.java
#	src/main/java/at/ac/tuwien/kr/alpha/grounder/RuleGroundingOrders.java
#	src/main/java/at/ac/tuwien/kr/alpha/grounder/transformation/CardinalityNormalization.java
#	src/test/java/at/ac/tuwien/kr/alpha/AnswerSetToXlsxWriterTest.java
#	src/test/java/at/ac/tuwien/kr/alpha/api/AlphaTest.java
#	src/test/java/at/ac/tuwien/kr/alpha/grounder/DummyGrounder.java
#	src/test/java/at/ac/tuwien/kr/alpha/grounder/NaiveGrounderTest.java
#	src/test/java/at/ac/tuwien/kr/alpha/grounder/RuleGroundingOrderTest.java
#	src/test/java/at/ac/tuwien/kr/alpha/solver/LearnedNoGoodDeletionTest.java
- Introduced AbstractVSIDS, bundling code common to all VSIDS implementations.
- VSIDS refactored and extends AbstractVSIDS now.
- VSIDSWithPhaseSaving refactored and extends AbstractVSIDS now.
# Conflicts:
#	alpha-api/src/main/java/at/ac/tuwien/kr/alpha/api/config/SystemConfig.java
#	alpha-cli-app/src/main/java/at/ac/tuwien/kr/alpha/app/config/CommandLineParser.java
#	alpha-cli-app/src/test/java/at/ac/tuwien/kr/alpha/app/config/CommandLineParserTest.java
#	alpha-cli-app/src/test/java/at/ac/tuwien/kr/alpha/app/mappers/AnswerSetToWorkbookMapperTest.java
#	alpha-commons/src/main/java/at/ac/tuwien/kr/alpha/commons/literals/ComparisonLiteralImpl.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/common/NoGood.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/grounder/ChoiceRecorder.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/grounder/Grounder.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/grounder/NaiveGrounder.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/grounder/NoGoodGenerator.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/programs/structure/AtomChoiceRelation.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/DefaultSolver.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/MixedRestartStrategy.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/NaiveNoGoodStore.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/NoGoodCounter.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/PerformanceLog.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/SolverFactory.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/TrailAssignment.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/heuristics/AbstractVSIDS.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/heuristics/BranchingHeuristicFactory.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/heuristics/ChainedBranchingHeuristics.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/heuristics/HeapOfActiveAtoms.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/heuristics/HeapOfRelatedChoiceAtoms.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/heuristics/PhaseInitializerFactory.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/heuristics/VSIDS.java
#	alpha-core/src/main/java/at/ac/tuwien/kr/alpha/core/solver/heuristics/VSIDSWithPhaseSaving.java
#	alpha-core/src/test/java/at/ac/tuwien/kr/alpha/core/grounder/ChoiceGrounder.java
#	alpha-core/src/test/java/at/ac/tuwien/kr/alpha/core/grounder/DummyGrounder.java
- Extract InitialAtomPhase from PhaseInitializerFactory.
- Fix missing/wrong imports.
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