We need to profile/optimise the risk calculator
Bug #797615 reported by
Muharem Hrnjadovic
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenQuake (deprecated) |
Fix Released
|
High
|
beatpanic |
Bug Description
The main reason we did not make risk calculations available in the June-demo-GUI was the lack of performance in the risk engine. We need to anayse/profile the latter and enhance it by removing the performance issues identified.
Changed in openquake: | |
status: | New → Confirmed |
importance: | Undecided → High |
tags: | added: risk |
tags: | added: performance |
Changed in openquake: | |
milestone: | none → 0.4.1 |
Changed in openquake: | |
milestone: | 0.4.1 → none |
Changed in openquake: | |
milestone: | none → 0.4.2 |
Changed in openquake: | |
assignee: | nobody → beatpanic (kpanic) |
Changed in openquake: | |
status: | Confirmed → In Progress |
Changed in openquake: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
I did some tests on the Classical PSHA calculator, here is a brief description of what I found:
* (this is something related to all calculators) We read the exposure file two times.
The first time we: 1. read the assets inside the region we want to compute and store the related sites 2. split the set of sites in blocks for later processing. (openquake. job.Job. _partition, openquake. job.Job. _read_sites_ from_exposure) . The second time we: 1. read the assets inside the region 2. store the assets in KVS for later processing (openquake. job.general. RiskJobMixin. store_exposure_ assets) .
I think we should do all of this in one pass.
* (this is something related to all calculators) When collecting the sites related to the assets, we save multiple times the same site.
When we collect the sites related to the assets we want to compute (openquake. job.Job. _read_sites_ from_exposure) , if multiple assets are defined on the same site, we save multiple times the same site (lines 281-282). I think we should use a set here, and not a list.
* (this is something related to all calculators) We compute multiple times the same assets.
This is something I haven't proved yet with sample configuration files, but: 1. we collect (and split into blocks) all the sites related to the assets without any particular order. 2. we store the assets in KVS using the grid point as key, i.e.: we translate the site into a grid point using the cell size of the region. This means that all the assets defined on sites falling into the same grid point are stored together (openquake. job.general. RiskJobMixin. store_exposure_ assets, line 127).
Now, let's assume to have:
BLOCK1, with site X that translates into grid point K
BLOCK2, with site Y that translates into grid point K
The sites both translate into the same grid point because they are closer than the cell size of the region.
Since inside the mixins (Classical, Probabilistic and Deterministic) we loop over the grid points defined in the block we are processing (for example openquake. risk.job. classical_ psha.ClassicalP SHABasedMixin. compute_ risk, line 76), we compute two times the assets that fall into grid point K.
* Classical PSHA optimization
The main output of this computation is a loss ratio curve. The inputs are:
- hazard curve, related to the site we use to compute the curve
- vulnerability function, related to the asset we use to compute the curve (that is defined on a specific site)
The scientific module that is able to compute this curve is openquake. risk.classical_ psha_based (the main function is openquake. risk.classical_ psha_based. compute_ loss_ratio_ curve).
I checked the performance of this module without connecting it to all the engine processing (i.e., mixins), and I found that:
- the computation of the LREM (a step to obtain the curve) is complex and thus slow, but can be cached, because it depends just on the vulnerability function (openquake. risk.classical_ psha_based. _compute_ lrem) and many assets share the same function. By slow I mean many seconds.
- with a cached LREM, the computation is reasonably fast, around 20ms on my machine.
I did some tests by simply storing the computed LREMs in memory and I was a...