Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
d41bbc96
Commit
d41bbc96
authored
4 years ago
by
Markus Holzer
Browse files
Options
Downloads
Patches
Plain Diff
Added test case for timeloop
parent
2d758462
No related branches found
No related tags found
1 merge request
!168
Extend testsuite
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pystencils_tests/test_timeloop.py
+49
-0
49 additions, 0 deletions
pystencils_tests/test_timeloop.py
with
49 additions
and
0 deletions
pystencils_tests/test_timeloop.py
0 → 100644
+
49
−
0
View file @
d41bbc96
import
time
import
numpy
as
np
from
pystencils
import
Assignment
from
pystencils
import
create_kernel
from
pystencils.datahandling
import
create_data_handling
from
pystencils.timeloop
import
TimeLoop
def
test_timeloop
():
dh
=
create_data_handling
(
domain_size
=
(
10
,
10
),
periodicity
=
True
)
pre
=
dh
.
add_array
(
'
pre_run_field
'
,
values_per_cell
=
1
)
dh
.
fill
(
"
pre_run_field
"
,
0.0
,
ghost_layers
=
True
)
f
=
dh
.
add_array
(
'
field
'
,
values_per_cell
=
1
)
dh
.
fill
(
"
field
"
,
0.0
,
ghost_layers
=
True
)
post
=
dh
.
add_array
(
'
post_run_field
'
,
values_per_cell
=
1
)
dh
.
fill
(
"
post_run_field
"
,
0.0
,
ghost_layers
=
True
)
pre_assignments
=
Assignment
(
pre
.
center
,
pre
.
center
+
1
)
pre_kernel
=
create_kernel
(
pre_assignments
).
compile
()
assignments
=
Assignment
(
f
.
center
,
f
.
center
+
1
)
kernel
=
create_kernel
(
assignments
).
compile
()
post_assignments
=
Assignment
(
post
.
center
,
post
.
center
+
1
)
post_kernel
=
create_kernel
(
post_assignments
).
compile
()
timeloop
=
TimeLoop
(
steps
=
1
)
def
pre_run
():
dh
.
run_kernel
(
pre_kernel
)
def
post_run
():
dh
.
run_kernel
(
post_kernel
)
timeloop
.
add_pre_run_function
(
pre_run
)
timeloop
.
add_post_run_function
(
post_run
)
timeloop
.
add_call
(
kernel
,
{
'
field
'
:
dh
.
cpu_arrays
[
"
field
"
]})
timeloop
.
run
(
time_steps
=
5
)
assert
np
.
all
(
dh
.
cpu_arrays
[
"
pre_run_field
"
]
==
1.0
)
assert
np
.
all
(
dh
.
cpu_arrays
[
"
field
"
]
==
5.0
)
assert
np
.
all
(
dh
.
cpu_arrays
[
"
post_run_field
"
]
==
1.0
)
seconds
=
2
start
=
time
.
perf_counter
()
timeloop
.
run_time_span
(
seconds
=
seconds
)
end
=
time
.
perf_counter
()
np
.
testing
.
assert_almost_equal
(
seconds
,
end
-
start
,
decimal
=
3
)
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