Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'ipython' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
directory = dirname(interactive.jobfolder_path)
job = interactive.jobfolder
name = interactive.jobfolder.name[1:]
if job.functional is None:
print("Current jobfolder does not contain any calculation.")
return
# avoid successful jobs.unless specifically requested
if hasattr(job.functional, 'Extract') and not event.force:
p = join(directory, name)
extract = job.functional.Extract(p)
if extract.success:
print("Job {0} completed successfully. " \
"It will not be relaunched.".format(name))
return
# now creates script
pbsargs['n'] = get_mppalloc(shell, event, False)
pbsargs['nnodes'] = (pbsargs['n'] + pbsargs['ppn'] - 1) \
// pbsargs['ppn']
pbsargs['err'] = pbspaths(directory, name, 'err')
pbsargs['out'] = pbspaths(directory, name, 'out')
pbsargs['name'] = name if len(name) \
else "{0}-root".format(basename(path))
pbsargs['directory'] = directory
pbsargs['header'] = ""
pbsargs['header'] += '\nexport PYLADA_JOBARRAY_NAME={0!r}\n'.format(name)
pbsargs['scriptcommand'] = "{0} --nbprocs {n} --ppn {ppn} {1} " \
.format(pyscript, path, **pbsargs)
pbsscript = pbspaths(directory, name, 'script')
local_path(directory).join(name).ensure(dir=True)
with open(pbsscript, "w") as file:
string = pbs_string(**pbsargs) if hasattr(pbs_string, '__call__') \
def pbspaths(directory, jobname, suffix):
""" creates filename paths. """
suffix = '{0}-pbs{1}'.format(event.prefix, suffix) if hasprefix \
else 'pbs{0}'.format(suffix)
return str(directory.join(jobname, suffix))
# now loop over jobfolders
pbsscripts = []
for current, path in jobfolders:
logger.info("launch/scattered: current: %s path: %s" % (current, path))
# creates directory.
directory = local_path(path).dirpath()
directory.ensure(dir=True)
# loop over executable folders in current jobfolder
for name, job in current.root.items():
logger.info('launch/scattered: current: %s' % current)
logger.info('launch/scattered: current.root: %s' % current.root)
logger.info('launch/scattered: name: %s' % name)
logger.info('launch/scattered: job: %s' % job)
logger.info('launch/scattered: job.is_tagged: %s' % job.is_tagged)
# avoid jobfolder which are off
if job.is_tagged:
continue
# added by Peter Graf
# avoid jobfolder which is already in the queue:
qstuff = qstat(name)
if (len(qstuff) > 0 and not event.force):
status = [x.split()[2] for x in qstuff]
# status is a list like ['Q'], ['R'], ['H'], ['C'], ['R', 'C'], etc
# 'RHQ' is the status that the job is indeed in the queue, 'C' job completed and
# being removed from the queue if needed, a prefix can be used to distinguish two
def goto(self, cmdl):
""" Moves current dictionary position and working directory (if appropriate). """
from os import chdir
from os.path import exists, join, split as splitpath, isdir
from .explore import explore
from . import get_shell
from pylada import interactive
shell = get_shell(self)
if interactive.jobfolder is None:
print("No current job-folders.")
return
if len(cmdl.split()) == 0:
if interactive.jobfolder_path is None:
print("Current position in job folder:", interactive.jobfolder.name)
else:
print("Current position in job folder:", interactive.jobfolder.name)
print("Filename of job-folder: ", interactive.jobfolder_path)
return
args = cmdl.split()
if len(args) > 1:
print("Invalid argument to goto {0}.".format(cmdl))
return
return
if len(cmdl.split()) == 0:
if interactive.jobfolder_path is None:
print("Current position in job folder:", interactive.jobfolder.name)
else:
print("Current position in job folder:", interactive.jobfolder.name)
print("Filename of job-folder: ", interactive.jobfolder_path)
return
args = cmdl.split()
if len(args) > 1:
print("Invalid argument to goto {0}.".format(cmdl))
return
# if no argument, then print current job data.
if len(args) == 0:
explore(self, "")
return
# cases to send to iterate.
if args[0] == "next":
return iterate(self, "")
elif args[0] == "previous":
return iterate(self, "previous")
elif args[0] == "reset":
return iterate(self, "reset")
# case for which precise location is given.
try:
result = interactive.jobfolder[args[0]]
except KeyError as e:
print(e)
return
from .asone import completer as asone_completer
from .array import completer as array_completer
from .single import completer as single_completer
from ... import qsub_array_exe
data = info.line.split()[1:]
if "scattered" in data:
return scattered_completer(self, info, data)
elif "interactive" in data:
return interactive_completer(self, info, data)
elif "asone" in data:
return asone_completer(self, info, data)
elif "single" in data:
return single_completer(self, info, data)
elif qsub_array_exe is not None and "array" in data:
return array_completer(self, info, data)
result = ["scattered", "interactive", 'asone', 'single', '--help']
return result + ['array'] if qsub_array_exe is not None else result
help='Optional path to a job-folder. If not present, the '
'currently loaded job-dictionary will be launched.')
opalls.add_argument('--force', action="store_true", dest="force",
help="If present, launches all untagged jobs, even those "
"which completed successfully.")
# subparsers
subparsers \
= parser.add_subparsers(help='Launches one job per untagged calculations')
# launch scattered.
scattered_parser(self, subparsers, opalls)
interactive_parser(self, subparsers, opalls)
asone_parser(self, subparsers, opalls)
single_parser(self, subparsers, opalls)
if qsub_array_exe is not None:
array_parser(self, subparsers, opalls)
# parse arguments
try:
args = parser.parse_args(event.split())
except SystemExit as e:
return None
# creates list of dictionaries.
jobfolders = []
if args.pickle != '':
for pickle in args.pickle:
pickle = RelativePath(pickle).path
try:
d = load_jobs(path=pickle, timeout=20)
except ImportError as e:
print("ImportError: ", e)
try:
mppalloc = shell.ev(event.nbprocs)
except Exception as e:
print(("Could not make sense of --nbprocs argument {0}.\n{1}" \
.format(event.nbprocs, e)))
return
logger.info("launch/init: mppalloc a: %s" % mppalloc)
if mppalloc is None and withdefault:
def mppalloc(job):
""" Returns number of processes for this job. """
natom = len(job.structure) # number of atoms.
# Round down to a multiple of ppn
nnode = max(1, natom / event.ppn)
nproc = nnode * event.ppn
return nproc
logger.info("launch/init: mppalloc b: %s" % mppalloc)
return mppalloc
def get_mppalloc(shell, event, withdefault=True):
""" Gets mpp allocation. """
from .. import logger
logger.info("launch/init: shell: %s" % shell)
logger.info("launch/init: event: %s" % event)
logger.info("launch/init: event.ppn: %s" % event.ppn)
logger.info("launch/init: withdefault: %s" % withdefault)
try:
mppalloc = shell.ev(event.nbprocs)
except Exception as e:
print(("Could not make sense of --nbprocs argument {0}.\n{1}" \
.format(event.nbprocs, e)))
return
logger.info("launch/init: mppalloc a: %s" % mppalloc)
if mppalloc is None and withdefault:
def mppalloc(job):
""" Returns number of processes for this job. """
natom = len(job.structure) # number of atoms.
# Round down to a multiple of ppn
nnode = max(1, natom / event.ppn)
job.tag()
# running jobs are not errors either.
else:
is_run = getattr(extract, 'is_running', False)
if is_run:
job.tag()
qstuff = self.qstat(name)
is_inqueue = len(qstuff) > 0
if is_inqueue:
job.tag()
# what's left is an error.
else:
job.untag()
logger.debug('ipython/explore errors: dir: %s is_run: %s' % (directory, is_run))
# Look only for jobs which are successfull.
if args.type == "results":
if interactive.jobfolder_path is None:
print("No known path/file for current job-folder.\n"\
"Please save to file first.")
return
directory = dirname(interactive.jobfolder_path)
for name, job in interactive.jobfolder.items():
if not job.functional.Extract(join(directory, name)).success:
job.tag()
else:
job.untag()
# Look only for jobs which are running (and can be determined as such).
elif args.type == "running":
# ['checkjob', str(job.jobNumber)],
# shell=False,
# cwd=wkDir,
# stdin=subprocess.PIPE,
# stdout=subprocess.PIPE,
# stderr=subprocess.PIPE,
# bufsize=10*1000*1000)
# (stdout, stderr) = proc.communicate()
# parse stdout to get status. May be 'not found'.
# if idle or active: job.untag()
# else: job.tag()
job.untag()
else:
job.tag()
logger.debug('ipython/explore running: dir: %s is_run: %s' % (directory, is_run))
# All jobs without restriction.
elif args.type == "all":
if interactive.jobfolder_path is None:
return
for job in interactive.jobfolder.values():
job.untag()