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
Sebastian Steinlechner
pykat
Commits
2a0ae4be
Commit
2a0ae4be
authored
9 years ago
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
adding parakat example
parent
121fe5fc
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/parallel_running.py
+74
-0
74 additions, 0 deletions
examples/parallel_running.py
pykat/parallel.py
+2
-2
2 additions, 2 deletions
pykat/parallel.py
with
76 additions
and
2 deletions
examples/parallel_running.py
0 → 100644
+
74
−
0
View file @
2a0ae4be
# Example on running multiple kat objects at once using the parakat feature.
#
# Firstly you need to start an ipython cluster on your computer. To do this open
# a new terminal and type the command:
#
# ipcluster start -n 4
#
# This will start a cluster with 4 workers. You should set this number to how many
# cores you have.
#
import
pykat
from
pykat.parallel
import
parakat
# Create a connection to the server
pk
=
parakat
()
# Create a bunch of kat objects to run
kat1
=
pykat
.
finesse
.
kat
()
kat2
=
pykat
.
finesse
.
kat
()
kat3
=
pykat
.
finesse
.
kat
()
kat1
.
parseCommands
(
"""
l l1 1 0 n0
s s1 1 n0 n1
pd P n1
noxaxis
"""
)
kat2
.
parseCommands
(
"""
l l1 2 0 n0
s s1 1 n0 n1
pd P n1
noxaxis
"""
)
kat3
.
parseCommands
(
"""
l l1 3 0 n0
s s1 1 n0 n1
pd P n1
noxaxis
"""
)
# Each kat object that is started straightaway when called like this.
# You can add as many as you want, the number that will
# run at once depends on the number of workers in the cluster
pk
.
run
(
kat1
,
cmd_args
=
[
"
-cr=on
"
])
pk
.
run
(
kat2
,
cmd_args
=
[
"
-cr=on
"
])
pk
.
run
(
kat3
,
cmd_args
=
[
"
-cr=on
"
])
# Now you can get the output objects for each of the files run
# They will be returned in order. So you can get each of the outputs using:
out1
,
out2
,
out3
=
pk
.
getResults
()
print
(
out1
[
"
P
"
])
print
(
out2
[
"
P
"
])
print
(
out3
[
"
P
"
])
# or you could also get the outputs in a list:
outs
=
pk
.
getResults
()
# so you'd then access the ouputs like: outs[0], outs[1], etc.
# This option is useful if you want to iterate over each output
# result in a for loop for example:
for
out
in
outs
:
print
(
out
[
"
P
"
])
# Call `clear` to remove the last output results
# After this you could run more in parallel and get the outputs
# for those.
pk
.
clear
()
# When finally done you should close the connection to the cluster
pk
.
close
()
This diff is collapsed.
Click to expand it.
pykat/parallel.py
+
2
−
2
View file @
2a0ae4be
...
...
@@ -89,8 +89,8 @@ class parakat(object):
return
out
def
clear
(
self
):
del
(
self
.
_result
)
self
.
_result
=
[]
del
(
self
.
_result
s
)
self
.
_result
s
=
[]
def
close
(
self
):
self
.
_rc
.
close
()
...
...
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