Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pairs
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
software
pairs
Commits
a3e7154a
Commit
a3e7154a
authored
3 years ago
by
Rafael Ravedutti
Browse files
Options
Downloads
Patches
Plain Diff
Inline particle interactions and fix modules references
Signed-off-by:
Rafael Ravedutti
<
rafaelravedutti@gmail.com
>
parent
216461eb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/pairs/analysis/modules.py
+22
-5
22 additions, 5 deletions
src/pairs/analysis/modules.py
src/pairs/ir/visitor.py
+21
-19
21 additions, 19 deletions
src/pairs/ir/visitor.py
src/pairs/sim/interaction.py
+2
-2
2 additions, 2 deletions
src/pairs/sim/interaction.py
with
45 additions
and
26 deletions
src/pairs/analysis/modules.py
+
22
−
5
View file @
a3e7154a
...
...
@@ -7,20 +7,37 @@ class FetchModulesReferences(Visitor):
self
.
module_stack
=
[]
self
.
writing
=
False
def
visit_ArrayAccess
(
self
,
ast_node
):
# Visit array and save current writing state
self
.
visit
(
ast_node
.
array
)
writing_state
=
self
.
writing
# Index elements are read-only
self
.
writing
=
False
self
.
visit
([
roc
for
roc
in
ast_node
.
children
()
if
roc
!=
ast_node
.
array
])
self
.
writing
=
writing_state
def
visit_Assign
(
self
,
ast_node
):
self
.
writing
=
True
for
c
in
ast_node
.
destinations
():
self
.
visit
(
c
)
self
.
visit
(
ast_node
.
destinations
())
self
.
writing
=
False
for
c
in
ast_node
.
sources
():
self
.
visit
(
c
)
self
.
visit
(
ast_node
.
sources
())
def
visit_Module
(
self
,
ast_node
):
self
.
module_stack
.
append
(
ast_node
)
self
.
visit_children
(
ast_node
)
self
.
module_stack
.
pop
()
def
visit_PropertyAccess
(
self
,
ast_node
):
# Visit property and save current writing state
self
.
visit
(
ast_node
.
prop
)
writing_state
=
self
.
writing
# Index elements are read-only
self
.
writing
=
False
self
.
visit
([
roc
for
roc
in
ast_node
.
children
()
if
roc
!=
ast_node
.
prop
])
self
.
writing
=
writing_state
def
visit_Array
(
self
,
ast_node
):
for
m
in
self
.
module_stack
:
m
.
add_array
(
ast_node
,
self
.
writing
)
...
...
This diff is collapsed.
Click to expand it.
src/pairs/ir/visitor.py
+
21
−
19
View file @
a3e7154a
...
...
@@ -11,26 +11,29 @@ class Visitor:
method
=
getattr
(
self
,
method_name
,
None
)
return
method
if
callable
(
method
)
else
None
def
visit
(
self
,
ast_node
=
None
):
if
ast_node
is
None
:
ast_node
=
self
.
ast
method
=
self
.
get_method
(
f
"
visit_
{
type
(
ast_node
).
__name__
}
"
)
if
method
is
not
None
:
method
(
ast_node
)
else
:
for
b
in
type
(
ast_node
).
__bases__
:
method
=
self
.
get_method
(
f
"
visit_
{
b
.
__name__
}
"
)
if
method
is
not
None
:
method
(
ast_node
)
break
if
method
is
None
:
self
.
visit_children
(
ast_node
)
def
visit
(
self
,
ast_nodes
=
None
):
if
ast_nodes
is
None
:
ast_nodes
=
[
self
.
ast
]
if
not
isinstance
(
ast_nodes
,
list
):
ast_nodes
=
[
ast_nodes
]
for
node
in
ast_nodes
:
method
=
self
.
get_method
(
f
"
visit_
{
type
(
node
).
__name__
}
"
)
if
method
is
not
None
:
method
(
node
)
else
:
for
b
in
type
(
node
).
__bases__
:
method
=
self
.
get_method
(
f
"
visit_
{
b
.
__name__
}
"
)
if
method
is
not
None
:
method
(
node
)
break
if
method
is
None
:
self
.
visit
(
node
.
children
())
def
visit_children
(
self
,
ast_node
):
for
c
in
ast_node
.
children
():
self
.
visit
(
c
)
self
.
visit
(
ast_node
.
children
())
def
yield_elements_breadth_first
(
self
,
ast_node
=
None
):
nodes_to_visit
=
deque
()
...
...
@@ -39,7 +42,6 @@ class Visitor:
ast_node
=
self
.
ast
nodes_to_visit
.
append
(
ast_node
)
while
nodes_to_visit
:
next_node
=
nodes_to_visit
.
popleft
()
# nodes_to_visit.pop() for depth-first traversal
yield
next_node
...
...
This diff is collapsed.
Click to expand it.
src/pairs/sim/interaction.py
+
2
−
2
View file @
a3e7154a
from
pairs.ir.bin_op
import
BinOp
from
pairs.ir.block
import
Block
,
pairs_
device_block
from
pairs.ir.block
import
Block
,
pairs_
inline
from
pairs.ir.branches
import
Branch
,
Filter
from
pairs.ir.loops
import
For
,
ParticleFor
from
pairs.ir.types
import
Types
...
...
@@ -60,7 +60,7 @@ class ParticleInteraction(Lowerable):
yield
self
.
i
,
self
.
j
self
.
sim
.
leave
()
@pairs_
device_block
@pairs_
inline
def
lower
(
self
):
if
self
.
nbody
==
2
:
position
=
self
.
sim
.
position
()
...
...
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