Source code for pycif.plugins.models.template.run
import pandas as pd
import datetime
import os
import shutil
import subprocess
import glob
import numpy as np
from logging import info, debug
[docs]
def run(self, runsubdir, mode, workdir, ddi, nbproc=1, do_simu=True,
approx_transf=False, ref_fwd_dir="", overlap=False, **kwargs):
"""Run the model in forward, tangent-linear or adjoint mode.
This includes:
- executing the model external executable
- updating ``adj_refdir``
- moving files needed for chained simulations to
"{}/../".format(runsubdir)
Note:
For model for which the adjoint is not coded, make sure to return
a clear error if the ``run`` function is called
in ``adj`` mode and with ``do_simu = True``
Args:
self: the model Plugin
runsubdir (str): working directory for the current run
mode (str): forward or backward
workdir (str): pyCIF working directory
do_simu (bool): re-run or not existing simulation
"""
if not do_simu:
# if mode in ["fwd", "tl"]:
# self.adj_refdir = "{}/../".format(runsubdir)
return
with open("{}/log.std".format(runsubdir), "w") as log:
process = subprocess.Popen(
"ls",
cwd=runsubdir,
stdout=log,
stderr=subprocess.PIPE
)
_, stderr = process.communicate()
if stderr != "":
debug("Deal with exception in executable")
# If not running the model, copy expected pre-computed output files
if self.only_outputs:
debug("Here, one should copy reference files from a directory "
"given as argument in the Yaml to $runsubdir: {}"
.format(runsubdir))
# if mode in ["fwd", "tl"]:
# # Adj_refdir is not the runsubdir itself
# # (which corresponds to a sub-simulation)
# # But the level above, which is the full chained simulation
# self.adj_refdir = "{}/../".format(runsubdir)
# Now move necessary files to the chain directory
os.system("mv -f {runsubdir}/XXXXX {runsubdir}/../chain/XXX"
.format(runsubdir=runsubdir))