Skip to content

Commit 8e95d21

Browse files
committed
Removed unused imports and hoisted all nested imports to the global module scope
1 parent 6306c1a commit 8e95d21

5 files changed

Lines changed: 7 additions & 14 deletions

File tree

src/process_omol25/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
from .process_omol25 import S3DataProcessor, setup_logging
8+
from mpi4py import MPI as mpi
89

910

1011
def parse_args():
@@ -92,7 +93,6 @@ def main():
9293
args = parse_args()
9394

9495
if args.mpi:
95-
from mpi4py import MPI as mpi
9696
comm = mpi.COMM_WORLD
9797
rank = comm.Get_rank()
9898
size = comm.Get_size()

src/process_omol25/download_omol25.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from botocore.config import Config
1111
from tqdm import tqdm
1212
import time
13-
import psutil
1413

15-
from .process_omol25 import setup_logging, get_ranges
14+
from .process_omol25 import setup_logging
15+
from mpi4py import MPI
16+
from mpi4py import MPI as mpi
1617

1718
logger = logging.getLogger(__name__)
1819

@@ -121,7 +122,6 @@ def extract_buffer(buffer: BytesIO, x: str, k: str):
121122

122123
def manager_loop(keys, data, restart_file, comm, size):
123124
"""Rank 0 Dispatcher for downloads (Synchronous)."""
124-
from mpi4py import MPI
125125
start_time = time.time()
126126
logger.info(f"Download Manager starting with {size - 1} workers.")
127127

@@ -158,7 +158,6 @@ def manager_loop(keys, data, restart_file, comm, size):
158158

159159
def worker_loop(data, args, comm):
160160
"""Rank > 0 Downloader (Synchronous)."""
161-
from mpi4py import MPI
162161
s3_client = None
163162
if not args.local_dir:
164163
with open(args.login_file, "r") as f:
@@ -211,7 +210,6 @@ def main():
211210
args = parse_args()
212211

213212
if args.mpi:
214-
from mpi4py import MPI as mpi
215213
comm = mpi.COMM_WORLD
216214
rank = comm.Get_rank()
217215
size = comm.Get_size()

src/process_omol25/process_omol25.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
ase.parallel.world = DummyMPI()
1515
import boto3
1616
from botocore.config import Config
17-
from botocore.exceptions import ClientError
1817
from tarfile import open as tar_open
1918
from zstandard import ZstdDecompressor
20-
from typing import Optional, Dict, Any, List, Tuple
19+
from typing import Optional, Dict, Any, Tuple
2120
import pandas as pd
2221
import numpy as np
23-
import psutil
2422
from tqdm import tqdm
2523
import time
24+
from mpi4py import MPI
2625

2726
MiB = 1024 ** 2
2827
GiB = 1024 * MiB
@@ -491,7 +490,6 @@ def process_single(self, idx: int, s3_client=None):
491490

492491
def _manager_loop(self):
493492
"""Rank 0 Result Collector loop (Hybrid RMA)."""
494-
from mpi4py import MPI
495493
start_time = time.time()
496494
num_tasks = len(self.indices_to_process)
497495
logger.info(f"Manager starting. Collecting results for {num_tasks} tasks.")
@@ -533,7 +531,6 @@ def _manager_loop(self):
533531

534532
def _worker_loop(self):
535533
"""Rank > 0 Processing loop (Hybrid RMA)."""
536-
from mpi4py import MPI
537534
s3_client = None
538535
if not self.local_dir:
539536
s3_client = boto3.client(
@@ -642,7 +639,6 @@ def _final_merge(self, elapsed_time):
642639

643640
def run_mpi(self):
644641
"""Main entry point for MPI runs (Hybrid RMA)."""
645-
from mpi4py import MPI
646642
self.comm = MPI.COMM_WORLD
647643
self.rank = self.comm.Get_rank()
648644
self.size = self.comm.Get_size()

src/process_omol25/verify_processed_omol25.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
try:
1212
import pandas as pd
13+
import numpy as np
1314
import ase.io
1415
except ImportError as e:
1516
print(f"Error: Missing required dependency. {e}")
@@ -122,7 +123,6 @@ def main():
122123
mismatches += 1
123124
elif pq_val != xyz_val:
124125
try:
125-
import numpy as np
126126
if isinstance(pq_val, np.ndarray) or isinstance(xyz_val, np.ndarray):
127127
if not np.allclose(pq_val, xyz_val, equal_nan=True):
128128
print(f" [Mismatch] sha={sha}, key={key}: NDArray mismatch")

tests/test_verify_processed_omol25.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import subprocess
22
import pandas as pd
3-
from pathlib import Path
43
from ase import Atoms
54
from ase.io import write
65

0 commit comments

Comments
 (0)