Python z3.Bool() Examples
The following are 9
code examples of z3.Bool().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
z3
, or try the search function
.
Example #1
Source File: nodes.py From f-ing-around-with-binaryninja with MIT License | 6 votes |
def __init__( self, ast: mlil_ast.MediumLevelILAst, condition: Bool, condition_il: MediumLevelILInstruction, true: MediumLevelILAstNode, false: MediumLevelILAstNode = None, ): if condition is None: raise NotImplementedError("condition should not be None") self._condition = condition super().__init__(ast) self._type = "cond" self._condition_il = condition_il self._true = true self._false = false self._flatten_conditions()
Example #2
Source File: hoare_opt.py From qiskit-terra with Apache License 2.0 | 5 votes |
def _gen_variable(self, qb_id): """ After each gate generate a new unique variable name for each of the qubits, using scheme: 'q[id]_[gatenum]', e.g. q1_0 -> q1_1 -> q1_2, q2_0 -> q2_1 Args: qb_id (int): index of qubit to generate new variable for Returns: BoolRef: z3 variable of qubit state """ varname = "q" + str(qb_id) + "_" + str(self.gatenum[qb_id]) var = Bool(varname) self.gatenum[qb_id] += 1 self.variables[qb_id].append(var) return var
Example #3
Source File: crosstalk_adaptive_schedule.py From qiskit-terra with Apache License 2.0 | 5 votes |
def create_z3_vars(self): """ Setup the variables required for Z3 optimization """ for gate in self.dag.gate_nodes(): t_var_name = 't_' + str(self.gate_id[gate]) d_var_name = 'd_' + str(self.gate_id[gate]) f_var_name = 'f_' + str(self.gate_id[gate]) self.gate_start_time[gate] = Real(t_var_name) self.gate_duration[gate] = Real(d_var_name) self.gate_fidelity[gate] = Real(f_var_name) for gate in self.xtalk_overlap_set: self.overlap_indicator[gate] = {} self.overlap_amounts[gate] = {} for g_1 in self.xtalk_overlap_set: for g_2 in self.xtalk_overlap_set[g_1]: if len(g_2.qargs) == 2 and g_1 in self.overlap_indicator[g_2]: self.overlap_indicator[g_1][g_2] = self.overlap_indicator[g_2][g_1] self.overlap_amounts[g_1][g_2] = self.overlap_amounts[g_2][g_1] else: # Indicator variable for overlap of g_1 and g_2 var_name1 = 'olp_ind_' + str(self.gate_id[g_1]) + '_' + str(self.gate_id[g_2]) self.overlap_indicator[g_1][g_2] = Bool(var_name1) var_name2 = 'olp_amnt_' + str(self.gate_id[g_1]) + '_' + str(self.gate_id[g_2]) self.overlap_amounts[g_1][g_2] = Real(var_name2) active_qubits_list = [] for gate in self.dag.gate_nodes(): for q in gate.qargs: active_qubits_list.append(q.index) for active_qubit in list(set(active_qubits_list)): q_var_name = 'l_' + str(active_qubit) self.qubit_lifetime[active_qubit] = Real(q_var_name) meas_q = [] for node in self.dag.op_nodes(): if isinstance(node.op, Measure): meas_q.append(node.qargs[0].index) self.measured_qubits = list(set(self.input_measured_qubits).union(set(meas_q))) self.measure_start = Real('meas_start')
Example #4
Source File: solver.py From tea-lang with Apache License 2.0 | 5 votes |
def __init__(self, name): self.name = name self.__z3__ = z3.Bool(self.name) # TODO write test that these areq unique with pointer eq # i.e StatVar('x') != StatVar('x') # vs # x = StatVar('x') # assert x == x
Example #5
Source File: solver.py From tea-lang with Apache License 2.0 | 5 votes |
def __init__(self, name, test_vars, test_properties=None, properties_for_vars=None): global __test_map__, __ALL_TESTS__ self.name = name self.test_vars = test_vars if test_properties is None: test_properties = [] if properties_for_vars is None: properties_for_vars = {} self.test_properties = test_properties self.properties_for_vars = {} for key in properties_for_vars: # properties_for_vars is a list of lists of variables. Get the indices of the variables # in each list. for prop_args in properties_for_vars[key]: indices = [] # if self.name == 'pointbiserial_corr_a': # import pdb; pdb.set_trace() # if self.name == 'factorial_ANOVA': # import pdb; pdb.set_trace() indices = [self.test_vars.index(arg) for arg in prop_args] if key not in self.properties_for_vars.keys(): self.properties_for_vars[key] = [] self.properties_for_vars[key].append(indices) # Create variable. self.__z3__ = z3.Bool(self.name) # Populate global table. __test_map__[self.__z3__] = self if not __ALL_TESTS__: __ALL_TESTS__ = [] __ALL_TESTS__.append(self) # Question: does this mean you can't consider two tests of the same type on different variables at once?
Example #6
Source File: solver.py From tea-lang with Apache License 2.0 | 5 votes |
def __init__(self, prop, pvars): global __property_var_map__ self.property = prop # e.g. continuous self.vars = pvars # (StatVar(name='x'),) # self._name = "" z3_args = [] for tv in pvars: # Allows for unique identification of prop -> var, but not looking up from model because that refs prop name # self._name += tv.name + ":" # self._name + tv.name z3_args.append(tv.__z3__) self._name = self.property.name # continuous # Why is property fn a bool? Does this allow continuous(x) and not continuous(y)? # Answer: I think the undefined function is able to capture all functionality of # deciding the boolean property value for each variable, so the z3.Bool() for the # property name isn't necessary. # self.__var__ = z3.Bool(self._name) # e.g. continuous self.__z3__ = prop.__z3__(*z3_args) # e.g. continuous(x) # _name needs to be unique to avoid overwriting same property for different variables. # But if it is unique, it makes it more difficult to look up from the z3 model. # Solution: Make the name the same, but have it map to a list of variables that the # property applies to. if self._name not in __property_var_map__.keys(): __property_var_map__[self._name] = [] # TODO: When does __property_var_map__ need to be cleared? __property_var_map__[self._name].append(self.vars) self.property_test_results = None
Example #7
Source File: nodes.py From f-ing-around-with-binaryninja with MIT License | 5 votes |
def condition(self) -> Bool: return self._condition
Example #8
Source File: AST.py From jeeves with MIT License | 5 votes |
def z3Node(self): return z3.Bool(self.name)
Example #9
Source File: Z3.py From jeeves with MIT License | 5 votes |
def getBoolVar(self, name): return z3.Bool(name)