Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ There are a few important configurations you might want to change:

### Run
A classic run would look something like this:

```python
from dreamer import System, config, log
from dreamer import analysis, search, extraction, loading
Expand All @@ -68,10 +69,10 @@ from dreamer import analysis, search, extraction, loading
config.configure(...)

my_system = System(
if_srcs=[loading.pFq(log(2), 2, 1, -1)], # Set up the loading stage - provide inspiration functions
extractor=extraction.extractor.ShardExtractorMod, # Choose an extraction module
analyzers=[analysis.AnalyzerModV1], # Choose an analysis module(s)
searcher=search.SearcherModV1 # Choose the search module
function_sources=[loading.pFq(log(2), 2, 1, -1)], # Set up the loading stage - provide inspiration functions
extractor=extraction.extractor.ShardExtractorMod, # Choose an extraction module
analyzers=[analysis.AnalyzerModV1], # Choose an analysis module(s)
searcher=search.SearcherModV1 # Choose the search module
)

my_system.run(constants=[log(2)])
Expand Down
17 changes: 9 additions & 8 deletions dreamer/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,28 @@ class System:
"""

def __init__(self,
if_srcs: List[DBModScheme | str | Formatter],
extractor: Optional[Type[ExtractionModScheme]],
*,
function_sources: List[DBModScheme | str | Formatter],
extractor: Optional[Type[ExtractionModScheme]] = None,
analyzers: List[Type[AnalyzerModScheme] | partial[AnalyzerModScheme] | str | Searchable],
searcher: Type[SearcherModScheme] | partial[SearcherModScheme]):
"""
Constructing a system runnable instance for a given combination of modules.
:param if_srcs: A list of DBModScheme instances used as sources.
:param function_sources: A list of DBModScheme instances used as sources.
:param extractor: An optional ExtractionModScheme type used to extract shards from the CMFs.
If extractor not provided, analysis will try to read from the default searchables directory.
:param analyzers: A list of AnalyzerModScheme types used for prioritization + preparation before the search
:param searcher: A SearcherModScheme type used to deepen the search done by the analyzers
"""
if not isinstance(if_srcs, list):
if not isinstance(function_sources, list):
raise ValueError('Inspiration Functions must be contained in a list')

self.if_srcs = if_srcs
self.func_srcs = function_sources
self.extractor = extractor
self.analyzers = analyzers
self.searcher = searcher

if not self.if_srcs and self.extractor:
if not self.func_srcs and self.extractor:
raise ValueError('Could not preform extraction if no sourced to extract from where provided')

def run(self, constants: Optional[List[str | Constant] | str | Constant] = None):
Expand Down Expand Up @@ -165,14 +166,14 @@ def __loading_stage(self, constants: List[Constant]) -> Dict[Constant, List[CMFD
:param constants: A list of all constants relevant to this run
:return: A mapping from a constant to the list of its CMFs (matching the inspiration functions)
"""
if not self.if_srcs:
if not self.func_srcs:
return dict()

Logger('Loading CMFs ...', Logger.Levels.info).log()
modules = []
cmf_data = defaultdict(set)

for db in self.if_srcs:
for db in self.func_srcs:
if isinstance(db, DBModScheme):
modules.append(db)
elif isinstance(db, str):
Expand Down
4 changes: 2 additions & 2 deletions examples/main_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def trajectory_compute_func_analysis(d):
)

System(
if_srcs=[pFq(log(2), 2, 1, -1)],
function_sources=[pFq(log(2), 2, 1, -1)],
extractor=extraction.extractor.ShardExtractorMod,
analyzers=[analysis.AnalyzerModV1],
searcher=search.SearcherModV1
searcher=search.GeneticSearchMod
).run(constants=[log(2)])
2 changes: 1 addition & 1 deletion tests/test_system_logger_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_system_run_calls_logger_start_run_once_per_run(monkeypatch, tmp_path):
monkeypatch.setattr(system_mod.extraction_config, "PATH_TO_SEARCHABLES", str(searchables_dir))

system = System(
if_srcs=[],
function_sources=[],
extractor=None,
analyzers=[],
searcher=cast(type[SearcherModScheme], _DummySearcher),
Expand Down
Loading