Skip to content

Commit d3e2527

Browse files
move to generic state
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent a74153f commit d3e2527

File tree

2 files changed

+78
-63
lines changed

2 files changed

+78
-63
lines changed

src/smt/smt_parallel.cpp

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,14 @@ namespace smt {
7070
lbool r = l_undef;
7171
try {
7272
r = ctx->check();
73-
} catch (z3_error &err) {
73+
}
74+
catch (z3_error &err) {
7475
b.set_exception(err.error_code());
75-
} catch (z3_exception &ex) {
76+
}
77+
catch (z3_exception &ex) {
7678
b.set_exception(ex.what());
77-
} catch (...) {
79+
}
80+
catch (...) {
7881
b.set_exception("unknown exception");
7982
}
8083
return r;
@@ -130,6 +133,52 @@ namespace smt {
130133
return best_param_state_idx;
131134
}
132135

136+
void parallel::param_generator::init_param_state() {
137+
// param_descrs smt_desc;
138+
// smt_params_helper::collect_param_descrs(smt_desc);
139+
smt_params_helper smtp(m_p);
140+
m_my_param_state.insert(symbol("smt.arith.nl.branching"), smtp.arith_nl_branching());
141+
m_my_param_state.insert(symbol("smt.arith.nl.cross_nested"), smtp.arith_nl_cross_nested());
142+
m_my_param_state.insert(symbol("smt.arith.nl.delay"), smtp.arith_nl_delay());
143+
m_my_param_state.insert(symbol("smt.arith.nl.expensive_patching"), smtp.arith_nl_expensive_patching());
144+
m_my_param_state.insert(symbol("smt.arith.nl.gb"), smtp.arith_nl_gb());
145+
m_my_param_state.insert(symbol("smt.arith.nl.horner"), smtp.arith_nl_horner());
146+
m_my_param_state.insert(symbol("smt.arith.nl.horner_frequency"), smtp.arith_nl_horner_frequency());
147+
m_my_param_state.insert(symbol("smt.arith.nl.optimize_bounds"), smtp.arith_nl_optimize_bounds());
148+
m_my_param_state.insert(symbol("smt.arith.nl.propagate_linear_monomials"), smtp.arith_nl_propagate_linear_monomials());
149+
m_my_param_state.insert(symbol("smt.arith.nl.tangents"), smtp.arith_nl_tangents());
150+
};
151+
152+
// TODO: this should mutate only one field at a time an mutate it based on m_my_param_state to keep it generic.
153+
154+
smt_params parallel::param_generator::mutate_param_state() {
155+
smt_params p = m_param_state;
156+
random_gen m_rand;
157+
158+
auto flip_bool = [&](bool &x) {
159+
if (m_rand(2) == 0)
160+
x = !x;
161+
};
162+
163+
auto mutate_uint = [&](unsigned &x, unsigned lo, unsigned hi) {
164+
if ((m_rand() % 2) == 0)
165+
x = lo + (m_rand((hi - lo + 1)));
166+
};
167+
168+
flip_bool(p.m_nl_arith_branching);
169+
flip_bool(p.m_nl_arith_cross_nested);
170+
mutate_uint(p.m_nl_arith_delay, 5, 20);
171+
flip_bool(p.m_nl_arith_expensive_patching);
172+
flip_bool(p.m_nl_arith_gb);
173+
flip_bool(p.m_nl_arith_horner);
174+
mutate_uint(p.m_nl_arith_horner_frequency, 2, 6);
175+
flip_bool(p.m_nl_arith_optimize_bounds);
176+
flip_bool(p.m_nl_arith_propagate_linear_monomials);
177+
flip_bool(p.m_nl_arith_tangents);
178+
179+
return p;
180+
}
181+
133182
void parallel::param_generator::protocol_iteration() {
134183
IF_VERBOSE(1, verbose_stream() << " PARAM TUNER running protocol iteration\n");
135184
ctx->get_fparams().m_max_conflicts = m_max_prefix_conflicts;
@@ -144,6 +193,8 @@ namespace smt {
144193

145194
switch (r) {
146195
case l_undef: {
196+
// TODO, change from smt_params to a generic param state representation based on params_ref
197+
// only params_ref have effect on updates.
147198
smt_params best_param_state = m_param_state;
148199
vector<smt_params> candidate_param_states;
149200

src/smt/smt_parallel.h

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Revision History:
2020

2121
#include "smt/smt_context.h"
2222
#include "util/search_tree.h"
23+
#include <variant>
2324
// #include "util/util.h"
2425
#include <thread>
2526
#include <mutex>
@@ -127,74 +128,37 @@ namespace smt {
127128
// 4. update current configuration with the winner
128129

129130
class param_generator {
130-
parallel& p;
131-
batch_manager& b;
131+
parallel &p;
132+
batch_manager &b;
132133
ast_manager m;
133134
scoped_ptr<context> ctx;
134135
ast_translation m_l2g;
135-
136-
unsigned N = 4; // number of prefix permutations to test (including current)
136+
137+
unsigned N = 4; // number of prefix permutations to test (including current)
137138
unsigned m_max_prefix_conflicts = 1000;
138-
139+
139140
scoped_ptr<context> m_prefix_solver;
140141
scoped_ptr_vector<context> m_param_probe_contexts;
141142
smt_params m_param_state;
142143
params_ref m_p;
143-
144-
private:
145-
void init_param_state() {
146-
m_param_state.m_nl_arith_branching = true;
147-
m_param_state.m_nl_arith_cross_nested = true;
148-
m_param_state.m_nl_arith_delay = 10;
149-
m_param_state.m_nl_arith_expensive_patching = false;
150-
m_param_state.m_nl_arith_gb = true;
151-
m_param_state.m_nl_arith_horner = true;
152-
m_param_state.m_nl_arith_horner_frequency = 4;
153-
m_param_state.m_nl_arith_optimize_bounds = true;
154-
m_param_state.m_nl_arith_propagate_linear_monomials = true;
155-
m_param_state.m_nl_arith_tangents = true;
156-
157-
m_param_state.updt_params(m_p);
158-
ctx->updt_params(m_p);
159-
};
160-
161-
smt_params mutate_param_state() {
162-
smt_params p = m_param_state;
163-
random_gen m_rand;
164-
165-
auto flip_bool = [&](bool &x) {
166-
if ((m_rand() % 2) == 0)
167-
x = !x;
168-
};
169-
170-
auto mutate_uint = [&](unsigned &x, unsigned lo, unsigned hi) {
171-
if ((m_rand() % 2) == 0)
172-
x = lo + (m_rand() % (hi - lo + 1));
173-
};
174-
175-
flip_bool(p.m_nl_arith_branching);
176-
flip_bool(p.m_nl_arith_cross_nested);
177-
mutate_uint(p.m_nl_arith_delay, 5, 20);
178-
flip_bool(p.m_nl_arith_expensive_patching);
179-
flip_bool(p.m_nl_arith_gb);
180-
flip_bool(p.m_nl_arith_horner);
181-
mutate_uint(p.m_nl_arith_horner_frequency, 2, 6);
182-
flip_bool(p.m_nl_arith_optimize_bounds);
183-
flip_bool(p.m_nl_arith_propagate_linear_monomials);
184-
flip_bool(p.m_nl_arith_tangents);
185-
186-
return p;
187-
}
188-
189-
public:
190-
param_generator(parallel& p);
191-
lbool run_prefix_step();
192-
void protocol_iteration();
193-
unsigned replay_proof_prefixes(vector<smt_params> candidate_param_states, unsigned max_conflicts_epsilon);
194-
195-
reslimit& limit() {
196-
return m.limit();
197-
}
144+
145+
using param_value = std::variant<unsigned, bool, double>;
146+
symbol_table<param_value> m_my_param_state;
147+
148+
private:
149+
void init_param_state();
150+
151+
smt_params mutate_param_state();
152+
153+
public:
154+
param_generator(parallel &p);
155+
lbool run_prefix_step();
156+
void protocol_iteration();
157+
unsigned replay_proof_prefixes(vector<smt_params> candidate_param_states, unsigned max_conflicts_epsilon);
158+
159+
reslimit &limit() {
160+
return m.limit();
161+
}
198162
};
199163

200164
class worker {

0 commit comments

Comments
 (0)