Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MPI-BugBench
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
High Performance Computing - Public
MPI-BugBench
Commits
e77b3d66
Commit
e77b3d66
authored
1 year ago
by
Jammer, Tim
Browse files
Options
Downloads
Patches
Plain Diff
Added Functionality to remove/replace Blocks in TemplateManager (
#1
)
parent
73e2d3ec
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
scripts/Infrastructure/InstructionBlock.py
+2
-1
2 additions, 1 deletion
scripts/Infrastructure/InstructionBlock.py
scripts/Infrastructure/Template.py
+86
-0
86 additions, 0 deletions
scripts/Infrastructure/Template.py
with
88 additions
and
1 deletion
scripts/Infrastructure/InstructionBlock.py
+
2
−
1
View file @
e77b3d66
...
@@ -21,10 +21,11 @@ class InstructionBlock:
...
@@ -21,10 +21,11 @@ class InstructionBlock:
Initialize an empty InstructionBlock
Initialize an empty InstructionBlock
Parameters:
Parameters:
- name: The name of the block (for referencing this block with the template Manager)
- name
(str)
: The name of the block (for referencing this block with the template Manager)
May be None, does not influence the code generated
May be None, does not influence the code generated
"""
"""
self
.
operations
=
{
'
all
'
:
[],
'
not0
'
:
[],
}
self
.
operations
=
{
'
all
'
:
[],
'
not0
'
:
[],
}
assert
not
isinstance
(
name
,
int
)
self
.
name
=
name
self
.
name
=
name
# TODO test if op also can be a list of operations
# TODO test if op also can be a list of operations
...
...
This diff is collapsed.
Click to expand it.
scripts/Infrastructure/Template.py
+
86
−
0
View file @
e77b3d66
...
@@ -155,3 +155,89 @@ class TemplateManager:
...
@@ -155,3 +155,89 @@ class TemplateManager:
"""
"""
assert
self
.
_descr_short
!=
""
assert
self
.
_descr_short
!=
""
return
self
.
_descr_short
return
self
.
_descr_short
def
get_block
(
self
,
block_name
=
None
,
idx
=
None
):
"""
Retrieves the given Instruction Block Either by name or by index
Raises IndexError if not the specified block is not found
Raises IndexError if multiple Blocks with the given name are found
Raises ValueError if Both a block name and index are given (or none is given)
Args:
block_name (str): The name of the InstructionBlock to receive
idx (int): index of the InstructionBlock to retrieve
Returns:
the specified Block
"""
if
block_name
is
not
None
:
if
idx
is
not
None
:
raise
ValueError
(
"
Both block name and index are given
"
)
to_return
=
[
b
for
b
in
self
.
_blocks
if
b
.
name
==
block_name
]
if
len
(
to_return
)
==
0
:
raise
IndexError
(
"
Block Not Found
"
)
if
len
(
to_return
)
>
0
:
raise
IndexError
(
"
Multiple Blocks Found
"
)
return
to_return
[
0
]
if
idx
is
not
None
:
if
block_name
is
not
None
:
raise
ValueError
(
"
Both block name and index are given
"
)
return
self
.
_blocks
[
idx
]
raise
ValueError
(
"
Neither Both block name nor index is given
"
)
def
remove_block
(
self
,
block_name
=
None
,
idx
=
None
):
"""
Removes the given Instruction Block Either by name or by index
Raises IndexError if not the specified block is not found
Raises IndexError if multiple Blocks with the given name are found
Raises ValueError if Both a block name and index are given (or none is given)
Args:
block_name (str): The name of the InstructionBlock to receive
idx (int): index of the InstructionBlock to retrieve
"""
if
block_name
is
not
None
:
if
idx
is
not
None
:
raise
ValueError
(
"
Both block name and index are given
"
)
to_return
=
[
b
for
b
in
self
.
_blocks
if
b
.
name
==
block_name
]
if
len
(
to_return
)
==
0
:
raise
IndexError
(
"
Block Not Found
"
)
if
len
(
to_return
)
>
0
:
raise
IndexError
(
"
Multiple Blocks Found
"
)
self
.
_blocks
.
remove
(
to_return
[
0
])
if
idx
is
not
None
:
if
block_name
is
not
None
:
raise
ValueError
(
"
Both block name and index are given
"
)
del
self
.
_blocks
[
idx
]
raise
ValueError
(
"
Neither Both block name nor index is given
"
)
def
replace_block
(
self
,
new_block
,
block_name
=
None
,
idx
=
None
):
"""
Removes the given Instruction Block Either by name or by index
Raises IndexError if not the specified block is not found
Raises IndexError if multiple Blocks with the given name are found
Raises ValueError if Both a block name and index are given (or none is given)
Args:
new_block (InstructionBlock): The new Block to replace the old one (does not need to have the same name)
block_name (str): The name of the InstructionBlock to receive
idx (int): index of the InstructionBlock to retrieve
"""
assert
isinstance
(
new_block
,
InstructionBlock
)
if
block_name
is
not
None
:
if
idx
is
not
None
:
raise
ValueError
(
"
Both block name and index are given
"
)
to_return
=
[
b
for
b
in
self
.
_blocks
if
b
.
name
==
block_name
]
if
len
(
to_return
)
==
0
:
raise
IndexError
(
"
Block Not Found
"
)
if
len
(
to_return
)
>
0
:
raise
IndexError
(
"
Multiple Blocks Found
"
)
self
.
_blocks
[
self
.
_blocks
.
index
(
to_return
[
0
])]
=
new_block
if
idx
is
not
None
:
if
block_name
is
not
None
:
raise
ValueError
(
"
Both block name and index are given
"
)
self
.
_blocks
[
idx
]
=
new_block
raise
ValueError
(
"
Neither Both block name nor index is given
"
)
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