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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
finesse
pykat
Commits
e22a9bc4
Commit
e22a9bc4
authored
10 years ago
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
fixing pd properties
parent
c7ea6bc5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/asc_test/master.py
+3
-0
3 additions, 0 deletions
examples/asc_test/master.py
pykat/components.py
+0
-3
0 additions, 3 deletions
pykat/components.py
pykat/detectors.py
+38
-23
38 additions, 23 deletions
pykat/detectors.py
test/test_properties.py
+33
-0
33 additions, 0 deletions
test/test_properties.py
with
74 additions
and
26 deletions
examples/asc_test/master.py
+
3
−
0
View file @
e22a9bc4
...
@@ -124,6 +124,8 @@ def pd_phase(tmpkat):
...
@@ -124,6 +124,8 @@ def pd_phase(tmpkat):
# function for root finding
# function for root finding
def
PD_q_test
(
x
):
def
PD_q_test
(
x
):
kat
.
PDrefl_q
.
phi1
=
x
kat
.
PDrefl_q
.
phi1
=
x
print
(
"
\n
!!!!!!
"
,
kat
.
PDrefl_q
.
phi1
,
x
)
out
=
kat
.
run
()
out
=
kat
.
run
()
print
(
'
\r
root finding: function value %g
'
%
out
.
y
,
end
=
'
'
)
print
(
'
\r
root finding: function value %g
'
%
out
.
y
,
end
=
'
'
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
...
@@ -131,6 +133,7 @@ def pd_phase(tmpkat):
...
@@ -131,6 +133,7 @@ def pd_phase(tmpkat):
# do root finding
# do root finding
xtol
=
1e-8
xtol
=
1e-8
(
result
,
info
)
=
scipy
.
optimize
.
bisect
(
PD_q_test
,
80.0
,
100.0
,
xtol
=
xtol
,
maxiter
=
500
,
full_output
=
True
)
(
result
,
info
)
=
scipy
.
optimize
.
bisect
(
PD_q_test
,
80.0
,
100.0
,
xtol
=
xtol
,
maxiter
=
500
,
full_output
=
True
)
print
(
""
)
print
(
""
)
...
...
This diff is collapsed.
Click to expand it.
pykat/components.py
+
0
−
3
View file @
e22a9bc4
...
@@ -198,9 +198,6 @@ class Component(object):
...
@@ -198,9 +198,6 @@ class Component(object):
name
=
str
(
ns
.
node
.
name
)
name
=
str
(
ns
.
node
.
name
)
fget
=
lambda
self
:
self
.
__get_node_setter
(
name
)
fget
=
lambda
self
:
self
.
__get_node_setter
(
name
)
if
name
==
"
nITM1
"
:
print
(
self
.
__class__
)
setattr
(
self
.
__class__
,
name
,
property
(
fget
))
setattr
(
self
.
__class__
,
name
,
property
(
fget
))
setattr
(
self
,
'
__nodesetter_
'
+
name
,
ns
)
setattr
(
self
,
'
__nodesetter_
'
+
name
,
ns
)
...
...
This diff is collapsed.
Click to expand it.
pykat/detectors.py
+
38
−
23
View file @
e22a9bc4
...
@@ -380,6 +380,7 @@ class bp(Detector1):
...
@@ -380,6 +380,7 @@ class bp(Detector1):
return
rtn
return
rtn
id___2
=
0
class
pd
(
Detector1
):
class
pd
(
Detector1
):
...
@@ -387,7 +388,28 @@ class pd(Detector1):
...
@@ -387,7 +388,28 @@ class pd(Detector1):
# This creates an instance specific class for the component
# This creates an instance specific class for the component
# this enables us to add properties to instances rather than
# this enables us to add properties to instances rather than
# all classes
# 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
):
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
)
BaseDetector
.
__init__
(
self
,
name
,
node_name
)
...
@@ -438,24 +460,6 @@ class pd(Detector1):
...
@@ -438,24 +460,6 @@ class pd(Detector1):
self
.
__set_demod_attrs
()
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
@property
def
senstype
(
self
):
return
self
.
__senstype
def
senstype
(
self
):
return
self
.
__senstype
@senstype.setter
@senstype.setter
...
@@ -486,9 +490,14 @@ class pd(Detector1):
...
@@ -486,9 +490,14 @@ class pd(Detector1):
return
getattr
(
self
,
'
_pd__
'
+
name
)
return
getattr
(
self
,
'
_pd__
'
+
name
)
def
__set_f
(
self
,
num
,
value
):
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
):
def
__set_phi
(
self
,
num
,
value
):
value
=
SIfloat
(
value
)
if
value
==
None
and
num
!=
self
.
num_demods
:
if
value
==
None
and
num
!=
self
.
num_demods
:
# check if we are setting no phase that this is only on the last
# check if we are setting no phase that this is only on the last
# demodulation phase.
# demodulation phase.
...
@@ -496,7 +505,8 @@ class pd(Detector1):
...
@@ -496,7 +505,8 @@ class pd(Detector1):
elif
isinstance
(
value
,
six
.
string_types
)
and
not
isinstance
(
value
,
float
)
and
value
.
lower
()
!=
"
max
"
:
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)
"
)
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
):
def
__set_demod_attrs
(
self
):
"""
"""
...
@@ -510,15 +520,20 @@ class pd(Detector1):
...
@@ -510,15 +520,20 @@ class pd(Detector1):
if
self
.
__num_demods
>
0
:
if
self
.
__num_demods
>
0
:
for
i
in
range
(
1
,
6
):
for
i
in
range
(
1
,
6
):
name
=
str
(
i
)
name
=
str
(
i
)
if
i
<=
self
.
num_demods
:
if
i
<=
self
.
num_demods
:
if
not
hasattr
(
self
,
"
f
"
+
name
):
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
):
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
)))
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
:
else
:
if
hasattr
(
self
,
"
f
"
+
name
):
if
hasattr
(
self
,
"
f
"
+
name
):
delattr
(
self
.
__class__
,
"
f
"
+
name
)
delattr
(
self
.
__class__
,
"
f
"
+
name
)
if
hasattr
(
self
,
"
phi
"
+
name
):
if
hasattr
(
self
,
"
phi
"
+
name
):
delattr
(
self
.
__class__
,
"
phi
"
+
name
)
delattr
(
self
.
__class__
,
"
phi
"
+
name
)
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
test/test_properties.py
0 → 100644
+
33
−
0
View file @
e22a9bc4
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
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