Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
multiprocessing-examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Gepetto
multiprocessing-examples
Commits
609583d8
Commit
609583d8
authored
4 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
review example-3
parent
60a0993e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
review details
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
example-3/boss.py
+16
-16
16 additions, 16 deletions
example-3/boss.py
example-3/task.py
+8
-5
8 additions, 5 deletions
example-3/task.py
with
24 additions
and
21 deletions
example-3/boss.py
+
16
−
16
View file @
609583d8
#!/usr/bin/env python3
import
numpy
as
np
import
time
from
manager
import
QueueClient
from
task
import
Task
,
TaskParameters
import
numpy
as
np
import
example_robot_data
as
robex
import
pinocchio
as
pin
from
manager
import
QueueClient
from
task
import
Task
,
TaskParameters
class
Boss
(
QueueClient
):
def
run
(
self
,
qs
,
vqs
,
aqs
):
def
run
(
self
,
qs
,
vqs
,
aqs
):
# create some tasks
for
i
,[
q
,
v
,
a
]
in
enumerate
(
zip
(
qs
,
vqs
,
aqs
)):
self
.
tasks
.
put
(
Task
(
i
,
q
,
v
,
a
))
for
i
,
[
q
,
v
,
a
]
in
enumerate
(
zip
(
qs
,
vqs
,
aqs
)):
self
.
tasks
.
put
(
Task
(
i
,
q
,
v
,
a
))
# Wait for the results
results
=
[]
for
_
in
range
(
len
(
qs
))
:
for
_
in
qs
:
result
=
self
.
results
.
get
()
print
(
f
'
got result
{
result
.
identifier
}
of processed in
{
result
.
time
:
.
3
f
}
s :
'
)
results
.
append
(
result
)
print
(
'
Got all {tasks} results !
'
)
if
__name__
==
'
__main__
'
:
import
time
# Allocate data to be proceeded.
NDATA
=
20
qs
=
np
.
array
([
pin
.
randomConfiguration
(
TaskParameters
.
robot
.
model
)
for
_
in
range
(
NDATA
)
])
vqs
=
np
.
random
.
rand
(
NDATA
,
TaskParameters
.
robot
.
model
.
nv
)
*
2
-
1
aqs
=
np
.
random
.
rand
(
NDATA
,
TaskParameters
.
robot
.
model
.
nv
)
*
2
-
1
qs
=
np
.
array
([
pin
.
randomConfiguration
(
TaskParameters
.
robot
.
model
)
for
_
in
range
(
NDATA
)])
vqs
=
np
.
random
.
rand
(
NDATA
,
TaskParameters
.
robot
.
model
.
nv
)
*
2
-
1
aqs
=
np
.
random
.
rand
(
NDATA
,
TaskParameters
.
robot
.
model
.
nv
)
*
2
-
1
start
=
time
.
perf_counter
()
Boss
().
run
(
qs
,
vqs
,
aqs
)
Boss
().
run
(
qs
,
vqs
,
aqs
)
total
=
time
.
perf_counter
()
-
start
print
(
f
'
Completed in
{
total
:
.
3
f
}
secs
'
)
print
(
f
'
Completed in
{
total
:
.
3
f
}
secs
'
)
This diff is collapsed.
Click to expand it.
example-3/task.py
+
8
−
5
View file @
609583d8
import
time
import
pinocchio
as
pin
import
numpy
as
np
import
pinocchio
as
pin
import
example_robot_data
as
robex
class
TaskParameters
:
'''
Common information to all tasks, to be allocated by each minion and the boss.
'''
robotname
=
'
ur5
'
robot
=
robex
.
load
(
robotname
)
class
Task
:
def
__init__
(
self
,
identifier
,
q
,
v
,
a
):
def
__init__
(
self
,
identifier
,
q
,
v
,
a
):
self
.
identifier
=
identifier
self
.
q
=
q
.
copy
()
...
...
@@ -23,8 +26,8 @@ class Task:
def
work
(
self
):
start
=
time
.
perf_counter
()
for
i
in
range
(
1000000
):
pin
.
rnea
(
TaskParameters
.
robot
.
model
,
TaskParameters
.
robot
.
data
,
self
.
q
,
self
.
v
,
self
.
a
)
for
i
in
range
(
1
_
000
_
000
):
pin
.
rnea
(
TaskParameters
.
robot
.
model
,
TaskParameters
.
robot
.
data
,
self
.
q
,
self
.
v
,
self
.
a
)
self
.
tau
[:]
=
TaskParameters
.
robot
.
data
.
tau
self
.
time
=
time
.
perf_counter
()
-
start
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