Skip to content

Commit

Permalink
Union --> |
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Jan 29, 2025
1 parent 8388eb3 commit f66cfe1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion abipy/examples/flows/run_phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def make_scf_input(paral_kgb=0):
nband=4,
ecut=2.0,
ngkpt=[4, 4, 4],
nshiftk=4,
nshiftk=4
shiftk=[0.0, 0.0, 0.5, # This gives the usual fcc Monkhorst-Pack grid
0.0, 0.5, 0.0,
0.5, 0.0, 0.0,
Expand Down
1 change: 0 additions & 1 deletion abipy/flowtk/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import copy
import numpy as np
import pandas as pd
#import ruamel.yaml as yaml

from io import StringIO
from pprint import pprint
Expand Down
22 changes: 11 additions & 11 deletions abipy/flowtk/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np
import pandas as pd

from typing import Iterator, Union # Any
from typing import Iterator # Any
from monty.collections import AttrDict
from monty.itertools import chunks
from monty.functools import lazy_property
Expand Down Expand Up @@ -158,7 +158,7 @@ def ncores_used(self) -> int:
"""
return sum(task.manager.num_cores for task in self if task.status == task.S_RUN)

def fetch_task_to_run(self) -> Union[Task, None]:
def fetch_task_to_run(self) -> Task | None:
"""
Returns the first task that is ready to run or
None if no task can be submitted at present"
Expand Down Expand Up @@ -659,7 +659,7 @@ def __len__(self) -> int:
def __iter__(self) -> Iterator[Task]:
return self._tasks.__iter__()

def __getitem__(self, slice) -> Union[Task, list[Task]]:
def __getitem__(self, slice) -> Task | list[Task]:
return self._tasks[slice]

def postpone_on_all_ok(self):
Expand Down Expand Up @@ -769,7 +769,7 @@ def allocate(self, manager=None) -> None:
if task.workdir != task_workdir:
raise ValueError("task.workdir != task_workdir: %s, %s" % (task.workdir, task_workdir))

def register(self, obj: Union[AbinitInput, Task],
def register(self, obj: AbinitInput | Task,
deps=None, required_files=None, manager=None, task_class=None) -> Task:
"""
Registers a new |Task| and add it to the internal list, taking into account possible dependencies.
Expand Down Expand Up @@ -1641,7 +1641,7 @@ def merge_ddb_files(self, delete_source_ddbs=False, only_dfpt_tasks=True,

return out_ddb

def merge_pot1_files(self, delete_source=False) -> Union[str, None]:
def merge_pot1_files(self, delete_source=False) -> str | None:
"""
This method is called when all the q-points have been computed.
It runs `mrgdvdb` in sequential on the local machine to produce
Expand Down Expand Up @@ -1744,7 +1744,7 @@ def from_scf_task(cls, scf_task: ScfTask,
manager: |TaskManager| object.
"""
if not isinstance(scf_task, ScfTask):
raise TypeError("task `%s` does not inherit from ScfTask" % scf_task)
raise TypeError(f"task {scf_task} does not inherit from ScfTask")

if is_ngqpt:
qpoints = scf_task.input.abiget_ibz(ngkpt=qpoints, shiftk=[0, 0, 0], kptopt=qptopt).points
Expand Down Expand Up @@ -1893,7 +1893,7 @@ def from_scf_task(cls, scf_task: ScfTask,
to decrease the number of WFQ files to be computed.
"""
if not isinstance(scf_task, ScfTask):
raise TypeError("task `%s` does not inherit from ScfTask" % scf_task)
raise TypeError(f"task {scf_task} does not inherit from ScfTask")

shiftq = np.reshape(shiftq, (3, ))
#print("ngqpt", ngqpt, "\nshiftq", shiftq)
Expand Down Expand Up @@ -2234,7 +2234,7 @@ def from_scf_task(cls, scf_task: ScfTask,
manager: |TaskManager| object.
"""
if not isinstance(scf_task, ScfTask):
raise TypeError("task `%s` does not inherit from ScfTask" % scf_task)
raise TypeError(f"task {scf_task} does not inherit from ScfTask")

new = cls(manager=manager)

Expand Down Expand Up @@ -2338,7 +2338,7 @@ def from_phwork(cls, phwork, multi, nbr_proc=None, flow=None, with_kerange=False
"""
# Verify phwork
if not isinstance(phwork, PhononWork):
raise TypeError("Work `%s` does not inherit from PhononWork" % phwork)
raise TypeError(f"Work {phwork} does not inherit from PhononWork")

# Verify Multi
if (not with_kerange) and (multi.ndtset != 3): #Without kerange, multi should contain 3 datasets
Expand Down Expand Up @@ -2406,10 +2406,10 @@ def from_filepath(cls, ddb_path, dvdb_path, multi, nbr_proc=None, flow=None,
multi with the factory function conduc_from_scf_nscf_inputs""" % multi.ndtset)
# Make sure both file exists
if not os.path.exists(ddb_path):
raise ValueError("The DDB file doesn't exists : `%s`" % ddb_path)
raise ValueError(f"The DDB file {ddb_path} does not exist")

if not os.path.exists(dvdb_path):
raise ValueError("The DVDB file doesn't exists : `%s`" % dvdb_path)
raise ValueError(f"The DVDB file {dvdb_path} does not exist")

# Verify nbr_proc and flow are defined if with_kerange
if with_kerange and (flow is None or nbr_proc is None):
Expand Down
4 changes: 2 additions & 2 deletions abipy/iotools/xsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def xsf_write_data(file, structure, data, add_replicas=True, cplx_mode=None,
elif cplx_mode == "abs":
data = np.abs(data)
else:
raise ValueError("Wrong value for cplx_mode: %s" % cplx_mode)
raise ValueError(f"Wrong value for {cplx_mode=}")

shape, ndim = data.shape, data.ndim

Expand All @@ -135,7 +135,7 @@ def xsf_write_data(file, structure, data, add_replicas=True, cplx_mode=None,
elif ndim == 4:
ngrids = shape[0]
else:
raise ValueError("ndim %d is not supported" % ndim)
raise ValueError(f"{ndim=} is not supported")

# Xcrysden uses Fortran-order.
# Transpose (...,x,y,z) --> (...,z,y,x) to speed up the write below.
Expand Down

0 comments on commit f66cfe1

Please sign in to comment.