Skip to content
Snippets Groups Projects
Commit c7ea6bc5 authored by Daniel Brown's avatar Daniel Brown
Browse files

updates

parent 755a17bf
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,8 @@ if USE_GUI:
import pykat.gui.resources
from pykat.gui.graphics import *
id___ = 0
class BaseDetector(object) :
"""
This is a base class for all detectors. Classes Detector1 and Detector2 should be used directly.
......@@ -39,6 +41,18 @@ class BaseDetector(object) :
__metaclass__ = abc.ABCMeta
def __new__(cls, *args, **kwargs):
# This creates an instance specific class for the component
# this enables us to add properties to instances rather than
# all classes
global id___
id___ += 1
cnew_name = str("%s.%s_%i" % (cls.__module__, cls.__name__, id___))
cnew = type(cnew_name, (cls,), {})
return object.__new__(cnew, *args, **kwargs)
def __init__(self, name, nodes=None, max_nodes=1):
self.__name = name
......@@ -82,6 +96,19 @@ class BaseDetector(object) :
else:
raise pkex.BasePyKatException("Nodes should be a list or tuple of node names or a singular node name as a string.")
def __deepcopy__(self, memo):
"""
When deep copying a kat object we need to take into account
the instance specific properties.
"""
# Here we create a copy of this object based of the base class
# of this one, otherwise we're making a copy of a copy of a copy...
result = self.__class__.__new__(self.__class__.__base__)
result.__dict__ = copy.deepcopy(self.__dict__, memo)
return result
def _register_param(self, param):
self._params.append(param)
......@@ -412,20 +439,22 @@ class pd(Detector1):
self.__set_demod_attrs()
def __deepcopy__(self, memo):
"""
When deep copying a kat object we need to take into account
the instance specific properties.
"""
result = pd(self.name, self.num_demods, self.node.name)
memo[id(self)] = result
result.__dict__ = copy.deepcopy(self.__dict__, memo)
# Find all properties in class we are copying
# and deep copy these to the new class instance
for x in self.__class__.__dict__.items():
if isinstance(x[1], property):
setattr(result.__class__, x[0], x[1])
return result
# def __deepcopy__(self, memo):
# """
# When deep copying a kat object we need to take into account
# the instance specific properties.
# """
# result = pd(self.name, self.num_demods, self.node.name)
# memo[id(self)] = result
# result.__dict__ = copy.deepcopy(self.__dict__, memo)
#
# # Find all properties in class we are copying
# # and deep copy these to the new class instance
# for x in self.__class__.__dict__.items():
# if isinstance(x[1], property):
# setattr(result.__class__, x[0], x[1])
#
# return result
@property
def senstype(self): return self.__senstype
......
......@@ -492,7 +492,7 @@ class kat(object):
same properties regardless of whether they have the actual
object added to it. So we create an instance specific class.
"""
result = self.__class__.__new__(self.__class__)
result = self.__class__.__new__(self.__class__.__base__)
memo[id(self)] = result
result.__dict__ = copy.deepcopy(self.__dict__, memo)
......
......@@ -8,6 +8,8 @@ from copy import deepcopy
kat0 = pykat.finesse.kat()
kat0.parseCommands("m m1 1 0 0 n0 n1")
kat0.parseCommands("pd o0 n1")
kat0.parseCommands("pd1 o1 1 0 n1")
kat1 = deepcopy(kat0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment