Skip to content

Commit 5f879dd

Browse files
committed
Fix some bugs.
1 parent 317809d commit 5f879dd

6 files changed

Lines changed: 301 additions & 236 deletions

File tree

deepks/__main__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import os
2-
import sys
1+
"""DeePKS package entry point."""
32

4-
# Add parent directory to path to import main
5-
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
6-
7-
from main import main
3+
from deepks.main import main
84

95
if __name__ == "__main__":
106
main()

deepks/main.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
"""Unified DeePKS command-line interface."""
3+
4+
import os
5+
import sys
6+
7+
8+
def _get_model_backend():
9+
"""Get model backend instance."""
10+
from deepks.ml.backend import CorrNetModelBackend
11+
return CorrNetModelBackend()
12+
13+
14+
def _get_physics_backend(scf_soft='pyscf'):
15+
"""Get physics backend based on scf_soft parameter.
16+
17+
Args:
18+
scf_soft: SCF software name ('pyscf' or 'abacus')
19+
20+
Returns:
21+
PhysicsBackend instance
22+
"""
23+
from deepks.physics.backends import get_scf_backend
24+
return get_scf_backend(scf_soft)
25+
26+
27+
def main():
28+
"""Main entry point for DeePKS CLI."""
29+
import argparse
30+
# Force line-buffered stdout/stderr so output appears in log.iter in real time
31+
# even when the process is launched with >> redirection (non-TTY).
32+
sys.stdout = open(sys.stdout.fileno(), mode='w', buffering=1, closefd=False)
33+
sys.stderr = open(sys.stderr.fileno(), mode='w', buffering=1, closefd=False)
34+
35+
parser = argparse.ArgumentParser(
36+
prog="deepks",
37+
description="DeePKS: Deep Kohn-Sham DFT with machine learning"
38+
)
39+
parser.add_argument(
40+
"config",
41+
nargs="?",
42+
default="input.yaml",
43+
help="Configuration file (default: input.yaml)"
44+
)
45+
parser.add_argument(
46+
"-v", "--version",
47+
action="version",
48+
version="DeePKS 1.0"
49+
)
50+
51+
args = parser.parse_args()
52+
53+
# Check if config file exists
54+
if not os.path.exists(args.config):
55+
print(f"Error: Configuration file '{args.config}' not found", file=sys.stderr)
56+
sys.exit(1)
57+
58+
# Load and process configuration
59+
from deepks.io.input import load_config, get_default_config
60+
from deepks.io.input.merger import merge_configs, apply_parameter_inheritance
61+
from deepks.io.input.dispatcher import dispatch_command
62+
63+
try:
64+
# Load configuration file
65+
config = load_config(args.config)
66+
67+
# Determine type from config
68+
if 'type' not in config:
69+
print("Error: 'type' field is required in configuration file", file=sys.stderr)
70+
print("Valid types: train, test, scf, stats, iterate", file=sys.stderr)
71+
sys.exit(1)
72+
73+
task_type = config['type']
74+
75+
# Get defaults based on type and backend
76+
scf_soft = config.get('scf_soft', 'pyscf')
77+
defaults = get_default_config(task_type, scf_soft)
78+
79+
# Merge defaults with config
80+
config = merge_configs(defaults, config)
81+
82+
# Apply parameter inheritance for iterate type
83+
if task_type == 'iterate':
84+
config = apply_parameter_inheritance(config)
85+
86+
# Dispatch to appropriate handler
87+
dispatch_command(config)
88+
89+
except Exception as e:
90+
print(f"Error: {e}", file=sys.stderr)
91+
import traceback
92+
traceback.print_exc()
93+
sys.exit(1)
94+
95+
96+
if __name__ == "__main__":
97+
main()

deepks/orchestration/scheduler/job/shell.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ class Shell(Batch) :
1212
def check_status(self) :
1313
if self.check_finish_tag():
1414
return JobStatus.finished
15-
elif self.check_running() or self.check_submitted_tag():
15+
elif self.check_running():
1616
return JobStatus.running
1717
else:
1818
return JobStatus.terminated
19-
## warn: cannont distinguish terminated from unsubmitted.
19+
## note: check_submitted_tag() only tells us the .sub file exists (was submitted),
20+
## not that the process is still running. Using it here caused an infinite loop
21+
## when a job failed: the .sub file remains, so check_status() kept returning
22+
## 'running' forever instead of 'terminated'.
2023

2124
def check_running(self):
2225
uuid_names = self.context.job_uuid

deepks/physics/backends/abacus/input_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def make_abacus_scf_stru(sys_data: Dict[str, Any],
301301
ret += f"{valid_orb_files[atom]}\n"
302302

303303
# DeepKS descriptor
304-
if (fp_params.get("deepks_scf") and
304+
if (fp_params.get("deepks_scf") == 1 or
305305
fp_params.get("deepks_out_labels") == 1):
306306
ret += "\nNUMERICAL_DESCRIPTOR\n"
307307
ret += f"{fp_params['proj_file'][0]}\n"

0 commit comments

Comments
 (0)