Skip to content

Commit

Permalink
Merge branch 'master' into feature/optimize-job-hash-eq
Browse files Browse the repository at this point in the history
  • Loading branch information
bdice authored Dec 29, 2020
2 parents ef7cc60 + 426d2ed commit 0179c46
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 132 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
paths:
- ".pre-commit-cache"


linux-python-39: &linux-template
docker:
- image: circleci/python:3.9
Expand Down
4 changes: 2 additions & 2 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def run(key, timer, repeat=3, number=10):
run(
"select_by_id",
Timer(
stmt="project.open_job(id=jobid)",
setup=setup + "jobid = random.choice(list(islice(project, 100))).get_id()",
stmt="project.open_job(id=job_id)",
setup=setup + "job_id = random.choice(list(islice(project, 100))).get_id()",
),
)

Expand Down
18 changes: 10 additions & 8 deletions signac/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def main_remove(args):
for job_id in args.job_id:
job = _open_job_by_id(project, job_id)
if args.interactive and not query_yes_no(
"Are you sure you want to {action} job with id '{job._id}'?".format(
"Are you sure you want to {action} job with id '{job.id}'?".format(
action="clear" if args.clear else "remove", job=job
),
default="no",
Expand Down Expand Up @@ -400,10 +400,12 @@ def format_lines(cat, _id, s):
job = project.open_job(id=job_id)

if args.sp is not None:
sp = job.statepoint()
statepoint = job.statepoint()
if len(args.sp) != 0:
sp = {key: sp[key] for key in args.sp if key in sp}
print(format_lines("sp ", job_id, sp))
statepoint = {
key: statepoint[key] for key in args.sp if key in statepoint
}
print(format_lines("sp ", job_id, statepoint))

if args.doc is not None:
doc = job.document()
Expand All @@ -428,9 +430,9 @@ def main_diff(args):

diff = diff_jobs(*jobs)

for jobid, sp in diff.items():
print(jobid)
pprint(sp)
for job_id, statepoint in diff.items():
print(job_id)
pprint(statepoint)


def main_view(args):
Expand Down Expand Up @@ -1166,7 +1168,7 @@ def write_history_file():
python_version=sys.version,
signac_version=__version__,
project_id=project.id,
job_banner=f"\nJob:\t\t{job._id}" if job is not None else "",
job_banner=f"\nJob:\t\t{job.id}" if job is not None else "",
root_path=project.root_directory(),
workspace_path=project.workspace(),
size=len(project),
Expand Down
20 changes: 10 additions & 10 deletions signac/contrib/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _make_schema_based_path_function(jobs, exclude_keys=None, delimiter_nested="
# signature of the path function below.
return lambda job, sep=None: ""

index = [{"_id": job._id, "statepoint": job.sp()} for job in jobs]
index = [{"_id": job.id, "statepoint": job.statepoint()} for job in jobs]
jsi = _build_job_statepoint_index(exclude_const=True, index=index)
sp_index = OrderedDict(jsi)

Expand Down Expand Up @@ -100,9 +100,9 @@ def path(job, sep=None):
"""
try:
if sep:
return os.path.normpath(sep.join(paths[job._id]))
return os.path.normpath(sep.join(paths[job.id]))
else:
return os.path.normpath(os.path.join(*paths[job._id]))
return os.path.normpath(os.path.join(*paths[job.id]))
except KeyError:
raise RuntimeError(
"Unable to determine path for job '{}'.\nThis is usually caused by a "
Expand All @@ -126,11 +126,9 @@ def format_field(self, value, format_spec):
----------
value :
The value to be formatted.
format_spec :
The format specification.
Returns
-------
str
Expand Down Expand Up @@ -220,7 +218,7 @@ def path_function(job):
"""
try:
try:
ret = path.format(job=job, **job.sp)
ret = path.format(job=job, **job.statepoint)
except TypeError as error:
if (
str(error)
Expand Down Expand Up @@ -605,11 +603,13 @@ def parse_path(path):
"""
match = re.match(schema_regex, os.path.normpath(path))
if match:
sp = match.groupdict()
statepoint = match.groupdict()
for key in types:
if key in sp:
sp[key] = types[key](sp[key])
return _dotted_dict_to_nested_dicts(sp, delimiter_nested=_DOT_MAGIC_WORD)
if key in statepoint:
statepoint[key] = types[key](statepoint[key])
return _dotted_dict_to_nested_dicts(
statepoint, delimiter_nested=_DOT_MAGIC_WORD
)

return parse_path

Expand Down
32 changes: 15 additions & 17 deletions signac/contrib/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,18 @@ def reset_statepoint(self, new_statepoint):
self._cwd = []
logger.info(f"Moved '{self}' -> '{dst}'.")

def _reset_sp(self, new_sp=None):
def _reset_sp(self, new_statepoint=None):
"""Check for new state point requested to assign this job.
Parameters
----------
new_sp : dict
new_statepoint : dict
The job's new state point (Default value = None).
"""
if new_sp is None:
new_sp = self.statepoint()
self.reset_statepoint(new_sp)
if new_statepoint is None:
new_statepoint = self.statepoint()
self.reset_statepoint(new_statepoint)

def update_statepoint(self, update, overwrite=False):
"""Update the state point of this job.
Expand Down Expand Up @@ -290,16 +290,16 @@ def statepoint(self):
return self._statepoint

@statepoint.setter
def statepoint(self, new_sp):
def statepoint(self, new_statepoint):
"""Assign a new state point to this job.
Parameters
----------
new_sp : dict
new_statepoint : dict
The new state point to be assigned.
"""
self._reset_sp(new_sp)
self._reset_sp(new_statepoint)

@property
def sp(self):
Expand Down Expand Up @@ -493,9 +493,9 @@ def _check_manifest(self):
fn_manifest = os.path.join(self._wd, self.FN_MANIFEST)
try:
with open(fn_manifest, "rb") as file:
assert calc_id(json.loads(file.read().decode())) == self._id
assert calc_id(json.loads(file.read().decode())) == self.id
except (AssertionError, ValueError):
raise JobsCorruptedError([self._id])
raise JobsCorruptedError([self.id])

def init(self, force=False):
"""Initialize the job's workspace directory.
Expand Down Expand Up @@ -523,7 +523,7 @@ def init(self, force=False):
self._init(force=force)
except Exception:
logger.error(
f"State point manifest file of job '{self._id}' appears to be corrupted."
f"State point manifest file of job '{self.id}' appears to be corrupted."
)
raise
return self
Expand Down Expand Up @@ -619,7 +619,7 @@ def move(self, project):
self.__dict__.update(dst.__dict__)

def sync(self, other, strategy=None, exclude=None, doc_sync=None, **kwargs):
"""Perform a one-way synchronization of this job with the other job.
r"""Perform a one-way synchronization of this job with the other job.
By default, this method will synchronize all files and document data with
the other job to this job until a synchronization conflict occurs. There
Expand Down Expand Up @@ -652,11 +652,9 @@ def sync(self, other, strategy=None, exclude=None, doc_sync=None, **kwargs):
no keys will be synchronized upon conflict.
dry_run :
If True, do not actually perform the synchronization.
kwargs :
\*\*kwargs :
Extra keyword arguments will be forward to the :meth:`~signac.sync.sync_jobs`
function which actually excutes the synchronization operation.
**kwargs :
Raises
------
Expand Down Expand Up @@ -748,6 +746,6 @@ def __deepcopy__(self, memo):
cls = self.__class__
result = cls.__new__(cls)
memo[id(self)] = result
for k, v in self.__dict__.items():
setattr(result, k, deepcopy(v, memo))
for key, value in self.__dict__.items():
setattr(result, key, deepcopy(value, memo))
return result
4 changes: 2 additions & 2 deletions signac/contrib/linked_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def create_linked_view(project, prefix=None, job_ids=None, index=None, path=None

if index is None:
if job_ids is None:
index = [{"_id": job._id, "statepoint": job.sp()} for job in project]
index = [{"_id": job.id, "statepoint": job.statepoint()} for job in project]
jobs = list(project)
else:
index = [
{"_id": job_id, "statepoint": project.open_job(id=job_id).sp()}
{"_id": job_id, "statepoint": project.open_job(id=job_id).statepoint()}
for job_id in job_ids
]
jobs = list(project.open_job(id=job_id) for job_id in job_ids)
Expand Down
Loading

0 comments on commit 0179c46

Please sign in to comment.