Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
python-common
Commits
e2d26468
Commit
e2d26468
authored
9 years ago
by
Mohamed, Fawzi Roberto (fawzi)
Browse files
Options
Downloads
Patches
Plain Diff
making caching level automatically recursive
if a section is not forwarded none of the children are
parent
2f70bee0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/python/nomadcore/caching_backend.py
+20
-8
20 additions, 8 deletions
common/python/nomadcore/caching_backend.py
with
20 additions
and
8 deletions
common/python/nomadcore/caching_backend.py
+
20
−
8
View file @
e2d26468
...
@@ -2,6 +2,7 @@ from builtins import str
...
@@ -2,6 +2,7 @@ from builtins import str
from
builtins
import
zip
from
builtins
import
zip
from
builtins
import
range
from
builtins
import
range
from
builtins
import
object
from
builtins
import
object
from
functools
import
reduce
import
json
import
json
import
numpy
as
np
import
numpy
as
np
import
sys
import
sys
...
@@ -17,17 +18,27 @@ class CachingLevel(object):
...
@@ -17,17 +18,27 @@ class CachingLevel(object):
@classmethod
@classmethod
def
toText
(
cls
,
cl
):
def
toText
(
cls
,
cl
):
if
cl
==
Forward
:
if
cl
==
cls
.
Forward
:
return
"
Forward
"
return
"
Forward
"
elif
cl
==
ForwardAndCache
:
elif
cl
==
cls
.
ForwardAndCache
:
return
"
ForwardAndCache
"
return
"
ForwardAndCache
"
elif
cl
==
Cache
:
elif
cl
==
cls
.
Cache
:
return
"
Cache
"
return
"
Cache
"
elif
cl
==
Ignore
:
elif
cl
==
cls
.
Ignore
:
return
"
Ignore
"
return
"
Ignore
"
else
:
else
:
return
"
CachingLevel(%s)
"
%
cl
return
"
CachingLevel(%s)
"
%
cl
@classmethod
def
restrict
(
cls
,
a
,
b
):
"""
restricts a keeping in account that it is contained in b (i.e. if b is not forwarded then also a cannot be forwarded)
"""
if
b
==
cls
.
Cache
or
b
==
cls
.
Ignore
:
if
a
==
cls
.
Forward
:
return
cls
.
Ignore
elif
a
==
cls
.
ForwardAndCache
:
return
cls
.
Cache
return
a
class
CachingSection
(
object
):
class
CachingSection
(
object
):
"""
Represents an open section, and can cache values
"""
"""
Represents an open section, and can cache values
"""
def
__init__
(
self
,
gIndex
,
references
,
storeInSuper
=
False
,
activeBackend
=
None
):
def
__init__
(
self
,
gIndex
,
references
,
storeInSuper
=
False
,
activeBackend
=
None
):
...
@@ -256,9 +267,9 @@ class ActiveBackend(object):
...
@@ -256,9 +267,9 @@ class ActiveBackend(object):
sectionManagers
=
{}
sectionManagers
=
{}
for
ikNames
,
ik
in
metaInfoEnv
.
infoKinds
.
items
():
for
ikNames
,
ik
in
metaInfoEnv
.
infoKinds
.
items
():
if
ik
.
kindStr
==
"
type_section
"
:
if
ik
.
kindStr
==
"
type_section
"
:
parentS
=
list
(
metaInfoEnv
.
firstAncestorsByType
(
ik
.
name
).
get
(
"
type_section
"
,
[[]
])[
0
])
parentS
,
parentO
=
list
(
metaInfoEnv
.
firstAncestorsByType
(
ik
.
name
).
get
(
"
type_section
"
,
[[]
,[]
])
)
parentS
.
sort
()
parentS
.
sort
()
cachingLevel
=
cachingLevelForMetaName
.
get
(
ik
.
name
,
defaultSectionCachingLevel
)
cachingLevel
=
reduce
(
CachingLevel
.
restrict
,
[
cachingLevelForMetaName
.
get
(
x
,
defaultSectionCachingLevel
)
for
x
in
([
ik
.
name
]
+
parentS
+
parentO
)])
sectionManagers
[
ik
.
name
]
=
CachingSectionManager
(
sectionManagers
[
ik
.
name
]
=
CachingSectionManager
(
metaInfo
=
ik
,
metaInfo
=
ik
,
parentSectionNames
=
parentS
,
parentSectionNames
=
parentS
,
...
@@ -275,8 +286,9 @@ class ActiveBackend(object):
...
@@ -275,8 +286,9 @@ class ActiveBackend(object):
elif
len
(
superSectionNames
)
>
1
:
elif
len
(
superSectionNames
)
>
1
:
raise
Exception
(
"
MetaInfo of concrete value %s has multiple superSections (%s)
"
%
raise
Exception
(
"
MetaInfo of concrete value %s has multiple superSections (%s)
"
%
(
ik
.
name
,
superSectionNames
))
(
ik
.
name
,
superSectionNames
))
dataManagers
[
ik
.
name
]
=
CachingDataManager
(
ik
,
sectionManagers
[
superSectionNames
[
0
]],
sectionManager
=
sectionManagers
[
superSectionNames
[
0
]]
cachingLevelForMetaName
.
get
(
ik
.
name
,
defaultDataCachingLevel
))
dataManagers
[
ik
.
name
]
=
CachingDataManager
(
ik
,
sectionManager
,
CachingLevel
.
restrict
(
cachingLevelForMetaName
.
get
(
ik
.
name
,
defaultDataCachingLevel
),
CachingLevel
.
Forward
if
sectionManager
.
forwardOpenClose
else
CachingLevel
.
Ignore
))
return
ActiveBackend
(
metaInfoEnv
,
sectionManagers
,
dataManagers
,
superBackend
,
propagateStartFinishParsing
,
default_units
,
metainfo_units
)
return
ActiveBackend
(
metaInfoEnv
,
sectionManagers
,
dataManagers
,
superBackend
,
propagateStartFinishParsing
,
default_units
,
metainfo_units
)
def
appendOnClose
(
self
,
sectionName
,
onClose
):
def
appendOnClose
(
self
,
sectionName
,
onClose
):
...
...
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