Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JobSearchIndex (unused class). #587

Merged
merged 1 commit into from
Aug 10, 2021
Merged
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
85 changes: 0 additions & 85 deletions signac/contrib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,91 +79,6 @@ def get_indexes(root):
)


class JobSearchIndex:
"""Search for specific jobs with filters.

The JobSearchIndex allows to search for job_ids,
that are part of an index, which match specific
state point filters or job document filters.

Parameters
----------
index :
A document index.
_trust : bool
Whether to skip document validation on insertion into the internal
Collection (Default value = False).

"""

def __init__(self, index, _trust=False):
self._collection = Collection(index, _trust=_trust)

def __len__(self):
return len(self._collection)

def _resolve_statepoint_filter(self, q):
"""Resolve state point based on filter.

Parameters
----------
q : dict
Filter used for state point selection.

Yields
------
str
Filtered state point.

"""
for key, value in q.items():
if key in ("$and", "$or"):
if not isinstance(value, list) or isinstance(value, tuple):
raise ValueError(
"The argument to a logical operator must be a sequence (e.g. a list)!"
)
yield key, [dict(self._resolve_statepoint_filter(i)) for i in value]
else:
yield f"statepoint.{key}", value

def find_job_ids(self, filter=None, doc_filter=None):
"""Find job ids from a state point or document filter.

Parameters
----------
filter : dict
A mapping of key-value pairs that all indexed job state points are
compared against (Default value = None).
doc_filter : dict
A mapping of key-value pairs that all indexed job documents are
compared against (Default value = None).

Returns
-------
list
List of job ids matching the provided filter(s).

Raises
------
TypeError
If the filters are not JSON serializable.
ValueError
If the filters are invalid.
RuntimeError
If the filters are not supported
by the index.

"""
if filter:
filter = dict(self._resolve_statepoint_filter(filter))
if doc_filter:
filter.update(doc_filter)
elif doc_filter:
warnings.warn(DOC_FILTER_WARNING, DeprecationWarning)
filter = doc_filter
return self._collection._find(filter)


class _ProjectConfig(Config):
r"""Extends the project config to make it immutable.

Expand Down