HOPE:用于天体物理计算的Python即时编译器
HOPE: A Python Just-In-Time compiler for astrophysical computations
摘要:
Python编程语言由于其简单性、多功能性和广泛的库而在科学应用中越来越受欢迎。然而,这种动态语言的一个缺点是其低运行时性能,这限制了其适用性的大型模拟和大型数据集的分析,是常见的天体物理学和宇宙学。虽然已经开发了各种框架来解决这个限制,但大多数框架都专注于覆盖完整的语言集,并且要么迫使用户修改代码,要么无法达到优化的本地编译语言的全速。为了结合Python的易用性和C++的速度,我们开发了HOPE,这是一个专门为数值天体物理应用设计的Python即时(JIT)编译器。HOPE专注于语言的一个子集,能够将Python代码转换为C++,同时在运行时对数学表达式进行数值优化。要启用JIT编译,用户只需要向函数定义添加装饰器。我们通过执行一系列基准测试来评估HOPE的性能,并将其执行速度与普通Python,C++和其他现有框架的执行速度进行比较。我们发现,与普通Python相比,HOPE将性能提高了2到120倍,达到了与C++相当的速度,并且通常超过了现有解决方案的速度。我们讨论了希望和其他框架之间的差异,以及其功能的未来扩展。完整文档的HOPE包可在http://hope.phys.ethz.ch上获得,并在PyPI和GitHub上以GPL v3许可证发布。
英文摘要:
The Python programming language is becoming increasingly popular for scientific applications due to its simplicity, versatility, and the broad range of its libraries. A drawback of this dynamic language, however, is its low runtime performance which limits its applicability for large simulations and for the analysis of large data sets, as is common in astrophysics and cosmology. While various frameworks have been developed to address this limitation, most focus on covering the complete language set, and either force the user to alter the code or are not able to reach the full speed of an optimised native compiled language. In order to combine the ease of Python and the speed of C++, we developed HOPE, a specialised Python just-in-time (JIT) compiler designed for numerical astrophysical applications. HOPE focuses on a subset of the language and is able to translate Python code into C++ while performing numerical optimisation on mathematical expressions at runtime. To enable the JIT compilation, the user only needs to add a decorator to the function definition. We assess the performance of HOPE by performing a series of benchmarks and compare its execution speed with that of plain Python, C++ and the other existing frameworks. We find that HOPE improves the performance compared to plain Python by a factor of 2 to 120, achieves speeds comparable to that of C++, and often exceeds the speed of the existing solutions. We discuss the differences between HOPE and the other frameworks, as well as future extensions of its capabilities. The fully documented HOPE package is available at http://hope.phys.ethz.ch and is published under the GPLv3 license on PyPI and GitHub.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。