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:
EnumThe 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:
tupleA request to generate a CNF.
Create new instance of GenerationRequest(assertion_type, k, boolean_values)
- Parameters
assertion_type (AssertionType) –
k (int) –
- assertion_type: AssertionType
The variant of assertion to make.
- static from_json(data)
Converts a JSON object to a
GenerationRequest.- Parameters
- Return type
- class sweetpea.core.generate.utility.SampleType(value)
Bases:
EnumThe 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:
tupleA 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 (SampleType) –
sample_count (int) –
fresh (int) –
support (int) –
cnf (CNF) –
requests (List[GenerationRequest]) –
- sample_type: SampleType
The type of sample to produce.
- requests: List[GenerationRequest]
A list of requests to make with regard to the CNF formula.
- static from_json(data)
Converts a JSON object to a
ProblemSpecification.- Parameters
- Return type
- class sweetpea.core.generate.utility.Solution(assignment, frequency)
Bases:
tupleThe result of a generation.
Create new instance of Solution(assignment, frequency)
- 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
listofGenerationRequests, merges those formulas, then saves the result to a file at the given path.
- sweetpea.core.generate.utility.combine_cnf_with_requests(initial_cnf, fresh, support, generation_requests)
Combines a base
CNFwith a newCNFformed from the givenGenerationRequests.
- sweetpea.core.generate.utility.save_cnf(filename, cnf, fresh=None, support=None)
Writes a CNF formula to a file at the given path.
- sweetpea.core.generate.utility.temporary_cnf_file(base_path=PosixPath('.'))
Returns a
pathlib.Pathto a new, local file in the directory of the given path with a.cnfsuffix. When used as a context manager (recommended), the file will be deleted when it leaves the context scope.