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

exception openquake.engine.engine.InvalidHazardCalculationID[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.

  • 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)[source]

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

  • job_id (int) – the job id
  • terminate (bool) – the celery revoke command terminate flag
openquake.engine.engine.create_job(user_name='openquake', log_level='progress')[source]

Create job for the given user, return it.

  • 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.
  • log_level (str) – Defaults to ‘progress’. Specify a logging level for this job. This level can be passed, for example, from the command line interface using the –log-level directive.

openquake.engine.db.models.OqJob instance.


Delete a calculation and all associated outputs.

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

Create a full job profile from a job config file.

  • cfg_file_path (str) – Path to the job.ini.
  • 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_output_id (int) – ID of a hazard output to use as input to this calculation. Specify this xor hazard_calculation_id.
  • hazard_calculation_id (int) – ID of a complete hazard job to use as input to this calculation. Specify this xor hazard_output_id.
Params extras:

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


openquake.engine.db.models.OqJob object


RuntimeError if the input job configuration is not valid

openquake.engine.engine.job_stats(*args, **kwds)[source]

A context manager saving information such as the number of sites and the disk space occupation in the job_stats table. The information is saved at the end of the job, even if the job fails.

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

List the outputs for a given OqJob.

  • job_id – ID of a calculation.
  • full (bool) – If True produce a full listing, otherwise a short version
openquake.engine.engine.log_status(job, status)[source]

Switch to a particular phase of execution.

  • job – An OqJob instance.
  • job_type (str) – calculation type (hazard|risk)
  • status (str) – one of the following: pre_executing, executing, post_executing, post_processing, export, clean_up, complete
openquake.engine.engine.print_outputs_summary(outputs, full=True)[source]

List of openquake.engine.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)[source]

Run a calculation.

  • jobopenquake.engine.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_output_id=None, hazard_calculation_id=None)[source]

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

  • cfg_file (str) – Path to calculation config (INI-style) file.
  • 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.
  • hazard_ouput_id (str) – The Hazard Output ID used by the risk calculation (can be None)
  • hazard_calculation_id (str) – The Hazard Job ID used by the risk calculation (can be None)

If a log file destination is specified, attempt to open the file in ‘append’ mode (‘a’). If the specified file is not writable, an IOError will be raised.