classical_psha_based_risk demo is broken

Bug #901091 reported by Muharem Hrnjadovic
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenQuake (deprecated)
Fix Released
Critical
Lars Butler

Bug Description

The root cause of the breakage appears to be that the hazard curve's
'statistic_type' is NULL but the risk code in question
(ClassicalPSHABasedMixin._get_db_curve()) expects it to be set to 'mean'.
Maybe the mean hazard curve is not being written to the database?

This is from openquake/risk/job/classical_psha.py, line 72

        hc = models.HazardCurveData.objects.filter(
            hazard_curve__output__oq_job=job,
            hazard_curve__statistic_type='mean').extra(
            where=["ST_GeoHash(location, 12) = %s"], params=[gh]).get()

I checked the geohash and it seems to be correct.

openquake=# SELECT * FROM hzrdr.hazard_curve WHERE output_id=509
 id | output_id | end_branch_label | statistic_type | quantile
-----+-----------+------------------+----------------+----------
 215 | 509 | 0 | |

openquake=# SELECT * FROM hzrdr.hazard_curve_data WHERE hazard_curve_id=215 AND ST_GeoHash(location, 12)='sqg1c4mr6jqf'
  id | hazard_curve_id | poes | location
------+-----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------
 9369 | 215 | {1,0.999999999999453,0.999999999548169,0.999999836608758,0.99997616150681,0.998842529677148,0.981856818337621,0.889990232703232,0.68045118835525,0.429341652777471,0.226848426506306,0.106924265907651,0.0451297161821955,0.0167622312848525,0.00520462897461305,0.00126037470418106,0.000214021103311146,1.58934217476814e-05,0} | 0101000020E61000000AD7A3703D0A2F4085EB51B81E254340

Changed in openquake:
status: New → Confirmed
importance: Undecided → High
tags: added: broken-test defect
John Tarter (toh2)
Changed in openquake:
status: Confirmed → In Progress
importance: High → Critical
milestone: none → 0.5.0
assignee: nobody → Lars Butler (lars-butler)
Revision history for this message
Lars Butler (lars-butler) wrote :

Here's the problem:

A few weeks ago, mean hazard curves were always being computed (even if the param COMPUTE_MEAN_HAZARD_CURVE was set to false). So we fixed the bug and the redundant computations are no longer happening.

This is what caused the bug to surface.

When the Classical Risk calculator computes loss ratio curves for a given asset + location, a hazard curve is required to do the calculation. The hazard curve used should be the mean curve of the hazard curve computed for the site of interest over N logic tree samples. The loss ratio curve calculation function queries the database for a mean hazard at the given site.

The classical_psha_based_risk demo specifies the COMPUTE_MEAN_HAZARD_CURVE parameter as false. So, when the database is queried for the mean hazard curve (at any site), the curve doesn't exist and the calculation blows up.

Here's what we need to do to fix it:

1) For Classical Risk calculations, COMPUTE_MEAN_HAZARD_CURVE should always be 'true' (according to Vitor).
2) We need appropriate database and job config constraints to enforce this rule. The rule is: if calculation mode is "classical" and job type is Hazard + Risk, then COMPUTE_MEAN_HAZARD_CURVE (a Hazard parameter) should always be 'true'. If it is specified in the config, it should be ignored and the software provide a default.
3) In the database, we are recording the 'job_type' in the oq_params table. This is really 'calc_mode' and should be renamed as such.
4) Once the existing 'job_type' is renamed to 'calc_mode', a new 'job_type' parameter should be introduced to record the type of the job, which at present is 'hazard' and/or 'risk'. This field should be a VARCHAR[] and should <= ['hazard', 'risk'] (one and/or the other).
5) Make any changes necessary to job config validation. I can't think of anything, but we may have to change something.
6) Finally, write a QA test that exercises this demo and validates the computed risk and hazard artifacts (curves, map, etc.).

Revision history for this message
Lars Butler (lars-butler) wrote :

Pull requests (so far):
https://github.com/gem/openquake/pull/612
https://github.com/gem/openquake/pull/613
https://github.com/gem/openquake/pull/614

The final pull request will introduce a QA test to prevent this demo from breaking (without our knowledge) in the future.

Revision history for this message
Lars Butler (lars-butler) wrote :

I have sent an e-mail to Vitor Silva to request QA test data.

tags: added: enduser-visible faq
John Tarter (toh2)
Changed in openquake:
milestone: 0.5.0 → 0.5.1
Revision history for this message
Lars Butler (lars-butler) wrote :

The QA test for this demo has been requested in a separate bug. I'm going to mark this as resolved.

See: https://bugs.launchpad.net/openquake/+bug/909381

Changed in openquake:
status: In Progress → Fix Committed
Changed in openquake:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.