feat: 外部引擎实时进度条 + C引擎read_bonds rewind修复
1. 引擎端:C/C++/Fortran 主循环每 1% 输出 progress 到 stdout 2. compute.py:读取 "[xxx] progress: N/total" 行更新 tqdm 3. 移除不准的时间估算逻辑,改用真实引擎进度 4. C引擎 read_bonds:rewind 后补 fgets 跳表头 5. gitignore 添加 output_test/
This commit is contained in:
+9
-3
@@ -10,6 +10,7 @@ compute.py
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -760,6 +761,14 @@ def run_engine(engine, input_dir, output_dir, config):
|
|||||||
_line = _line.strip()
|
_line = _line.strip()
|
||||||
if _line:
|
if _line:
|
||||||
_engine_lines.append(_line)
|
_engine_lines.append(_line)
|
||||||
|
# 读取外部引擎真实进度:格式 "[xxx-engine] progress: N/total"
|
||||||
|
_prog_match = re.search(r'progress:\s*(\d+)/(\d+)', _line)
|
||||||
|
if _pbar is not None and _prog_match:
|
||||||
|
_prog_done = int(_prog_match.group(1))
|
||||||
|
_prog_total = int(_prog_match.group(2))
|
||||||
|
if _prog_total > 0:
|
||||||
|
_pbar.n = min(_prog_done, total_steps)
|
||||||
|
_pbar.refresh()
|
||||||
if _p.poll() is not None:
|
if _p.poll() is not None:
|
||||||
if _p.stdout:
|
if _p.stdout:
|
||||||
for _r in _p.stdout:
|
for _r in _p.stdout:
|
||||||
@@ -767,9 +776,6 @@ def run_engine(engine, input_dir, output_dir, config):
|
|||||||
if _r:
|
if _r:
|
||||||
_engine_lines.append(_r)
|
_engine_lines.append(_r)
|
||||||
break
|
break
|
||||||
if _pbar is not None and _est_total > 0:
|
|
||||||
_pbar.n = int(min((time.time() - t_start) / _est_total, 0.99) * total_steps)
|
|
||||||
_pbar.refresh()
|
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
finally:
|
finally:
|
||||||
if _pbar is not None:
|
if _pbar is not None:
|
||||||
|
|||||||
@@ -926,7 +926,13 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 记录 */
|
/* 记录 */
|
||||||
|
int _prog_interval = record_steps / 100;
|
||||||
|
if (_prog_interval < 1) _prog_interval = 1;
|
||||||
for (int s = 0; s < record_steps; s++) {
|
for (int s = 0; s < record_steps; s++) {
|
||||||
|
if (s % _prog_interval == 0 && s > 0) {
|
||||||
|
printf("[C-engine] progress: %d/%d\n", s, record_steps);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
double t = (s + params.warmup_steps) * params.DT;
|
double t = (s + params.warmup_steps) * params.DT;
|
||||||
if (params.driving_force) apply_driving_force(n, x, y, z, vx, vy, vz, t, s, params.DT, &drivers);
|
if (params.driving_force) apply_driving_force(n, x, y, z, vx, vy, vz, t, s, params.DT, &drivers);
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
|
|||||||
@@ -843,7 +843,12 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 记录
|
// 记录
|
||||||
|
int _prog_int = record_steps / 100;
|
||||||
|
if (_prog_int < 1) _prog_int = 1;
|
||||||
for (int s = 0; s < record_steps; s++) {
|
for (int s = 0; s < record_steps; s++) {
|
||||||
|
if (s % _prog_int == 0 && s > 0) {
|
||||||
|
std::cout << "[Cpp-engine] progress: " << s << "/" << record_steps << std::endl;
|
||||||
|
}
|
||||||
double t = (s + params.warmup_steps) * params.DT;
|
double t = (s + params.warmup_steps) * params.DT;
|
||||||
if (params.driving_force)
|
if (params.driving_force)
|
||||||
apply_driving_force(n, x.data(), y.data(), z.data(), vx.data(), vy.data(), vz.data(), t, s, params.DT, drivers);
|
apply_driving_force(n, x.data(), y.data(), z.data(), vx.data(), vy.data(), vz.data(), t, s, params.DT, drivers);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ program dynamics_f90
|
|||||||
double precision, allocatable :: bond_stiffness(:), bond_rest_lengths(:)
|
double precision, allocatable :: bond_stiffness(:), bond_rest_lengths(:)
|
||||||
|
|
||||||
! 驱动力数据
|
! 驱动力数据
|
||||||
integer :: n_drivers
|
integer :: n_drivers, prog_step
|
||||||
integer, allocatable :: drv_atom_idx(:)
|
integer, allocatable :: drv_atom_idx(:)
|
||||||
double precision, allocatable :: drv_amp_x(:), drv_amp_y(:), drv_amp_z(:)
|
double precision, allocatable :: drv_amp_x(:), drv_amp_y(:), drv_amp_z(:)
|
||||||
double precision, allocatable :: drv_freq_x(:), drv_freq_y(:), drv_freq_z(:)
|
double precision, allocatable :: drv_freq_x(:), drv_freq_y(:), drv_freq_z(:)
|
||||||
@@ -139,7 +139,12 @@ program dynamics_f90
|
|||||||
end do
|
end do
|
||||||
|
|
||||||
! 记录
|
! 记录
|
||||||
|
prog_step = record_steps / 100
|
||||||
|
if (prog_step < 1) prog_step = 1
|
||||||
do s = 1, record_steps
|
do s = 1, record_steps
|
||||||
|
if (mod(s, prog_step) == 0 .and. s > 0) then
|
||||||
|
write(*, '("[Fortran-engine] progress: ", i0, "/", i0)') s, record_steps
|
||||||
|
end if
|
||||||
if (driving_force /= 0 .and. n_drivers > 0) then
|
if (driving_force /= 0 .and. n_drivers > 0) then
|
||||||
tw = ((s-1 + warmup_steps) * 1.0d0) * DT
|
tw = ((s-1 + warmup_steps) * 1.0d0) * DT
|
||||||
call apply_driving(n, x, y, z, vx, vy, vz, tw, s-1, DT, &
|
call apply_driving(n, x, y, z, vx, vy, vz, tw, s-1, DT, &
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ warmup_steps: 0 # 默认 0(立即开始记录)
|
|||||||
|
|
||||||
# 总模拟时间(秒),程序自动计算 NT = T_total / DT
|
# 总模拟时间(秒),程序自动计算 NT = T_total / DT
|
||||||
# 如果同时指定了 NT,以 NT 为准
|
# 如果同时指定了 NT,以 NT 为准
|
||||||
T_total: 10.0
|
T_total: 50.0
|
||||||
|
|
||||||
# 抽帧间隔(每 NSTEP 步取一帧用于动画)
|
# 抽帧间隔(每 NSTEP 步取一帧用于动画)
|
||||||
NSTEP: 100
|
NSTEP: 100
|
||||||
|
|||||||
Reference in New Issue
Block a user