Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pykat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
finesse
pykat
Commits
c7ea6bc5
Commit
c7ea6bc5
authored
10 years ago
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
updates
parent
755a17bf
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pykat/detectors.py
+44
-15
44 additions, 15 deletions
pykat/detectors.py
pykat/finesse.py
+1
-1
1 addition, 1 deletion
pykat/finesse.py
test/test_deepcopying_references.py
+2
-0
2 additions, 0 deletions
test/test_deepcopying_references.py
with
47 additions
and
16 deletions
pykat/detectors.py
+
44
−
15
View file @
c7ea6bc5
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
pykat/finesse.py
+
1
−
1
View file @
c7ea6bc5
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
test/test_deepcopying_references.py
+
2
−
0
View file @
c7ea6bc5
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment