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
Sebastian Steinlechner
pykat
Commits
37d6fe82
Commit
37d6fe82
authored
Jul 27, 2015
by
Daniel Toyra
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitmaster.atlas.aei.uni-hannover.de:pykat/pykat
parents
20ffb193
7ade3ecd
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
pykat/components.py
+16
-5
16 additions, 5 deletions
pykat/components.py
pykat/finesse.py
+14
-5
14 additions, 5 deletions
pykat/finesse.py
pykat/optics/maps.py
+5
-3
5 additions, 3 deletions
pykat/optics/maps.py
pykat/parallel.py
+89
-0
89 additions, 0 deletions
pykat/parallel.py
with
124 additions
and
13 deletions
pykat/components.py
+
16
−
5
View file @
37d6fe82
...
@@ -901,13 +901,14 @@ class grating(Component):
...
@@ -901,13 +901,14 @@ class grating(Component):
return
self
.
_svgItem
return
self
.
_svgItem
class
isolator
(
Component
):
class
isolator
(
Component
):
def
__init__
(
self
,
name
,
node1
,
node2
,
S
=
0
,
node3
=
"
dump
"
):
def
__init__
(
self
,
name
,
node1
,
node2
,
S
=
0
,
node3
=
"
dump
"
,
option
=
0
):
Component
.
__init__
(
self
,
name
)
Component
.
__init__
(
self
,
name
)
self
.
_requested_node_names
.
append
(
node1
)
self
.
_requested_node_names
.
append
(
node1
)
self
.
_requested_node_names
.
append
(
node2
)
self
.
_requested_node_names
.
append
(
node2
)
self
.
_requested_node_names
.
append
(
node3
)
self
.
_requested_node_names
.
append
(
node3
)
self
.
_svgItem
=
None
self
.
_svgItem
=
None
self
.
_option
=
option
self
.
__S
=
Param
(
"
S
"
,
self
,
SIfloat
(
S
))
self
.
__S
=
Param
(
"
S
"
,
self
,
SIfloat
(
S
))
...
@@ -920,20 +921,30 @@ class isolator(Component):
...
@@ -920,20 +921,30 @@ class isolator(Component):
def
parseFinesseText
(
text
):
def
parseFinesseText
(
text
):
values
=
text
.
split
()
values
=
text
.
split
()
if
values
[
0
]
!=
"
isol
"
:
if
values
[
0
]
!=
"
isol
"
and
values
[
0
]
!=
"
isol*
"
:
raise
pkex
.
BasePyKatException
(
"'
{0}
'
not a valid Finesse isolator command
"
.
format
(
text
))
raise
pkex
.
BasePyKatException
(
"'
{0}
'
not a valid Finesse isolator command
"
.
format
(
text
))
if
values
[
0
].
endswith
(
'
*
'
):
option
=
1
else
:
option
=
0
values
.
pop
(
0
)
# remove initial value
values
.
pop
(
0
)
# remove initial value
if
len
(
values
)
==
4
:
if
len
(
values
)
==
4
:
return
isolator
(
values
[
0
],
values
[
2
],
values
[
3
],
values
[
1
])
return
isolator
(
values
[
0
],
values
[
2
],
values
[
3
],
values
[
1
]
,
option
=
option
)
elif
len
(
values
)
==
5
:
elif
len
(
values
)
==
5
:
return
isolator
(
values
[
0
],
values
[
2
],
values
[
3
],
node3
=
values
[
4
],
S
=
values
[
1
])
return
isolator
(
values
[
0
],
values
[
2
],
values
[
3
],
node3
=
values
[
4
],
S
=
values
[
1
]
,
option
=
option
)
else
:
else
:
raise
pkex
.
BasePyKatException
(
"
Isolator Finesse code format incorrect
'
{0}
'"
.
format
(
text
))
raise
pkex
.
BasePyKatException
(
"
Isolator Finesse code format incorrect
'
{0}
'"
.
format
(
text
))
def
getFinesseText
(
self
):
def
getFinesseText
(
self
):
rtn
=
[
'
isol {0} {1} {2} {3} {4}
'
.
format
(
self
.
name
,
self
.
S
.
value
,
self
.
nodes
[
0
].
name
,
self
.
nodes
[
1
].
name
,
self
.
nodes
[
2
].
name
)]
if
self
.
_option
==
0
:
cmd
=
"
isol
"
elif
self
.
_option
==
1
:
cmd
=
"
isol*
"
rtn
=
[
'
{cmd} {0} {1} {2} {3} {4}
'
.
format
(
self
.
name
,
self
.
S
.
value
,
self
.
nodes
[
0
].
name
,
self
.
nodes
[
1
].
name
,
self
.
nodes
[
2
].
name
,
cmd
=
cmd
)]
for
p
in
self
.
_params
:
for
p
in
self
.
_params
:
rtn
.
extend
(
p
.
getFinesseText
())
rtn
.
extend
(
p
.
getFinesseText
())
...
...
This diff is collapsed.
Click to expand it.
pykat/finesse.py
+
14
−
5
View file @
37d6fe82
...
@@ -1107,7 +1107,7 @@ class kat(object):
...
@@ -1107,7 +1107,7 @@ class kat(object):
except
pkex
.
BasePyKatException
as
ex
:
except
pkex
.
BasePyKatException
as
ex
:
print
(
ex
)
print
(
ex
)
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
,
rethrowExceptions
=
False
):
"""
"""
Runs the current simulation setup that has been built thus far.
Runs the current simulation setup that has been built thus far.
It returns a katRun or katRun2D object which is populated with the various
It returns a katRun or katRun2D object which is populated with the various
...
@@ -1124,6 +1124,8 @@ class kat(object):
...
@@ -1124,6 +1124,8 @@ class kat(object):
that Finesse performs, the keys are the node names and the values
that Finesse performs, the keys are the node names and the values
are the x and y beam parameters. If no tracing is done a None
are the x and y beam parameters. If no tracing is done a None
is returned.
is returned.
rethrowExceptions - if true exceptions will be thrown again rather than being excepted and calling sys.exit()
"""
"""
start
=
datetime
.
datetime
.
now
()
start
=
datetime
.
datetime
.
now
()
...
@@ -1423,8 +1425,15 @@ class kat(object):
...
@@ -1423,8 +1425,15 @@ class kat(object):
except
KeyboardInterrupt
as
ex
:
except
KeyboardInterrupt
as
ex
:
print
(
"
Keyboard interrupt caught, stopped simulation.
"
)
print
(
"
Keyboard interrupt caught, stopped simulation.
"
)
except
pkex
.
FinesseRunError
as
ex
:
except
pkex
.
FinesseRunError
as
ex
:
if
rethrowExceptions
:
raise
ex
else
:
pkex
.
PrintError
(
"
Error from Finesse:
"
,
ex
)
pkex
.
PrintError
(
"
Error from Finesse:
"
,
ex
)
except
pkex
.
BasePyKatException
as
ex
:
except
pkex
.
BasePyKatException
as
ex
:
if
rethrowExceptions
:
raise
ex
else
:
pkex
.
PrintError
(
"
Error from pykat:
"
,
ex
)
pkex
.
PrintError
(
"
Error from pykat:
"
,
ex
)
finally
:
finally
:
if
self
.
verbose
:
print
(
""
)
if
self
.
verbose
:
print
(
""
)
...
@@ -1500,11 +1509,11 @@ class kat(object):
...
@@ -1500,11 +1509,11 @@ class kat(object):
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
(
self
.
nodes
,
node_name
):
node_name
=
"
%s_%i
"
%
(
str
(
undumped_name_prefix
),
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
))
def
getMatrices
(
self
):
def
getMatrices
(
self
):
...
...
This diff is collapsed.
Click to expand it.
pykat/optics/maps.py
+
5
−
3
View file @
37d6fe82
...
@@ -1076,6 +1076,8 @@ def read_map(filename, mapFormat='finesse', scaling=1.0e-9):
...
@@ -1076,6 +1076,8 @@ def read_map(filename, mapFormat='finesse', scaling=1.0e-9):
data
=
np
.
loadtxt
(
filename
,
dtype
=
np
.
float64
,
ndmin
=
2
,
comments
=
'
%
'
)
data
=
np
.
loadtxt
(
filename
,
dtype
=
np
.
float64
,
ndmin
=
2
,
comments
=
'
%
'
)
return
surfacemap
(
name
,
maptype
,
size
,
center
,
step
,
scaling
,
data
)
# Converts raw zygo and ligo mirror maps to the finesse
# Converts raw zygo and ligo mirror maps to the finesse
# format. Based on the matlab scripts 'FT_read_zygo_map.m' and
# format. Based on the matlab scripts 'FT_read_zygo_map.m' and
# 'FT_read_ligo_map.m'.
# 'FT_read_ligo_map.m'.
...
@@ -1289,14 +1291,14 @@ def read_map(filename, mapFormat='finesse', scaling=1.0e-9):
...
@@ -1289,14 +1291,14 @@ def read_map(filename, mapFormat='finesse', scaling=1.0e-9):
# map with surfacemap.plot().
# map with surfacemap.plot().
data
[
isNan
]
=
0
data
[
isNan
]
=
0
return
surfacemap
(
name
,
maptype
,
size
,
center
,
step
,
scaling
,
data
,
notNan
)
# TODO: Add options for reading virgo maps, and .xyz zygo
# TODO: Add options for reading virgo maps, and .xyz zygo
# maps (need .xys file for this). Binary ligo-maps?
# maps (need .xys file for this). Binary ligo-maps?
# The intensity data is not used to anything here. Remove
# The intensity data is not used to anything here. Remove
# or add to pykat?
# or add to pykat?
return
surfacemap
(
name
,
maptype
,
size
,
center
,
step
,
scaling
,
data
,
notNan
)
def
rnm
(
n
,
m
,
rho
):
def
rnm
(
n
,
m
,
rho
):
...
...
This diff is collapsed.
Click to expand it.
pykat/parallel.py
0 → 100644
+
89
−
0
View file @
37d6fe82
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 27 09:56:53 2013
PyKat - Python interface and wrapper for FINESSE
Copyright (C) 2013 Daniel David Brown
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Contact at ddb@star.sr.bham.ac.uk
@author: Daniel Brown
"""
from
IPython.parallel
import
Client
import
sys
import
os
def
_run
(
commands
,
pwd
):
import
os
os
.
chdir
(
pwd
)
import
pykat
kat
=
pykat
.
finesse
.
kat
()
kat
.
parseCommands
(
commands
)
out
=
kat
.
run
(
rethrowExceptions
=
True
)
return
out
class
parakat
(
object
):
"""
Uses the ipython clustering for running kat objects in parallel.
To use this you must have started an ipython cluster on your computer.
From a new terminal use the command:
ipcluster start -n 4
This will start a cluster with 4 workers.
To run a kat object use:
pk = parakat()
pk.run(kat1)
pk.run(kat2)
pk.run(kat3)
outs = pk.getResults()
The list
'
outs
'
will contain the katRun object you
'
d normal get if you
had just called, kat1.run(), etc. The results list is matched to order
in which you run the kats.
If you need to stop long running kat processes the chances are you will
also need to kill the ipython cluster process, as sometimes they carry
on running.
"""
def
__init__
(
self
):
self
.
_rc
=
Client
()
self
.
_lview
=
self
.
_rc
.
load_balanced_view
()
self
.
_lview
.
block
=
False
self
.
_results
=
[]
def
run
(
self
,
kat
):
self
.
_results
.
append
(
self
.
_lview
.
apply_async
(
_run
,
""
.
join
(
kat
.
generateKatScript
()),
os
.
getcwd
()))
def
getResults
(
self
):
out
=
[]
self
.
_lview
.
wait
(
self
.
_results
)
for
done
in
self
.
_results
:
out
.
append
(
done
.
get
())
return
out
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