Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
finesse
pykat
Commits
35db2cb1
Commit
35db2cb1
authored
Apr 15, 2015
by
Andreas Freise
Browse files
Merge branch 'master' of gitmaster.atlas.aei.uni-hannover.de:pykat/pykat
parents
c4e6fb25
38bb369c
Changes
5
Hide whitespace changes
Inline
Side-by-side
examples/asc_test/master.py
View file @
35db2cb1
...
...
@@ -124,6 +124,7 @@ def pd_phase(tmpkat):
# function for root finding
def
PD_q_test
(
x
):
kat
.
PDrefl_q
.
phi1
=
x
out
=
kat
.
run
()
print
(
'
\r
root finding: function value %g '
%
out
.
y
,
end
=
' '
)
sys
.
stdout
.
flush
()
...
...
@@ -131,6 +132,7 @@ def pd_phase(tmpkat):
# do root finding
xtol
=
1e-8
(
result
,
info
)
=
scipy
.
optimize
.
bisect
(
PD_q_test
,
80.0
,
100.0
,
xtol
=
xtol
,
maxiter
=
500
,
full_output
=
True
)
print
(
""
)
...
...
pykat/components.py
View file @
35db2cb1
...
...
@@ -197,9 +197,6 @@ class Component(object):
name
=
str
(
ns
.
node
.
name
)
fget
=
lambda
self
:
self
.
__get_node_setter
(
name
)
if
name
==
"nITM1"
:
print
(
self
.
__class__
)
setattr
(
self
.
__class__
,
name
,
property
(
fget
))
setattr
(
self
,
'__nodesetter_'
+
name
,
ns
)
...
...
pykat/detectors.py
View file @
35db2cb1
...
...
@@ -380,6 +380,7 @@ class bp(Detector1):
return
rtn
id___2
=
0
class
pd
(
Detector1
):
...
...
@@ -387,7 +388,28 @@ class pd(Detector1):
# This creates an instance specific class for the component
# this enables us to add properties to instances rather than
# all classes
return
object
.
__new__
(
type
(
cls
.
__name__
,
(
cls
,),
{}),
*
args
,
**
kwargs
)
global
id___2
id___2
+=
1
cnew_name
=
str
(
"%s.%s_%i"
%
(
cls
.
__module__
,
cls
.
__name__
,
id___2
))
cnew
=
type
(
cnew_name
,
(
cls
,),
{})
return
object
.
__new__
(
cnew
,
*
args
,
**
kwargs
)
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
)
result
.
__set_demod_attrs
()
return
result
def
__init__
(
self
,
name
=
None
,
num_demods
=
1
,
node_name
=
None
,
senstype
=
None
,
alternate_beam
=
False
,
pdtype
=
None
,
**
kwargs
):
BaseDetector
.
__init__
(
self
,
name
,
node_name
)
...
...
@@ -437,24 +459,6 @@ 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
@
property
def
senstype
(
self
):
return
self
.
__senstype
...
...
@@ -486,17 +490,23 @@ class pd(Detector1):
return
getattr
(
self
,
'_pd__'
+
name
)
def
__set_f
(
self
,
num
,
value
):
setattr
(
self
,
'_pd__f'
+
num
,
value
)
value
=
SIfloat
(
value
)
p
=
getattr
(
self
,
'_pd__f'
+
num
)
p
.
value
=
value
def
__set_phi
(
self
,
num
,
value
):
value
=
SIfloat
(
value
)
if
value
==
None
and
num
!=
self
.
num_demods
:
# check if we are setting no phase that this is only on the last
# demodulation phase.
raise
pkex
.
BasePyKatException
(
"Only last demodulation phase can be set to None"
)
elif
isinstance
(
value
,
six
.
string_types
)
and
not
isinstance
(
value
,
float
)
and
value
.
lower
()
!=
"max"
:
raise
pkex
.
BasePyKatException
(
"Demodulation phase can only be set to a 'max' or a number (or None if the last demodulation phase)"
)
setattr
(
self
,
'_'
+
self
.
__class__
.
__name__
+
'__phi'
+
num
,
value
)
p
=
getattr
(
self
,
'_pd__phi'
+
num
)
p
.
value
=
value
def
__set_demod_attrs
(
self
):
"""
...
...
@@ -510,15 +520,20 @@ class pd(Detector1):
if
self
.
__num_demods
>
0
:
for
i
in
range
(
1
,
6
):
name
=
str
(
i
)
if
i
<=
self
.
num_demods
:
if
not
hasattr
(
self
,
"f"
+
name
):
setattr
(
self
.
__class__
,
"f"
+
name
,
property
(
fget
=
lambda
self
,
i
=
i
:
self
.
__get_fphi
(
'f'
+
str
(
i
)),
fset
=
lambda
self
,
value
,
i
=
i
:
self
.
__set_f
(
str
(
i
),
value
)))
fget
=
lambda
self
,
i
=
i
:
self
.
__get_fphi
(
'f'
+
str
(
i
))
fset
=
lambda
self
,
value
,
i
=
i
:
self
.
__set_f
(
str
(
i
),
value
)
setattr
(
self
.
__class__
,
"f"
+
name
,
property
(
fget
=
fget
,
fset
=
fset
))
if
not
hasattr
(
self
,
"phi"
+
name
):
setattr
(
self
.
__class__
,
"phi"
+
name
,
property
(
fget
=
lambda
self
,
i
=
i
:
self
.
__get_fphi
(
'phi'
+
str
(
i
)),
fset
=
lambda
self
,
value
,
i
=
i
:
self
.
__set_phi
(
str
(
i
),
value
)))
else
:
if
hasattr
(
self
,
"f"
+
name
):
delattr
(
self
.
__class__
,
"f"
+
name
)
if
hasattr
(
self
,
"phi"
+
name
):
delattr
(
self
.
__class__
,
"phi"
+
name
)
else
:
...
...
test/test_deepcopying_references.py
View file @
35db2cb1
...
...
@@ -8,7 +8,6 @@ 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
)
...
...
@@ -23,6 +22,29 @@ assert(kat0.m1.n0 != kat1.m1.n0)
assert
(
kat0
.
m1
.
n0
.
node
!=
kat1
.
m1
.
n0
.
node
)
assert
(
kat0
.
nodes
.
n0
!=
kat1
.
nodes
.
n0
)
assert
(
kat0
.
o1
!=
kat1
.
o1
)
assert
(
kat0
.
o1
.
__class__
!=
kat1
.
o1
.
__class__
)
# use is to compare if two params are the same object as equals is override to compare the value
assert
(
kat0
.
o1
.
f1
is
not
kat1
.
o1
.
f1
)
assert
(
kat0
.
o1
.
f1
==
kat1
.
o1
.
f1
)
kat0
.
o1
.
f1
*=
2
kat0
.
o1
.
phi1
*=
2
assert
(
isinstance
(
kat0
.
o1
.
f1
,
pykat
.
param
.
Param
))
assert
(
isinstance
(
kat0
.
o1
.
phi1
,
pykat
.
param
.
Param
))
assert
(
kat0
.
o1
.
f1
!=
kat1
.
o1
.
f1
)
kat1
.
o1
.
num_demods
=
2
assert
(
hasattr
(
kat1
.
o1
,
"f2"
))
assert
(
not
hasattr
(
kat0
.
o1
,
"f2"
))
kat1
.
num_demods
=
1
assert
(
hasattr
(
kat1
.
o1
,
"f1"
))
new
=
kat1
.
nodes
.
createNode
(
"n4"
)
kat1
.
nodes
.
replaceNode
(
kat1
.
m1
,
kat1
.
m1
.
n0
,
new
)
...
...
test/test_properties.py
0 → 100644
View file @
35db2cb1
import
pykat
from
copy
import
deepcopy
kat
=
pykat
.
finesse
.
kat
()
code_det
=
"""
m m1 1 0 0 n0 n1
pd1 pdr 9M 90 n1
"""
kat
.
parseCommands
(
code_det
)
kat
.
pdr
.
f1
=
"0.1k"
assert
(
kat
.
pdr
.
f1
==
100
)
assert
(
type
(
kat
.
pdr
.
f1
)
is
pykat
.
param
.
Param
)
kat
.
pdr
.
phi1
=
"10u"
assert
(
kat
.
pdr
.
phi1
==
1e-5
)
assert
(
type
(
kat
.
pdr
.
phi1
)
is
pykat
.
param
.
Param
)
kat
.
m1
.
R
=
"10000u"
assert
(
kat
.
m1
.
R
==
0.01
)
#################################
kat
=
deepcopy
(
kat
)
kat
.
m1
.
R
=
0.9
assert
(
kat
.
m1
.
R
==
0.9
)
kat
.
pdr
.
phi1
=
20
assert
(
kat
.
pdr
.
phi1
==
20
)
print
"PASSED"
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment