Comments (3)
HI, @taosong1999 You may provide an example line of code to show how to profile the solution_test.py and how to interpret the profile results here.
from reactorch.
Line by Line Profiling in iPython
You can also use built-in profiler in Spyder.
from reactorch.
Hi, all. Here's a performance test on the reaction rate constants func (forward, equlibrium and reverse) and wdot func, in which I run these functions for several times (see x-axis). Note that the path of the mechanism file might need to be changed according to where you put the script.
Results:
(The unit of y-axis should be second, of course. )
Codes:
from time import perf_counter
import cantera as ct
import matplotlib.pyplot as plt
import numpy as np
import torch
import reactorch as rt
cpu = torch.device('cpu')
cuda = torch.device('cuda:0')
device = cpu
mech_yaml = '../../data/gri30.yaml'
composition = "CH4:0.5, O2:1.0, N2:3.76"
sol = rt.Solution(mech_yaml=mech_yaml, device=device)
gas = sol.gas
gas.TPX = 950, 20 * ct.one_atm, composition
r = ct.IdealGasReactor(gas)
sim = ct.ReactorNet([r])
time = 0.0
t_end = 10
idt = 0
states = ct.SolutionArray(gas, extra=['t'])
T0 = gas.T
print('%10s %10s %10s %14s' % ('t [s]', 'T [K]', 'P [atm]', 'u [J/kg]'))
count = 0
while sim.time < t_end:
sim.step()
states.append(r.thermo.state, t=time)
if r.thermo.T > T0 + 600 and idt < 1e-10:
idt = sim.time
if idt > 1e-10 and sim.time > 4 * idt:
break
print('%10.3e %10.3f %10.3f %14.6e' % (sim.time,
r.T,
r.thermo.P / ct.one_atm,
r.thermo.u))
print('idt = {:.2e} [s] number of points {}'.format(idt, states.t.shape[0]))
TP = torch.stack((torch.Tensor(states.T), torch.Tensor(states.P)), dim=-1)
Y = torch.Tensor(states.Y)
TPY = torch.cat([TP, Y], dim=-1).to(device)
t0_start = perf_counter()
sol.set_states(TPY)
t1_stop = perf_counter()
print('sol set_states time spent {:.1e} [s]'.format(t1_stop - t0_start))
# tesing reaction rate func
def check_reaction_rate(num):
for i in range(0,num):
sol.forward_rate_constants_func()
sol.equilibrium_constants_func()
sol.reverse_rate_constants_func()
# tesing wdot calc func
def check_wdot(num):
for i in range(0,num):
sol.wdot_func()
test_n_iter = np.array([100,150,200,250,300,350,400,450,500])
time_cost1 = np.zeros_like(test_n_iter)
time_cost2 = np.zeros_like(test_n_iter)
for j in range(0,9):
print('#Test {:d}'.format(j))
t1_stop = perf_counter()
check_reaction_rate(test_n_iter[j])
t2_stop = perf_counter()
t_cost1 = t2_stop - t1_stop
print('sol check_reaction_rate time spent {:.1e} [s]'.format(t_cost1))
check_wdot(test_n_iter[j])
t3_stop = perf_counter()
t_cost2 = t3_stop - t2_stop
print('sol check_wdot time spent {:.1e} [s]'.format(t_cost2))
time_cost1[j] = t_cost1
time_cost2[j] = t_cost2
plt.plot(test_n_iter,time_cost1)
plt.plot(test_n_iter,time_cost2)
plt.xlabel('Number of iterations')
plt.ylabel('Time cost')
plt.legend(['Reaction rate cost','Wdot cost'])
plt.savefig('Performance_test.png',dpi=600)
from reactorch.
Related Issues (20)
- Implementing Jacobian Matrix using PyTorch 1.5 HOT 2
- Write Unit Test HOT 1
- Set up documentation
- Code Flow Chart
- Update installation guidance
- Performance optimization for forward reaction rate and wdot
- abandon the usage of numpy in the class of Solution HOT 2
- Implement an homogenous reactor with scipy.ode.ivp and Jacobian Matrix HOT 2
- Implement PLOG reactions for pressure dependence reactions HOT 3
- Imported error when species order in YAML file is different from expected one
- Implement a PSR example
- Implement BDF solver in PyTorch
- Implement transport data and diffusion term
- Results sensitive on inital composition and setting parameters HOT 32
- Wrong dimension conversion in pre-factor A
- Relationship between ReacTorch and Cantera/Chemkin
- Evaluate the rate constants in batch
- Investigate the sensitivity of this non-negative epsilon HOT 3
- Test Performance for Large Reaction Mechanism HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactorch.