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

fixing fsig target, adding in batch processor for multiple kat objects

parent 5b47eae8
...@@ -25,33 +25,31 @@ qd tran_Q 0 90 n4 ...@@ -25,33 +25,31 @@ qd tran_Q 0 90 n4
qnoised qnd 1 $fs max n4 qnoised qnd 1 $fs max n4
qshot qsd 1 $fs max n4 qshot qsd 1 $fs max n4
pd1 p1 $fs max n4
yaxis log re:im pd1 p1 $fs max n4
fsig noise m2 1 0 fsig noise l1 amp 1 0
""" """
kat = finesse.kat(kat_code=code) kat = finesse.kat(kat_code=code)
kat.removeLine("fsig noise 9") # kat.signals.apply(kat.m2.z, 1.0, 0.0)
# kat.yaxis = "re:im"
kat.signals.apply(kat.l1.P, 1, 0) # kat.add(xaxis('log', [1, 1000], kat.signals.f, 1000))
kat.signals.apply(kat.m1.phi, 1, 90) #
# out = kat.run(printout=0, printerr=0)
kat.add(xaxis('log', [1, 1000], kat.signals.f, 100)) #
# a_up = out[kat.up_refl]
out = kat.run(printout=0, printerr=0) # a_lo = out[kat.low_refl]
#
# using real and imag part compute the complex value of the upper and lower sidebands # pl.figure(1)
a_up = out.y[:,0] + out.y[:,1]*1j # ax = pl.subplot(111)
a_lo = out.y[:,2] + out.y[:,3]*-1j # pl.grid()
# ax.loglog(out.x, abs(a_up))
pl.figure(1) # ax = ax.twinx()
pl.loglog(out.x, out["p1"]) # ax.plot(out.x, np.rad2deg(np.angle(a_up)), 'r')
pl.xlabel(out.xlabel) # pl.xlabel(out.xlabel)
pl.title("Reflection quadratures with no relative carrier phase")
pl.legend(["Amplitude","Phase"]) #pl.show()
pl.show() print(kat.generateKatScript())
kat.remove(kat.signals)
kat.remove(kat.signals)
\ No newline at end of file
...@@ -181,7 +181,47 @@ def f__lkat_trace_callback(lkat, trace_info, getCavities, getNodes, getSpaces): ...@@ -181,7 +181,47 @@ def f__lkat_trace_callback(lkat, trace_info, getCavities, getNodes, getSpaces):
trace_info[space.name] = space_trace(gouyx = space.gouy_x, trace_info[space.name] = space_trace(gouyx = space.gouy_x,
gouyy = space.gouy_y) gouyy = space.gouy_y)
class KatBatch(object):
"""
"""
def __init__(self):
from IPython.parallel import Client
self._c = Client()
self._lb = c.load_balanced_view()
self.lb.block = False
self._todo = []
def _run(dir, commands, **kwargs):
import pykat
kat = pykat.finesse.kat()
kat.verbose = False
kat.parseCommands(commands)
kw = dict()
if "cmd_args" in kwargs:
kw["cmd_args"] = kwargs["cmd_args"]
return kat.run(printerr=1, **kw)
def addKat(self, kat, **kwargs):
import os
cdir = os.getcwd()
script = "\n".join(kat.generateKatScript())
self.todo.append(self.lb.apply_async(self._run, script, **kwargs))
return self.todo[-1]
def wait(self):
return self.lb.wait(self.todo)
def results(self):
return self.todo
def GUILength(L): def GUILength(L):
""" """
Should scale the lengths in some way to handle km and mm for time being Should scale the lengths in some way to handle km and mm for time being
...@@ -971,7 +1011,7 @@ class kat(object): ...@@ -971,7 +1011,7 @@ class kat(object):
if comp._default_fsig() is None: if comp._default_fsig() is None:
raise pkex.BasePyKatException("Component '{0}' cannot be fsig'd. Line: '{1}'".format(comp.name, line)) raise pkex.BasePyKatException("Component '{0}' cannot be fsig'd. Line: '{1}'".format(comp.name, line))
param = None param_name = None
amp = None amp = None
if len(v) == 5: if len(v) == 5:
...@@ -984,11 +1024,12 @@ class kat(object): ...@@ -984,11 +1024,12 @@ class kat(object):
phase = float(v[4]) phase = float(v[4])
amp = float(v[5]) amp = float(v[5])
else: else:
param = v[3] param_name = v[3]
freq = float(v[4]) freq = float(v[4])
phase = float(v[5]) phase = float(v[5])
elif len(v) == 7: elif len(v) == 7:
param = v[3] param_name = v[3]
freq = float(v[4]) freq = float(v[4])
phase = float(v[5]) phase = float(v[5])
amp = float(v[6]) amp = float(v[6])
...@@ -996,7 +1037,17 @@ class kat(object): ...@@ -996,7 +1037,17 @@ class kat(object):
raise pkex.BasePyKatException("'{0}' isnot a valid fsig command".format(line)) raise pkex.BasePyKatException("'{0}' isnot a valid fsig command".format(line))
self.signals.f = freq self.signals.f = freq
self.signals.apply(comp._default_fsig(), amp, phase, name)
if param_name is None:
param = comp._default_fsig()
else:
for p in comp._params:
if p.canFsig and p.fsigName == param_name:
param = p
break
self.signals.apply(param, amp, phase, name)
else: else:
raise pkex.BasePyKatException("Haven't handled parsing of '{0}'".format(line)) raise pkex.BasePyKatException("Haven't handled parsing of '{0}'".format(line))
...@@ -1022,15 +1073,6 @@ class kat(object): ...@@ -1022,15 +1073,6 @@ class kat(object):
except pkex.BasePyKatException as ex: except pkex.BasePyKatException as ex:
print (ex) print (ex)
def getProcess(self, callback, **kwargs):
"""
"""
cmd = "\n".join(self.generateKatScript())
return Process(target=f__lkat_process, args=(callback, cmd, kwargs))
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):
""" """
Runs the current simulation setup that has been built thus far. Runs the current simulation setup that has been built thus far.
...@@ -1404,7 +1446,7 @@ class kat(object): ...@@ -1404,7 +1446,7 @@ class kat(object):
except pkex.BasePyKatException as ex: except pkex.BasePyKatException as ex:
pkex.PrintError("Error on removing object:", ex) pkex.PrintError("Error on removing object:", ex)
def undumpNodes(self): def undumpNodes(self, undumped_name_prefix = "dump"):
""" """
Loops through and removes all dump nodes. Required when running quantum noise Loops through and removes all dump nodes. Required when running quantum noise
calculations using qnoised as noise must be injected in where losses occur, such as power calculations using qnoised as noise must be injected in where losses occur, such as power
...@@ -1416,13 +1458,13 @@ class kat(object): ...@@ -1416,13 +1458,13 @@ class kat(object):
""" """
i = 0 i = 0
node_name = "dump%i" % i node_name = "%s_%i" % (str(undumped_name_prefix), i)
for c in self.components.values(): for c in self.components.values():
for n in c.nodes: for n in c.nodes:
if n.isDump: if n.isDump:
while hasattr(kat.nodes, node_name): while hasattr(kat.nodes, node_name):
node_name = "dump%i" % i node_name = "%s_%i" % (str(undumped_name_prefix), i)
i += 1 i += 1
self.nodes.replaceNode(c, n, self.nodes.createNode(node_name % i)) self.nodes.replaceNode(c, n, self.nodes.createNode(node_name % i))
...@@ -1950,8 +1992,17 @@ class kat(object): ...@@ -1950,8 +1992,17 @@ class kat(object):
rtn.append(name) rtn.append(name)
return rtn return rtn
def _lkat_getProcess(self, callback, **kwargs):
"""
"""
cmd = "\n".join(self.generateKatScript())
def lkat_trace(self, getCavities=True, getNodes=True, getSpaces=True): return Process(target=f__lkat_process, args=(callback, cmd, kwargs))
def _lkat_trace(self, getCavities=True, getNodes=True, getSpaces=True):
""" """
Given the current state of the kat object a new FINESSE process is called and just Given the current state of the kat object a new FINESSE process is called and just
the beam tracing routine is run. The object that is returned contains all the information the beam tracing routine is run. The object that is returned contains all the information
......
...@@ -111,6 +111,9 @@ class Param(putable, putter): ...@@ -111,6 +111,9 @@ class Param(putable, putter):
@property @property
def fsig_name(self): return self.__fsig_name def fsig_name(self): return self.__fsig_name
@property
def fsigName(self): return self.__fsig_name
@property @property
def name(self): return self._name def name(self): return self._name
......
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