hydrotopo
中,当我运行find_edge_nodes
来查找大约100,000条线串的拓扑关系时,只需要大约10秒;但在下面的代码中,find_edge_nodes
将花费大约30分钟:
# extract from https://github.com/iHeadWater/torchhydro/blob/dev-gnn/torchhydro/datasets/data_sets.py#L872
import hydrotopo.ig_path as htip
# the same method costs about 30min
graph_lists = htip.find_edge_nodes(node_features, network_features, node_idx, 'up', cutoff)
return graph_lists
总之,当我在其他程序中调用我的工具时,程序的速度会变得非常慢,当我在调试模式下暂停程序时,程序会停止在
predicates.has_z
。我的代码中没有太多循环。
那么为什么
has_z
会花费这么多时间,或者我应该寻找其他解决方案?
如果您想了解更多详情,请参阅:https://github.com/shapely/shapely/issues/2108
更新:Hydrotopo 和 TorchHydro 都使用 3.11,并且它们都在 Intellij IDEA 中使用 pytest 进行了测试。
我确定
hydrotopo
已编译(/home/username/.conda/envs/torchhydro1/lib/python3.11/site-packages/hydrotopo/__pycache__/ig_path.cpython-311.pyc
)
test_run_model
,但它崩溃了:
(torchhydro1) username@vm-jupyterhub-server:~/torchhydro$ pytest experiments/train_with_era5land_gnn.py::run_test_model
platform linux -- Python 3.11.9, pytest-8.3.2, pluggy-1.5.0
rootdir: /home/username/torchhydro
configfile: setup.cfg
collected 0 items / 1 error
ImportError while importing test module '/home/username/torchhydro/experiments/train_with_era5land_gnn.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../.conda/envs/torchhydro1/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
experiments/train_with_era5land_gnn.py:14: in <module>
from torchhydro.configs.config import cmd, default_config_file, update_cfg
E ModuleNotFoundError: No module named 'torchhydro'
ERROR: found no collectors for /home/username/torchhydro/experiments/train_with_era5land_gnn.py::run_test_model
我知道发生了什么让我的程序变得更慢。 测试Hydrotopo的依赖是
numpy==1.26 shapely==2.0.1
,程序正常;然而,当我使用 numpy==2.0 shapely==2.0.5
时,性能变得更差。
我已经降级了这两个软件包并向 shapely 开发人员报告了这一情况。
与IDEA或pycharm没有任何关系。