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

Migrate to ruff #239

Merged
merged 1 commit into from
Jun 21, 2024
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
29 changes: 5 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,12 @@ repos:
exclude: ^conda/
- id: check-added-large-files

- repo: https://github.com/pycqa/flake8
rev: 7.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: flake8
args:
- "--max-line-length=88"
- "--ignore=E203,W503"

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
args:
- --line-length=88

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- id: ruff
args: [ "--fix", "--show-fixes" ]
- id: ruff-format

- repo: https://github.com/Takishima/cmake-pre-commit-hooks
rev: v1.9.6
Expand Down
2 changes: 1 addition & 1 deletion phono3py/api_jointdos.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
from phonopy.units import VaspToTHz

from phono3py.file_IO import write_joint_dos
from phono3py.phonon.grid import BZGrid
from phono3py.phonon3.imag_self_energy import (
get_freq_points_batches,
get_frequency_points,
)
from phono3py.phonon3.joint_dos import JointDos
from phono3py.phonon.grid import BZGrid


class Phono3pyJointDos:
Expand Down
6 changes: 3 additions & 3 deletions phono3py/api_phono3py.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,20 @@
from phono3py.conductivity.rta import get_thermal_conductivity_RTA
from phono3py.interface.fc_calculator import get_fc3
from phono3py.interface.phono3py_yaml import Phono3pyYaml
from phono3py.phonon.grid import BZGrid
from phono3py.phonon3.dataset import get_displacements_and_forces_fc3
from phono3py.phonon3.displacement_fc3 import (
direction_to_displacement,
get_third_order_displacements,
)
from phono3py.phonon3.fc3 import cutoff_fc3_by_zero
from phono3py.phonon3.fc3 import get_fc3 as get_phono3py_fc3
from phono3py.phonon3.fc3 import (
cutoff_fc3_by_zero,
set_permutation_symmetry_compact_fc3,
set_permutation_symmetry_fc3,
set_translational_invariance_compact_fc3,
set_translational_invariance_fc3,
)
from phono3py.phonon3.fc3 import get_fc3 as get_phono3py_fc3
from phono3py.phonon3.imag_self_energy import (
get_imag_self_energy,
write_imag_self_energy,
Expand All @@ -95,7 +96,6 @@
write_real_self_energy,
)
from phono3py.phonon3.spectral_function import run_spectral_function
from phono3py.phonon.grid import BZGrid
from phono3py.version import __version__


Expand Down
22 changes: 21 additions & 1 deletion phono3py/conductivity/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
from phonopy.units import EV, Angstrom, Kb, THz, THzToEv

from phono3py.other.isotope import Isotope
from phono3py.phonon.grid import get_grid_points_by_rotations, get_ir_grid_points
from phono3py.phonon3.collision_matrix import CollisionMatrix
from phono3py.phonon3.imag_self_energy import ImagSelfEnergy
from phono3py.phonon3.interaction import Interaction
from phono3py.phonon.grid import get_grid_points_by_rotations, get_ir_grid_points

unit_to_WmK = (
(THz * Angstrom) ** 2 / (Angstrom**3) * EV / THz / (2 * np.pi)
Expand Down Expand Up @@ -81,6 +81,7 @@ def get_mode_heat_capacities(self):
"Use attribute, Conductivity.mode_heat_capacities "
"instead of Conductivity.get_mode_heat_capacities().",
DeprecationWarning,
stacklevel=2,
)
return self.mode_heat_capacities

Expand Down Expand Up @@ -129,6 +130,7 @@ def get_kappa(self):
warnings.warn(
"Use attribute, Conductivity.kappa " "instead of Conductivity.get_kappa().",
DeprecationWarning,
stacklevel=2,
)
return self.kappa

Expand All @@ -143,6 +145,7 @@ def get_mode_kappa(self):
"Use attribute, Conductivity.mode_kappa "
"instead of Conductivity.get_mode_kappa().",
DeprecationWarning,
stacklevel=2,
)
return self.mode_kappa

Expand All @@ -165,6 +168,7 @@ def get_group_velocities(self):
"Use attribute, Conductivity.group_velocities "
"instead of Conductivity.get_group_velocities().",
DeprecationWarning,
stacklevel=2,
)
return self.group_velocities

Expand All @@ -179,6 +183,7 @@ def get_gv_by_gv(self):
"Use attribute, Conductivity.gv_by_gv "
"instead of Conductivity.get_gv_by_gv().",
DeprecationWarning,
stacklevel=2,
)
return self.gv_by_gv

Expand Down Expand Up @@ -413,6 +418,7 @@ def get_mesh_numbers(self):
"Use attribute, Conductivity.mesh_numbers "
"instead of Conductivity.get_mesh_numbers().",
DeprecationWarning,
stacklevel=2,
)
return self.mesh_numbers

Expand Down Expand Up @@ -440,6 +446,7 @@ def get_frequencies(self):
"Use attribute, Conductivity.frequencies "
"instead of Conductivity.get_frequencies().",
DeprecationWarning,
stacklevel=2,
)
return self.frequencies

Expand All @@ -458,6 +465,7 @@ def get_qpoints(self):
"Use attribute, Conductivity.qpoints "
"instead of Conductivity.get_qpoints().",
DeprecationWarning,
stacklevel=2,
)
return self.qpoints

Expand All @@ -480,6 +488,7 @@ def get_grid_points(self):
"Use attribute, Conductivity.grid_points "
"instead of Conductivity.get_grid_points().",
DeprecationWarning,
stacklevel=2,
)
return self.grid_points

Expand All @@ -494,6 +503,7 @@ def get_grid_weights(self):
"Use attribute, Conductivity.grid_weights "
"instead of Conductivity.get_grid_weights().",
DeprecationWarning,
stacklevel=2,
)
return self.grid_weights

Expand All @@ -513,6 +523,7 @@ def get_temperatures(self):
"Use attribute, Conductivity.temperatures "
"instead of Conductivity.get_temperatures().",
DeprecationWarning,
stacklevel=2,
)
return self.temperatures

Expand All @@ -522,6 +533,7 @@ def set_temperatures(self, temperatures):
"Use attribute, Conductivity.temperatures "
"instead of Conductivity.set_temperatures().",
DeprecationWarning,
stacklevel=2,
)
self.temperatures = temperatures

Expand All @@ -540,6 +552,7 @@ def get_gamma(self):
warnings.warn(
"Use attribute, Conductivity.gamma " "instead of Conductivity.get_gamma().",
DeprecationWarning,
stacklevel=2,
)
return self.gamma

Expand All @@ -548,6 +561,7 @@ def set_gamma(self, gamma):
warnings.warn(
"Use attribute, Conductivity.gamma " "instead of Conductivity.set_gamma().",
DeprecationWarning,
stacklevel=2,
)
self.gamma = gamma

Expand All @@ -567,6 +581,7 @@ def get_gamma_isotope(self):
"Use attribute, Conductivity.gamma_isotope "
"instead of Conductivity.get_gamma_isotope().",
DeprecationWarning,
stacklevel=2,
)
return self.gamma_isotope

Expand All @@ -576,6 +591,7 @@ def set_gamma_isotope(self, gamma_iso):
"Use attribute, Conductivity.gamma_isotope "
"instead of Conductivity.set_gamma_isotope().",
DeprecationWarning,
stacklevel=2,
)
self.gamma_isotope = gamma_iso

Expand All @@ -590,6 +606,7 @@ def get_sigmas(self):
"Use attribute, Conductivity.sigmas "
"instead of Conductivity.get_sigmas().",
DeprecationWarning,
stacklevel=2,
)
return self.sigmas

Expand All @@ -604,6 +621,7 @@ def get_sigma_cutoff_width(self):
"Use attribute, Conductivity.sigma_cutoff_width "
"instead of Conductivity.get_sigma_cutoff_width().",
DeprecationWarning,
stacklevel=2,
)
return self.sigma_cutoff_width

Expand All @@ -618,6 +636,7 @@ def get_grid_point_count(self):
"Use attribute, Conductivity.grid_point_count "
"instead of Conductivity.get_grid_point_count().",
DeprecationWarning,
stacklevel=2,
)
return self.grid_point_count

Expand All @@ -632,6 +651,7 @@ def get_averaged_pp_interaction(self):
"Use attribute, Conductivity.averaged_pp_interaction "
"instead of Conductivity.get_averaged_pp_interaction().",
DeprecationWarning,
stacklevel=2,
)
return self.averaged_pp_interaction

Expand Down
12 changes: 8 additions & 4 deletions phono3py/conductivity/direct_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
get_conversion_factor_WTE,
)
from phono3py.file_IO import read_pp_from_hdf5
from phono3py.phonon.grid import get_grid_points_by_rotations
from phono3py.phonon3.collision_matrix import CollisionMatrix
from phono3py.phonon3.interaction import Interaction, all_bands_exist
from phono3py.phonon.grid import get_grid_points_by_rotations


class ConductivityLBTEBase(ConductivityBase):
Expand Down Expand Up @@ -163,6 +163,7 @@ def get_collision_matrix(self):
"Use attribute, Conductivity_LBTE.collision_matrix "
"instead of Conductivity_LBTE.get_collision_matrix().",
DeprecationWarning,
stacklevel=2,
)
return self.collision_matrix

Expand All @@ -172,6 +173,7 @@ def set_collision_matrix(self, collision_matrix):
"Use attribute, Conductivity_LBTE.collision_matrix "
"instead of Conductivity_LBTE.set_collision_matrix().",
DeprecationWarning,
stacklevel=2,
)
self.collision_matrix = collision_matrix

Expand Down Expand Up @@ -517,9 +519,9 @@ def _set_collision_matrix_at_sigmas(self, i_gp):
else:
i_data = 0
self._gamma[j, k, i_data] = self._collision.imag_self_energy
self._collision_matrix[j, k, i_data] = (
self._collision.get_collision_matrix()
)
self._collision_matrix[
j, k, i_data
] = self._collision.get_collision_matrix()

def _prepare_collision_matrix(self):
"""Collect pieces and construct collision matrix."""
Expand Down Expand Up @@ -1271,6 +1273,7 @@ def get_kappa_RTA(self):
"Use attribute, Conductivity_LBTE.kappa_RTA "
"instead of Conductivity_LBTE.get_kappa_RTA().",
DeprecationWarning,
stacklevel=2,
)
return self.kappa_RTA

Expand All @@ -1285,6 +1288,7 @@ def get_mode_kappa_RTA(self):
"Use attribute, Conductivity_LBTE.mode_kappa_RTA "
"instead of Conductivity_LBTE.get_mode_kappa_RTA().",
DeprecationWarning,
stacklevel=2,
)
return self.mode_kappa_RTA

Expand Down
10 changes: 5 additions & 5 deletions phono3py/conductivity/rta.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
)
from phono3py.file_IO import read_pp_from_hdf5
from phono3py.other.tetrahedron_method import get_tetrahedra_relative_grid_address
from phono3py.phonon.grid import get_grid_points_by_rotations
from phono3py.phonon3.imag_self_energy import ImagSelfEnergy, average_by_degeneracy
from phono3py.phonon3.interaction import Interaction, all_bands_exist
from phono3py.phonon.grid import get_grid_points_by_rotations


class ConductivityRTABase(ConductivityBase):
Expand Down Expand Up @@ -298,9 +298,9 @@ def _set_gamma_at_sigmas(self, i):
self._gamma_N[j, k, i] = g_N
self._gamma_U[j, k, i] = g_U
if self._is_gamma_detail:
self._gamma_detail_at_q[k] = (
self._collision.get_detailed_imag_self_energy()
)
self._gamma_detail_at_q[
k
] = self._collision.get_detailed_imag_self_energy()

def _set_gamma_at_sigmas_lowmem(self, i):
"""Calculate gamma without storing ph-ph interaction strength.
Expand Down Expand Up @@ -921,7 +921,7 @@ def _set_kappa_at_sigmas(self, j, k, i_gp, i_band, g_sum, frequencies):
return

g = g_sum[i_band] + g_sum[j_band]
for i_pair, (a, b) in enumerate(
for i_pair, _ in enumerate(
([0, 0], [1, 1], [2, 2], [1, 2], [0, 2], [0, 1])
):
old_settings = np.seterr(all="raise")
Expand Down
13 changes: 6 additions & 7 deletions phono3py/conductivity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


import sys
from typing import TYPE_CHECKING, Optional, Union

Expand Down Expand Up @@ -367,7 +366,7 @@ def write_gamma_detail(
all_triplets = get_all_triplets(gp, interaction.bz_grid)

if all_bands_exist(interaction):
for j, sigma in enumerate(sigmas):
for sigma in sigmas:
write_gamma_detail_to_hdf5(
temperatures,
mesh,
Expand All @@ -384,7 +383,7 @@ def write_gamma_detail(
verbose=verbose,
)
else:
for j, sigma in enumerate(sigmas):
for sigma in sigmas:
for k, bi in enumerate(interaction.get_band_indices()):
write_gamma_detail_to_hdf5(
temperatures,
Expand Down Expand Up @@ -871,7 +870,7 @@ def kappa_RTA(br: "ConductivityRTA", log_level):
("#%6s " + " %-10s" * 6)
% ("T(K)", "xx", "yy", "zz", "yz", "xz", "xy")
)
for j, (t, k) in enumerate(zip(temperatures, kappa[i])):
for t, k in zip(temperatures, kappa[i]):
print(("%7.1f " + " %10.3f" * 6) % ((t,) + tuple(k)))
print("")

Expand Down Expand Up @@ -936,13 +935,13 @@ def kappa_Wigner_RTA(br: "ConductivityWignerRTA", log_level):
% (" \t T(K)", "xx", "yy", "zz", "yz", "xz", "xy")
)
if kappa_P_RTA is not None:
for j, (t, k) in enumerate(zip(temperatures, kappa_P_RTA[i])):
for t, k in zip(temperatures, kappa_P_RTA[i]):
print("K_P\t" + ("%7.1f " + " %10.3f" * 6) % ((t,) + tuple(k)))
print(" ")
for j, (t, k) in enumerate(zip(temperatures, kappa_C[i])):
for t, k in zip(temperatures, kappa_C[i]):
print("K_C\t" + ("%7.1f " + " %10.3f" * 6) % ((t,) + tuple(k)))
print(" ")
for j, (t, k) in enumerate(zip(temperatures, kappa_TOT_RTA[i])):
for t, k in zip(temperatures, kappa_TOT_RTA[i]):
print("K_T\t" + ("%7.1f " + " %10.3f" * 6) % ((t,) + tuple(k)))
print("")

Expand Down
Loading
Loading