Engine

Engine: A collection of fundamental functions for initializing and running calculations.

exception openquake.engine.engine.InvalidCalculationID[source]

Bases: exceptions.Exception

openquake.engine.engine.check_hazard_risk_consistency(haz_job, risk_mode)[source]

Make sure that the provided hazard job is the right one for the current risk calculator.

Parameters:
  • job – an OqJob instance referring to the previous hazard calculation
  • risk_mode – the calculation_mode string of the current risk calculation
openquake.engine.engine.cleanup_after_job(job, terminate, task_ids=())[source]

Release the resources used by an openquake job. In particular revoke the running tasks (if any).

Parameters:
  • job_id (int) – the job id
  • terminate (bool) – the celery revoke command terminate flag
  • task_ids – celery task IDs
openquake.engine.engine.create_job(calc_mode, user_name='openquake', hc_id=None)[source]

Create job for the given user, return it.

Parameters:
  • calc_mode (str) – Calculation mode, such as classical, event_based, etc
  • username (str) – Username of the user who owns/started this job. If the username doesn’t exist, a user record for this name will be created.
  • hc_id – If not None, then the created job is a risk job
Returns:

openquake.server.db.models.OqJob instance.

openquake.engine.engine.del_calc(job_id)[source]

Delete a calculation and all associated outputs.

Parameters:job_id – ID of a OqJob.
openquake.engine.engine.expose_outputs(dstore, job)[source]

Build a correspondence between the outputs in the datastore and the ones in the database.

Parameters:
  • dstore – a datastore instance
  • job – an OqJob instance
openquake.engine.engine.get_calc_id(job_id=None)[source]

Return the latest calc_id by looking both at the datastore and the database.

openquake.engine.engine.get_outputs(job_id)[source]
Parameters:job_id – ID of a calculation.
Returns:A sequence of openquake.server.db.models.Output objects
openquake.engine.engine.job_from_file(*args, **kwargs)[source]

Create a full job profile from a job config file.

Parameters:
  • cfg_file (str) – Path to the job.ini files.
  • username (str) – The user who will own this job profile and all results.
  • log_level (str) – Desired log level.
  • exports – Comma-separated sting of desired export types
  • hazard_calculation_id – Hazard calculation ID
Params extras:

Extra parameters (used only in the tests to override the params)

Returns:

openquake.server.db.models.OqJob object

Raises:

RuntimeError if the input job configuration is not valid

openquake.engine.engine.list_outputs(job_id, full=True)[source]

List the outputs for a given OqJob.

Parameters:
  • job_id – ID of a calculation.
  • full (bool) – If True produce a full listing, otherwise a short version
openquake.engine.engine.print_outputs_summary(outputs, full=True)[source]

List of openquake.server.db.models.Output objects.

openquake.engine.engine.print_results(job_id, duration, list_outputs)[source]
openquake.engine.engine.run_calc(job, log_level, log_file, exports, hazard_calculation_id=None)[source]

Run a calculation.

Parameters:
  • jobopenquake.server.db.model.OqJob instance
  • log_level (str) – The desired logging level. Valid choices are ‘debug’, ‘info’, ‘progress’, ‘warn’, ‘error’, and ‘critical’.
  • log_file (str) – Complete path (including file name) to file where logs will be written. If None, logging will just be printed to standard output.
  • exports – A comma-separated string of export types.
openquake.engine.engine.run_job(cfg_file, log_level, log_file, exports='', hazard_calculation_id=None)[source]

Run a job using the specified config file and other options.

Parameters:
  • cfg_file (str) – Path to calculation config (INI-style) files.
  • log_level (str) – ‘debug’, ‘info’, ‘warn’, ‘error’, or ‘critical’
  • log_file (str) – Path to log file.
  • exports – A comma-separated string of export types requested by the user. Currently only ‘xml’ is supported.