sweetpea.core.generate.utility module¶
This module provides the types and common functions that are used across the
various submodules of sweetpea.core.generate
.
- class sweetpea.core.generate.utility.AssertionType(value)¶
Bases:
enum.Enum
The three supported variants of CNF assertion.
- EQ = 1¶
Assert k == n.
- LT = 2¶
Assert k < n.
- GT = 3¶
Assert k > n.
- static from_json(s)¶
Converts a JSON string to an
AssertionType
.- Parameters
s (str) –
- Return type
- class sweetpea.core.generate.utility.GenerationRequest(assertion_type, k, boolean_values)¶
Bases:
tuple
A request to generate a CNF.
Create new instance of GenerationRequest(assertion_type, k, boolean_values)
- Parameters
assertion_type (sweetpea.core.generate.utility.AssertionType) –
k (int) –
boolean_values (List[sweetpea.core.cnf.Var]) –
- property assertion_type¶
The variant of assertion to make.
- property k¶
The
k
value.
- property boolean_values¶
A list of variables to use in generation.
- static from_json(data)¶
Converts a JSON object to a
GenerationRequest
.- Parameters
data (Dict[str, Any]) –
- Return type
- class sweetpea.core.generate.utility.SampleType(value)¶
Bases:
enum.Enum
The supported methods of interacting with SweetPea core.
- Uniform = 1¶
Uniform sampling of a CNF formula.
- NonUniform = 2¶
Non-uniform sampling of a CNF formula.
- IsSatisfiable = 3¶
Test whether a CNF formula is satisfiable.
- static from_json(s)¶
Converts a JSON string to a
SampleType
.- Parameters
s (str) –
- Return type
- class sweetpea.core.generate.utility.ProblemSpecification(sample_type, sample_count, fresh, support, cnf, requests)¶
Bases:
tuple
A specification of a complete SweetPea problem to be solved.
Create new instance of ProblemSpecification(sample_type, sample_count, fresh, support, cnf, requests)
- Parameters
sample_type (sweetpea.core.generate.utility.SampleType) –
sample_count (int) –
fresh (int) –
support (int) –
cnf (sweetpea.core.cnf.CNF) –
requests (List[sweetpea.core.generate.utility.GenerationRequest]) –
- property sample_type¶
The type of sample to produce.
- property sample_count¶
The number of samples to take.
- property fresh¶
Alias for field number 2
- property support¶
The length of the support set.
- property cnf¶
The CNF formula to sample.
- property requests¶
A list of requests to make with regard to the CNF formula.
- static from_json(data)¶
Converts a JSON object to a
ProblemSpecification
.- Parameters
data (Dict[str, Any]) –
- Return type
- class sweetpea.core.generate.utility.Solution(assignment, frequency)¶
Bases:
tuple
The result of a generation.
Create new instance of Solution(assignment, frequency)
- property assignment¶
Alias for field number 0
- property frequency¶
Alias for field number 1
- sweetpea.core.generate.utility.combine_and_save_cnf(filename, initial_cnf, fresh, support, generation_requests)¶
Combines a base CNF formula with the augmentations specified by the
list
ofGenerationRequests
, merges those formulas, then saves the result to a file at the given path.- Parameters
filename (pathlib.Path) –
initial_cnf (sweetpea.core.cnf.CNF) –
fresh (int) –
support (int) –
generation_requests (List[sweetpea.core.generate.utility.GenerationRequest]) –
- sweetpea.core.generate.utility.combine_cnf_with_requests(initial_cnf, fresh, support, generation_requests)¶
Combines a base
CNF
with a newCNF
formed from the givenGenerationRequests
.- Parameters
initial_cnf (sweetpea.core.cnf.CNF) –
fresh (int) –
support (int) –
generation_requests (List[sweetpea.core.generate.utility.GenerationRequest]) –
- Return type
- sweetpea.core.generate.utility.save_cnf(filename, cnf, fresh=None, support=None)¶
Writes a CNF formula to a file at the given path.
- Parameters
filename (pathlib.Path) –
cnf (sweetpea.core.cnf.CNF) –
fresh (Optional[int]) –
support (Optional[int]) –
- sweetpea.core.generate.utility.temporary_cnf_file(base_path=PosixPath('.'))¶
Returns a
pathlib.Path
to a new, local file in the directory of the given path with a.cnf
suffix. When used as a context manager (recommended), the file will be deleted when it leaves the context scope.- Parameters
base_path (pathlib.Path) –
- Return type
Iterator[pathlib.Path]