Commit f043f013 authored by Daniel Brown's avatar Daniel Brown
Browse files

adding in parakat object to run multiple kat objects at once using ipython cluster feature.

parent 04fbb874
......@@ -1107,7 +1107,7 @@ class kat(object):
except pkex.BasePyKatException as ex:
print (ex)
def run(self, printout=0, printerr=0, plot=None, save_output=False, save_kat=False, kat_name=None, cmd_args=None, getTraceData=False):
def run(self, printout=0, printerr=0, plot=None, save_output=False, save_kat=False, kat_name=None, cmd_args=None, getTraceData=False, rethrowExceptions=False):
Runs the current simulation setup that has been built thus far.
It returns a katRun or katRun2D object which is populated with the various
......@@ -1124,6 +1124,8 @@ class kat(object):
that Finesse performs, the keys are the node names and the values
are the x and y beam parameters. If no tracing is done a None
is returned.
rethrowExceptions - if true exceptions will be thrown again rather than being excepted and calling sys.exit()
start =
......@@ -1423,9 +1425,16 @@ class kat(object):
except KeyboardInterrupt as ex:
print("Keyboard interrupt caught, stopped simulation.")
except pkex.FinesseRunError as ex:
pkex.PrintError("Error from Finesse:", ex)
if rethrowExceptions:
raise ex
pkex.PrintError("Error from Finesse:", ex)
except pkex.BasePyKatException as ex:
pkex.PrintError("Error from pykat:", ex)
if rethrowExceptions:
raise ex
pkex.PrintError("Error from pykat:", ex)
if self.verbose: print ("")
if self.verbose: print ("Finished in " + str(
# -*- coding: utf-8 -*-
Created on Sun Jan 27 09:56:53 2013
PyKat - Python interface and wrapper for FINESSE
Copyright (C) 2013 Daniel David Brown
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Contact at
@author: Daniel Brown
from IPython.parallel import Client
import sys
import os
def _run(commands, pwd):
import os
import pykat
kat = pykat.finesse.kat()
out =
return out
class parakat(object):
Uses the ipython clustering for running kat objects in parallel.
To use this you must have started an ipython cluster on your computer.
From a new terminal use the command:
ipcluster start -n 4
This will start a cluster with 4 workers.
To run a kat object use:
pk = parakat()
outs = pk.getResults()
The list 'outs' will contain the katRun object you'd normal get if you
had just called,, etc. The results list is matched to order
in which you run the kats.
If you need to stop long running kat processes the chances are you will
also need to kill the ipython cluster process, as sometimes they carry
on running.
def __init__(self):
self._rc = Client()
self._lview = self._rc.load_balanced_view()
self._lview.block = False
self._results = []
def run(self, kat):
self._results.append(self._lview.apply_async(_run, "".join(kat.generateKatScript()), os.getcwd()))
def getResults(self):
out = []
for done in self._results:
return out
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment