用于随机模拟的python包
pyssa的Python项目详细描述
pyssa:用于随机模拟的python包
简介
pyssa
是一个用于随机模拟的python包。它提供了一个简单的api来定义模型,对模型执行随机模拟,并以方便的方式可视化结果。
安装
安装时使用pip
:
$ pip install pyssa
文档
用法
frompyssa.simulationimportSimulationV_r=np.array([[1,0],[0,1],[0,0]])# Reactant matrixV_p=np.array([[0,0],[1,0],[0,1]])# Product matrixX0=np.array([100,0,0])# Initial statek=np.array([1.0,1.0])# Rate constantssim=Simulation(V_r,V_p,X0,k)# Declare the simulation object# Run the simulationsim.simulate(max_t=150,max_iter=1000,chem_flag=True,n_rep=10)
您可以通过更改algorithm
参数来更改用于执行模拟的算法
sim.simulate(max_t=150,max_iter=1000,chem_flag=True,n_rep=10,algorithm="tau_adaptive")
通过指定n_procs
参数,可以在多个核心上运行模拟
sim.simulate(max_t=150,max_iter=1000,chem_flag=True,n_rep=10,n_procs=4)
绘制
sim.plot()
访问结果
results=sim.results
您还可以通过访问所有模拟运行的最终状态
final_times,final_states=results.final
基准
在针对python
和cython
实现进行了广泛的测试和基准测试之后,我们选择了numba
。
Name (time in ms) | Min | Max | Mean | StdDev | Median | IQR | Outliers | OPS | Rounds | Iterations |
---|---|---|---|---|---|---|---|---|---|---|
test_numba_benchmark | 314.1758 (1.0) | 342.9915 (1.0) | 322.9318 (1.0) | 11.4590 (1.0) | 318.7983 (1.0) | 9.1533 (1.0) | 1;1 | 3.0966 (1.0) | 5 | 1 |
test_cy_benchmark | 17,345.7698 (55.21) | 19,628.3931 (57.23) | 18,255.3931 (56.53) | 862.4711 (75.27) | 18,148.9358 (56.93) | 1,030.3676 (112.57) | 2;0 | 0.0548 (0.02) | 5 | 1 |
test_py_benchmark | 27,366.3681 (87.11) | 28,417.8333 (82.85) | 27,782.2482 (86.03) | 387.2758 (33.80) | 27,728.4224 (86.98) | 347.3891 (37.95) | 2;0 | 0.0360 (0.01) | 5 | 1 |
许可证
版权所有(c)2018-2019,Dileep Kishore,Srikiran Chandrasekaran。发布于:apache软件许可证2.0