Work towards supporting multiple solvers running in parallel.
There are now only 5 remaining internal calls to smt::currentSmtEngine.
More will be eliminated on future PRs.
#include "preprocessing/assertion_pipeline.h"
#include "preprocessing/preprocessing_pass_context.h"
#include "smt/dump_manager.h"
-#include "smt/smt_engine_scope.h"
#include "theory/rewriter.h"
#include "theory/sort_inference.h"
#include "theory/theory_engine.h"
assertionsToPreprocess->push_back(nar);
}
// indicate correspondence between the functions
- SmtEngine* smt = smt::currentSmtEngine();
+ SmtEngine* smt = d_preprocContext->getSmt();
smt::DumpManager* dm = smt->getDumpManager();
for (const std::pair<const Node, Node>& mrf : model_replace_f)
{
its = d_sampler[a].find(tn);
}
// check equivalent
- its->second.checkEquivalent(bv, bvr);
+ its->second.checkEquivalent(bv, bvr, *d_state.options().base.out);
}
}
namespace theory {
namespace quantifiers {
-CandidateRewriteDatabase::CandidateRewriteDatabase(bool doCheck,
- bool rewAccel,
- bool silent,
- bool filterPairs)
- : d_tds(nullptr),
+CandidateRewriteDatabase::CandidateRewriteDatabase(
+ Env& env, bool doCheck, bool rewAccel, bool silent, bool filterPairs)
+ : ExprMiner(env),
+ d_tds(nullptr),
d_ext_rewrite(nullptr),
d_doCheck(doCheck),
d_rewAccel(rewAccel),
public:
/**
* Constructor
+ * @param env Reference to the environment
* @param doCheck Whether to check rewrite rules using subsolvers.
* @param rewAccel Whether to construct symmetry breaking lemmas based on
* discovered rewrites (see option sygusRewSynthAccel()).
* @param filterPairs Whether to filter rewrite pairs using filtering
* techniques from the SAT 2019 paper above.
*/
- CandidateRewriteDatabase(bool doCheck,
+ CandidateRewriteDatabase(Env& env,
+ bool doCheck,
bool rewAccel = false,
bool silent = false,
bool filterPairs = true);
#include "expr/skolem_manager.h"
#include "options/quantifiers_options.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
#include "theory/quantifiers/term_util.h"
#include "theory/rewriter.h"
-#include "theory/smt_engine_subsolver.h"
using namespace std;
using namespace cvc5::kind;
#include <vector>
#include "expr/node.h"
-#include "smt/smt_engine.h"
#include "theory/quantifiers/sygus_sampler.h"
+#include "theory/smt_engine_subsolver.h"
namespace cvc5 {
+
+class Env;
+class SmtEngine;
+
namespace theory {
namespace quantifiers {
class ExprMiner
{
public:
- ExprMiner() : d_sampler(nullptr) {}
+ ExprMiner(Env& env) : d_env(env), d_sampler(nullptr) {}
virtual ~ExprMiner() {}
/** initialize
*
virtual bool addTerm(Node n, std::ostream& out) = 0;
protected:
+ /** Reference to the env */
+ Env& d_env;
/** the set of variables used by this class */
std::vector<Node> d_vars;
/**
namespace theory {
namespace quantifiers {
-ExpressionMinerManager::ExpressionMinerManager()
- : d_doRewSynth(false),
+ExpressionMinerManager::ExpressionMinerManager(Env& env)
+ : d_env(env),
+ d_doRewSynth(false),
d_doQueryGen(false),
d_doFilterLogicalStrength(false),
d_use_sygus_type(false),
d_tds(nullptr),
- d_crd(options::sygusRewSynthCheck(), options::sygusRewSynthAccel(), false)
+ d_crd(env,
+ options::sygusRewSynthCheck(),
+ options::sygusRewSynthAccel(),
+ false),
+ d_qg(env),
+ d_sols(env)
{
}
#include "theory/quantifiers/sygus_sampler.h"
namespace cvc5 {
-namespace theory {
-class QuantifiersEngine;
+class Env;
+namespace theory {
namespace quantifiers {
/** ExpressionMinerManager
class ExpressionMinerManager
{
public:
- ExpressionMinerManager();
+ ExpressionMinerManager(Env& env);
~ExpressionMinerManager() {}
/** Initialize this class
*
bool addTerm(Node sol, std::ostream& out, bool& rew_print);
private:
+ /** Reference to the env */
+ Env& d_env;
/** whether we are doing rewrite synthesis */
bool d_doRewSynth;
/** whether we are doing query generation */
#include "proof/lazy_proof.h"
#include "proof/proof_node_manager.h"
#include "smt/logic_exception.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
#include "smt/smt_statistics_registry.h"
#include "theory/quantifiers/cegqi/inst_strategy_cegqi.h"
#include "theory/quantifiers/first_order_model.h"
#include <sstream>
#include "options/quantifiers_options.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
#include "util/random.h"
using namespace std;
namespace theory {
namespace quantifiers {
-QueryGenerator::QueryGenerator() : d_queryCount(0) {}
+QueryGenerator::QueryGenerator(Env& env) : ExprMiner(env), d_queryCount(0) {}
void QueryGenerator::initialize(const std::vector<Node>& vars, SygusSampler* ss)
{
Assert(ss != nullptr);
class QueryGenerator : public ExprMiner
{
public:
- QueryGenerator();
+ QueryGenerator(Env& env);
~QueryGenerator() {}
/** initialize */
void initialize(const std::vector<Node>& vars,
#include "options/base_options.h"
#include "options/quantifiers_options.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
#include "util/random.h"
using namespace cvc5::kind;
namespace theory {
namespace quantifiers {
-SolutionFilterStrength::SolutionFilterStrength() : d_isStrong(true) {}
+SolutionFilterStrength::SolutionFilterStrength(Env& env)
+ : ExprMiner(env), d_isStrong(true)
+{
+}
void SolutionFilterStrength::initialize(const std::vector<Node>& vars,
SygusSampler* ss)
{
}
else
{
- Options& opts = smt::currentSmtEngine()->getOptions();
+ const Options& opts = d_env.getOptions();
std::ostream* smtOut = opts.base.out;
(*smtOut) << "; (filtered " << (d_isStrong ? s : s.negate()) << ")"
<< std::endl;
class SolutionFilterStrength : public ExprMiner
{
public:
- SolutionFilterStrength();
+ SolutionFilterStrength(Env& d_env);
~SolutionFilterStrength() {}
/** initialize */
void initialize(const std::vector<Node>& vars,
#include "expr/skolem_manager.h"
#include "options/quantifiers_options.h"
#include "smt/logic_exception.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
#include "smt/smt_statistics_registry.h"
#include "theory/arith/arith_msum.h"
#include "theory/quantifiers/quantifiers_attributes.h"
namespace theory {
namespace quantifiers {
-CegSingleInv::CegSingleInv(TermRegistry& tr, SygusStatistics& s)
+CegSingleInv::CegSingleInv(Env& env, TermRegistry& tr, SygusStatistics& s)
: d_sip(new SingleInvocationPartition),
- d_srcons(new SygusReconstruct(tr.getTermDatabaseSygus(), s)),
+ d_srcons(new SygusReconstruct(env, tr.getTermDatabaseSygus(), s)),
d_isSolved(false),
d_single_invocation(false),
d_treg(tr)
Node d_single_inv;
public:
- CegSingleInv(TermRegistry& tr, SygusStatistics& s);
+ CegSingleInv(Env& env, TermRegistry& tr, SygusStatistics& s);
~CegSingleInv();
// get simplified conjecture
#include "options/base_options.h"
#include "printer/printer.h"
#include "proof/unsat_core.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
#include "theory/datatypes/theory_datatypes_utils.h"
#include "theory/quantifiers/sygus/ce_guided_single_inv.h"
#include "theory/quantifiers/sygus/transition_inference.h"
*/
#include "theory/quantifiers/sygus/enum_value_manager.h"
+#include "options/base_options.h"
#include "options/datatypes_options.h"
#include "options/quantifiers_options.h"
#include "theory/datatypes/sygus_datatype_utils.h"
namespace quantifiers {
EnumValueManager::EnumValueManager(Node e,
+ QuantifiersState& qs,
QuantifiersInferenceManager& qim,
TermRegistry& tr,
SygusStatistics& s,
bool hasExamples)
: d_enum(e),
+ d_qstate(qs),
d_qim(qim),
d_treg(tr),
d_stats(s),
// create the enumerator callback
if (options::sygusSymBreakDynamic())
{
+ std::ostream* out = nullptr;
if (options::sygusRewVerify())
{
d_samplerRrV.reset(new SygusSampler);
d_samplerRrV->initializeSygus(
d_tds, e, options::sygusSamples(), false);
+ // use the default output for the output of sygusRewVerify
+ out = d_qstate.options().base.out;
}
d_secd.reset(new SygusEnumeratorCallbackDefault(
- e, &d_stats, d_eec.get(), d_samplerRrV.get()));
+ e, &d_stats, d_eec.get(), d_samplerRrV.get(), out));
}
// if sygus repair const is enabled, we enumerate terms with free
// variables as arguments to any-constant constructors
{
public:
EnumValueManager(Node e,
+ QuantifiersState& qs,
QuantifiersInferenceManager& qim,
TermRegistry& tr,
SygusStatistics& s,
Node getModelValue(Node n);
/** The enumerator */
Node d_enum;
+ /** Reference to the quantifiers state */
+ QuantifiersState& d_qstate;
/** Reference to the quantifiers inference manager */
QuantifiersInferenceManager& d_qim;
/** Reference to the term registry */
namespace theory {
namespace quantifiers {
-void RConsTypeInfo::initialize(TermDbSygus* tds,
+void RConsTypeInfo::initialize(Env& env,
+ TermDbSygus* tds,
SygusStatistics& s,
TypeNode stn,
const std::vector<Node>& builtinVars)
d_enumerator.reset(new SygusEnumerator(tds, nullptr, &s, true));
d_enumerator->initialize(sm->mkDummySkolem("sygus_rcons", stn));
- d_crd.reset(new CandidateRewriteDatabase(true, false, true, false));
+ d_crd.reset(new CandidateRewriteDatabase(env, true, false, true, false));
// since initial samples are not always useful for equivalence checks, set
// their number to 0
d_sygusSampler.initialize(stn, builtinVars, 0);
* Initialize a sygus enumerator and a candidate rewrite database for this
* class' sygus datatype type.
*
+ * @param env Reference to the environment
* @param tds Database for sygus terms
* @param s Statistics managed for the synth engine
* @param stn The sygus datatype type encoding the syntax restrictions
* @param builtinVars A list containing the builtin analog of sygus variable
* list for the sygus datatype type
*/
- void initialize(TermDbSygus* tds,
+ void initialize(Env& env,
+ TermDbSygus* tds,
SygusStatistics& s,
TypeNode stn,
const std::vector<Node>& builtinVars);
}
SygusEnumeratorCallbackDefault::SygusEnumeratorCallbackDefault(
- Node e, SygusStatistics* s, ExampleEvalCache* eec, SygusSampler* ssrv)
- : SygusEnumeratorCallback(e, s), d_eec(eec), d_samplerRrV(ssrv)
+ Node e,
+ SygusStatistics* s,
+ ExampleEvalCache* eec,
+ SygusSampler* ssrv,
+ std::ostream* out)
+ : SygusEnumeratorCallback(e, s), d_eec(eec), d_samplerRrV(ssrv), d_out(out)
{
}
void SygusEnumeratorCallbackDefault::notifyTermInternal(Node n,
{
if (d_samplerRrV != nullptr)
{
- d_samplerRrV->checkEquivalent(bn, bnr);
+ Assert(d_out != nullptr);
+ d_samplerRrV->checkEquivalent(bn, bnr, *d_out);
}
}
SygusEnumeratorCallbackDefault(Node e,
SygusStatistics* s = nullptr,
ExampleEvalCache* eec = nullptr,
- SygusSampler* ssrv = nullptr);
+ SygusSampler* ssrv = nullptr,
+ std::ostream* out = nullptr);
virtual ~SygusEnumeratorCallbackDefault() {}
protected:
ExampleEvalCache* d_eec;
/** sampler (for --sygus-rr-verify) */
SygusSampler* d_samplerRrV;
+ /** The output stream to print unsound rewrites for above */
+ std::ostream* d_out;
};
} // namespace quantifiers
#include "expr/dtype_cons.h"
#include "expr/node_manager_attributes.h" // for VarNameAttr
#include "options/quantifiers_options.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
#include "theory/datatypes/theory_datatypes_utils.h"
#include "theory/quantifiers/cegqi/ceg_instantiator.h"
#include "theory/quantifiers/sygus/sygus_grammar_cons.h"
#include "expr/node.h"
#include "expr/type_node.h"
-#include "smt/smt_engine.h"
namespace cvc5 {
+
+class SmtEngine;
+
namespace theory {
namespace quantifiers {
/**
namespace theory {
namespace quantifiers {
-SygusReconstruct::SygusReconstruct(TermDbSygus* tds, SygusStatistics& s)
- : d_tds(tds), d_stats(s)
+SygusReconstruct::SygusReconstruct(Env& env,
+ TermDbSygus* tds,
+ SygusStatistics& s)
+ : d_env(env), d_tds(tds), d_stats(s)
{
}
// the database.
for (TypeNode tn : sfTypes)
{
- d_stnInfo[tn].initialize(d_tds, d_stats, tn, builtinVars);
+ d_stnInfo[tn].initialize(d_env, d_tds, d_stats, tn, builtinVars);
}
}
/**
* Constructor.
*
+ * @param env reference to the environment
* @param tds database for sygus terms
* @param s statistics managed for the synth engine
*/
- SygusReconstruct(TermDbSygus* tds, SygusStatistics& s);
+ SygusReconstruct(Env& env, TermDbSygus* tds, SygusStatistics& s);
/** Reconstruct solution.
*
void printPool(
const std::unordered_map<TypeNode, std::vector<Node>>& pool) const;
+ /** Reference to the env */
+ Env& d_env;
/** pointer to the sygus term database */
TermDbSygus* d_tds;
/** reference to the statistics of parent */
#include "options/base_options.h"
#include "options/quantifiers_options.h"
#include "printer/printer.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
-#include "smt/smt_statistics_registry.h"
#include "theory/datatypes/theory_datatypes_utils.h"
#include "theory/logic_info.h"
#include "theory/quantifiers/cegqi/ceg_instantiator.h"
namespace theory {
namespace quantifiers {
-SygusRepairConst::SygusRepairConst(TermDbSygus* tds)
- : d_tds(tds), d_allow_constant_grammar(false)
+SygusRepairConst::SygusRepairConst(Env& env, TermDbSygus* tds)
+ : d_env(env), d_tds(tds), d_allow_constant_grammar(false)
{
}
// check whether it is not in the current logic, e.g. non-linear arithmetic.
// if so, undo replacements until it is in the current logic.
- LogicInfo logic = smt::currentSmtEngine()->getLogicInfo();
+ const LogicInfo& logic = d_env.getLogicInfo();
if (logic.isTheoryEnabled(THEORY_ARITH) && logic.isLinear())
{
fo_body = fitToLogic(sygusBody,
}
Node SygusRepairConst::fitToLogic(Node body,
- LogicInfo& logic,
+ const LogicInfo& logic,
Node n,
const std::vector<Node>& candidates,
std::vector<Node>& candidate_skeletons,
return Node::null();
}
-bool SygusRepairConst::getFitToLogicExcludeVar(LogicInfo& logic,
+bool SygusRepairConst::getFitToLogicExcludeVar(const LogicInfo& logic,
Node n,
Node& exvar)
{
namespace cvc5 {
+class Env;
class LogicInfo;
namespace theory {
class SygusRepairConst
{
public:
- SygusRepairConst(TermDbSygus* tds);
+ SygusRepairConst(Env& env, TermDbSygus* tds);
~SygusRepairConst() {}
/** initialize
*
static bool mustRepair(Node n);
private:
+ /** Reference to the env */
+ Env& d_env;
/** pointer to the sygus term database of d_qe */
TermDbSygus* d_tds;
/**
* sk_vars.
*/
Node fitToLogic(Node body,
- LogicInfo& logic,
+ const LogicInfo& logic,
Node n,
const std::vector<Node>& candidates,
std::vector<Node>& candidate_skeletons,
* exvar to x.
* If n is in the given logic, this method returns true.
*/
- bool getFitToLogicExcludeVar(LogicInfo& logic, Node n, Node& exvar);
+ bool getFitToLogicExcludeVar(const LogicInfo& logic, Node n, Node& exvar);
};
} // namespace quantifiers
#include "options/quantifiers_options.h"
#include "printer/printer.h"
#include "smt/logic_exception.h"
-#include "smt/smt_engine_scope.h"
#include "smt/smt_statistics_registry.h"
#include "theory/datatypes/sygus_datatype_utils.h"
#include "theory/quantifiers/first_order_model.h"
d_treg(tr),
d_stats(s),
d_tds(tr.getTermDatabaseSygus()),
- d_verify(d_tds),
+ d_verify(qs.options(), d_tds),
d_hasSolution(false),
- d_ceg_si(new CegSingleInv(tr, s)),
+ d_ceg_si(new CegSingleInv(qs.getEnv(), tr, s)),
d_templInfer(new SygusTemplateInfer),
d_ceg_proc(new SynthConjectureProcess),
d_ceg_gc(new CegGrammarConstructor(d_tds, this)),
- d_sygus_rconst(new SygusRepairConst(d_tds)),
+ d_sygus_rconst(new SygusRepairConst(qs.getEnv(), d_tds)),
d_exampleInfer(new ExampleInfer(d_tds)),
d_ceg_pbe(new SygusPbe(qim, d_tds, this)),
d_ceg_cegis(new Cegis(qim, d_tds, this)),
{
if (printDebug)
{
- Options& sopts = smt::currentSmtEngine()->getOptions();
+ const Options& sopts = d_qstate.options();
std::ostream& out = *sopts.base.out;
out << "(sygus-candidate ";
Assert(d_quant[0].getNumChildren() == candidate_values.size());
bool hasExamples = (d_exampleInfer->hasExamples(f)
&& d_exampleInfer->getNumExamples(f) != 0);
d_enumManager[e].reset(
- new EnumValueManager(e, d_qim, d_treg, d_stats, hasExamples));
+ new EnumValueManager(e, d_qstate, d_qim, d_treg, d_stats, hasExamples));
EnumValueManager* eman = d_enumManager[e].get();
// set up the examples
if (hasExamples)
Assert(d_master != nullptr);
// we have generated a solution, print it
// get the current output stream
- Options& sopts = smt::currentSmtEngine()->getOptions();
+ const Options& sopts = d_qstate.options();
printSynthSolutionInternal(*sopts.base.out);
excludeCurrentSolution(enums, values);
}
!= options::SygusFilterSolMode::NONE))
{
Trace("cegqi-sol-debug") << "Run expression mining..." << std::endl;
- std::map<Node, ExpressionMinerManager>::iterator its =
+ std::map<Node, std::unique_ptr<ExpressionMinerManager>>::iterator its =
d_exprm.find(prog);
if (its == d_exprm.end())
{
- d_exprm[prog].initializeSygus(
+ d_exprm[prog].reset(new ExpressionMinerManager(d_qstate.getEnv()));
+ ExpressionMinerManager* emm = d_exprm[prog].get();
+ emm->initializeSygus(
d_tds, d_candidates[i], options::sygusSamples(), true);
if (options::sygusRewSynth())
{
- d_exprm[prog].enableRewriteRuleSynth();
+ emm->enableRewriteRuleSynth();
}
if (options::sygusQueryGen())
{
- d_exprm[prog].enableQueryGeneration(options::sygusQueryGenThresh());
+ emm->enableQueryGeneration(options::sygusQueryGenThresh());
}
if (options::sygusFilterSolMode()
!= options::SygusFilterSolMode::NONE)
if (options::sygusFilterSolMode()
== options::SygusFilterSolMode::STRONG)
{
- d_exprm[prog].enableFilterStrongSolutions();
+ emm->enableFilterStrongSolutions();
}
else if (options::sygusFilterSolMode()
== options::SygusFilterSolMode::WEAK)
{
- d_exprm[prog].enableFilterWeakSolutions();
+ emm->enableFilterWeakSolutions();
}
}
its = d_exprm.find(prog);
}
bool rew_print = false;
- is_unique_term = d_exprm[prog].addTerm(sol, out, rew_print);
+ is_unique_term = its->second->addTerm(sol, out, rew_print);
if (rew_print)
{
++(d_stats.d_candidate_rewrites_print);
* This is used for the sygusRewSynth() option to synthesize new candidate
* rewrite rules.
*/
- std::map<Node, ExpressionMinerManager> d_exprm;
+ std::map<Node, std::unique_ptr<ExpressionMinerManager>> d_exprm;
};
} // namespace quantifiers
#include "options/arith_options.h"
#include "options/base_options.h"
#include "options/quantifiers_options.h"
-#include "smt/smt_engine_scope.h"
#include "smt/smt_statistics_registry.h"
#include "theory/quantifiers/first_order_model.h"
#include "theory/quantifiers/sygus/term_database_sygus.h"
namespace theory {
namespace quantifiers {
-SynthVerify::SynthVerify(TermDbSygus* tds) : d_tds(tds)
+SynthVerify::SynthVerify(const Options& opts, TermDbSygus* tds) : d_tds(tds)
{
// determine the options to use for the verification subsolvers we spawn
- // we start with the options of the current SmtEngine
- SmtEngine* smtCurr = smt::currentSmtEngine();
- d_subOptions.copyValues(smtCurr->getOptions());
+ // we start with the provided options
+ d_subOptions.copyValues(opts);
// limit the number of instantiation rounds on subcalls
d_subOptions.quantifiers.instMaxRounds =
d_subOptions.quantifiers.sygusVerifyInstMaxRounds;
class SynthVerify
{
public:
- SynthVerify(TermDbSygus* tds);
+ SynthVerify(const Options& opts, TermDbSygus* tds);
~SynthVerify();
/**
* Verification call, which takes into account specific aspects of the
#include "options/base_options.h"
#include "options/quantifiers_options.h"
#include "printer/printer.h"
-#include "smt/smt_engine.h"
-#include "smt/smt_engine_scope.h"
#include "theory/quantifiers/lazy_trie.h"
#include "theory/rewriter.h"
#include "util/bitvector.h"
}
}
-void SygusSampler::checkEquivalent(Node bv, Node bvr)
+void SygusSampler::checkEquivalent(Node bv, Node bvr, std::ostream& out)
{
if (bv == bvr)
{
return;
}
// we have detected unsoundness in the rewriter
- Options& sopts = smt::currentSmtEngine()->getOptions();
- std::ostream* out = sopts.base.out;
- (*out) << "(unsound-rewrite " << bv << " " << bvr << ")" << std::endl;
+ out << "(unsound-rewrite " << bv << " " << bvr << ")" << std::endl;
// debugging information
- (*out) << "Terms are not equivalent for : " << std::endl;
- (*out) << ptOut.str();
+ out << "Terms are not equivalent for : " << std::endl;
+ out << ptOut.str();
Assert(bve != bvre);
- (*out) << "where they evaluate to " << bve << " and " << bvre << std::endl;
+ out << "where they evaluate to " << bve << " and " << bvre << std::endl;
if (options::sygusRewVerifyAbort())
{
*
* Check whether bv and bvr are equivalent on all sample points, print
* an error if not. Used with --sygus-rr-verify.
+ *
+ * @param bv The original term
+ * @param bvr The rewritten form of bvr
+ * @param out The output stream to write if the rewrite was unsound.
*/
- void checkEquivalent(Node bv, Node bvr);
+ void checkEquivalent(Node bv, Node bvr, std::ostream& out);
protected:
/** sygus term database of d_qe */
#include "options/smt_options.h"
#include "options/strings_options.h"
#include "options/uf_options.h"
-#include "smt/smt_engine_scope.h"
#include "theory/quantifiers/equality_query.h"
#include "theory/quantifiers/first_order_model.h"
#include "theory/quantifiers/fmf/first_order_model_fmc.h"