Engine¶
Engine: A collection of fundamental functions for initializing and running calculations.
-
class
openquake.engine.engine.
EnginePerformanceMonitor
(operation, hdf5path=None, autoflush=False, measuremem=False)[source]¶ Bases:
openquake.baselib.performance.PerformanceMonitor
PerformanceMonitor that writes both in the datastore and in the database
-
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
(user_name='openquake', log_level='progress', hc_id=None)[source]¶ Create job for the given user, return it.
Parameters: - 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.
- 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_output_id – Hazard output ID
- hazard_calculation_id – Hazard calculation ID
Params extras: Extra parameters (used only in the tests to override the params)
Returns: Raises: 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 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
.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.
run_calc
(job, log_level, log_file, exports, hazard_calculation_id=None)[source]¶ Run a calculation.
Parameters: - job –
openquake.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.
- job –
-
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.
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.