sympy2c:从符号表达式到Python中的快速C/C ++函数和ODE求解器
sympy2c: from symbolic expressions to fast C/C++ functions and ODE solvers in Python
摘要:
计算机代数系统在科学中发挥着重要作用,因为它们促进了新理论模型的发展。所得到的符号方程通常在编译的编程语言中实现,以便为实际应用提供快速和可移植的代码。我们描述sympy 2c,一个新的Python包,旨在弥合理论模型的符号开发和数值实现之间的差距。sympy 2c将SymPy Python包中实现的符号方程转换为使用符号转换优化的C/C++代码。生成的函数可以方便地用作Python中的扩展模块。sympy 2c在PyCosmo Python包中用于求解爱因斯坦-玻尔兹曼方程,这是一个描述宇宙中线性扰动演化的大型常微分方程系统。在回顾了sympy 2c的功能和用法之后,我们描述了它的实现和优化策略。这包括,特别是,一种新的方法来生成优化的ODE求解器,利用符号雅可比矩阵的稀疏性。我们证明了它的性能使用爱因斯坦-玻尔兹曼方程作为测试用例。Sympy 2c是广泛适用的,并且可以证明对计算物理的各个领域是有用的。sympy 2c可在https://cosmology.ethz.ch/research/software-lab/sympy2c.html上公开获取
英文摘要:
Computer algebra systems play an important role in science as they facilitate the development of new theoretical models. The resulting symbolic equations are often implemented in a compiled programming language in order to provide fast and portable codes for practical applications. We describe sympy2c, a new Python package designed to bridge the gap between the symbolic development and the numerical implementation of a theoretical model. sympy2c translates symbolic equations implemented in the SymPy Python package to C/C++ code that is optimized using symbolic transformations. The resulting functions can be conveniently used as an extension module in Python. sympy2c is used within the PyCosmo Python package to solve the Einstein-Boltzmann equations, a large system of ODEs describing the evolution of linear perturbations in the Universe. After reviewing the functionalities and usage of sympy2c, we describe its implementation and optimization strategies. This includes, in particular, a novel approach to generate optimized ODE solvers making use of the sparsity of the symbolic Jacobian matrix. We demonstrate its performance using the Einstein-Boltzmann equations as a test case. sympy2c is widely applicable and may prove useful for various areas of computational physics. sympy2c is publicly available at https://cosmology.ethz.ch/research/software-lab/sympy2c.html
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。