Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
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
Service Desk
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
mimc
WindEnergyToolbox
Commits
574c6214
Commit
574c6214
authored
6 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
Div
parent
c23df80f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
wetb/hawc2/htc_contents.py
+2
-0
2 additions, 0 deletions
wetb/hawc2/htc_contents.py
wetb/hawc2/log_file.py
+15
-12
15 additions, 12 deletions
wetb/hawc2/log_file.py
wetb/hawc2/simulation.py
+28
-15
28 additions, 15 deletions
wetb/hawc2/simulation.py
with
45 additions
and
27 deletions
wetb/hawc2/htc_contents.py
+
2
−
0
View file @
574c6214
...
...
@@ -204,6 +204,8 @@ class HTCSection(HTCContents):
break
else
:
section
.
_add_contents
(
section
.
line_from_line
(
lines
))
else
:
raise
Exception
(
"
Section
'
%s
'
has not end
"
%
section
.
name_
)
return
section
def
line_from_line
(
self
,
lines
):
...
...
This diff is collapsed.
Click to expand it.
wetb/hawc2/log_file.py
+
15
−
12
View file @
574c6214
...
...
@@ -23,6 +23,7 @@ INITIALIZATION = 'Initializing simulation'
SIMULATING
=
"
Simulating
"
DONE
=
"
Simulation succeded
"
class
LogInterpreter
(
object
):
def
__init__
(
self
,
time_stop
):
self
.
time_stop
=
time_stop
...
...
@@ -60,7 +61,7 @@ class LogInterpreter(object):
try
:
return
float
(
time_line
[
time_line
.
index
(
'
=
'
)
+
1
:
time_line
.
index
(
'
Iter
'
)])
except
:
print
(
"
Cannot extract time from #
"
+
time_line
+
"
#
"
)
print
(
"
Cannot extract time from #
"
+
time_line
+
"
#
"
)
pass
def
update_status
(
self
,
new_lines
=
""
):
...
...
@@ -97,14 +98,16 @@ class LogInterpreter(object):
_3to2list1
=
list
(
txt
.
split
(
'
Elapsed time
'
))
simulation_txt
,
rest
,
=
_3to2list1
[:
1
]
+
[
_3to2list1
[
1
:]]
if
"
*** ERROR ***
"
in
simulation_txt
:
self
.
errors
.
extend
([
l
.
strip
()
for
l
in
simulation_txt
.
strip
().
split
(
"
\n
"
)
if
"
error
"
in
l
.
lower
()])
self
.
errors
.
extend
([
l
.
strip
()
for
l
in
simulation_txt
.
strip
().
split
(
"
\n
"
)
if
"
error
"
in
l
.
lower
()])
i1
=
simulation_txt
.
rfind
(
"
Global time
"
)
if
i1
>
-
1
:
self
.
current_time
=
self
.
extract_time
(
simulation_txt
[
i1
:])
if
self
.
current_time
is
not
None
and
self
.
time_stop
>
0
:
self
.
pct
=
int
(
100
*
self
.
current_time
//
self
.
time_stop
)
try
:
self
.
remaining_time
=
(
time
.
time
()
-
self
.
start_time
[
1
])
/
(
self
.
current_time
-
self
.
start_time
[
0
])
*
(
self
.
time_stop
-
self
.
current_time
)
self
.
remaining_time
=
(
time
.
time
()
-
self
.
start_time
[
1
])
/
(
self
.
current_time
-
self
.
start_time
[
0
])
*
(
self
.
time_stop
-
self
.
current_time
)
except
:
pass
if
rest
:
...
...
@@ -118,7 +121,6 @@ class LogInterpreter(object):
error_dict
[
error
]
=
error_dict
.
get
(
error
,
0
)
+
1
return
"
\n
"
.
join
([(
"
%d x %s
"
%
(
v
,
k
),
k
)[
v
==
1
]
for
k
,
v
in
error_dict
.
items
()])
def
remaining_time_str
(
self
):
if
self
.
remaining_time
:
if
self
.
remaining_time
<
3600
:
...
...
@@ -138,7 +140,6 @@ class LogFile(LogInterpreter):
self
.
filename
=
log_filename
LogInterpreter
.
__init__
(
self
,
time_stop
)
@staticmethod
def
from_htcfile
(
htcfile
,
modelpath
=
None
):
logfilename
=
htcfile
.
simulation
.
logfile
[
0
]
...
...
@@ -150,13 +151,14 @@ class LogFile(LogInterpreter):
def
clear
(
self
):
# exist_ok does not exist in Python27
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
self
.
filename
)):
os
.
makedirs
(
os
.
path
.
dirname
(
self
.
filename
))
#, exist_ok=True)
try
:
with
open
(
self
.
filename
,
'
w
'
,
encoding
=
'
utf-8
'
):
pass
except
PermissionError
as
e
:
raise
PermissionError
(
str
(
e
)
+
"
\n
Log file cannot be cleared. Check if it is open in another program
"
)
# if not os.path.exists(os.path.dirname(self.filename)):
# os.makedirs(os.path.dirname(self.filename)) #, exist_ok=True)
if
os
.
path
.
isfile
(
self
.
filename
):
try
:
with
open
(
self
.
filename
,
'
w
'
,
encoding
=
'
utf-8
'
):
pass
except
PermissionError
as
e
:
raise
PermissionError
(
str
(
e
)
+
"
\n
Log file cannot be cleared. Check if it is open in another program
"
)
LogInterpreter
.
clear
(
self
)
def
update_status
(
self
):
...
...
@@ -174,6 +176,7 @@ class LogFile(LogInterpreter):
if
txt
!=
""
:
LogInterpreter
.
update_status
(
self
,
txt
)
class
LogInfo
(
LogFile
):
def
__init__
(
self
,
status
,
pct
,
remaining_time
,
lastline
):
self
.
status
=
status
...
...
This diff is collapsed.
Click to expand it.
wetb/hawc2/simulation.py
+
28
−
15
View file @
574c6214
...
...
@@ -18,6 +18,8 @@ from wetb.hawc2 import log_file
from
wetb.hawc2.htc_file
import
HTCFile
,
fmt_path
from
wetb.hawc2.log_file
import
LogFile
import
tempfile
import
stat
import
shutil
standard_library
.
install_aliases
()
...
...
@@ -240,7 +242,8 @@ class Simulation(object):
if
self
.
status
==
ABORTED
:
return
if
"
error
"
in
self
.
host
.
stdout
.
lower
():
self
.
errors
=
(
list
(
set
([
l
for
l
in
self
.
host
.
stdout
.
split
(
"
\n
"
)
if
'
error
'
in
l
.
lower
()])))
self
.
errors
=
(
list
(
set
([
l
for
l
in
self
.
host
.
stdout
.
split
(
"
\n
"
)
if
'
error
'
in
l
.
lower
()
and
not
'
rms error
'
in
l
])))
self
.
status
=
ERROR
if
'
HAWC2MB version:
'
not
in
self
.
host
.
stdout
:
self
.
errors
.
append
(
self
.
host
.
stdout
)
...
...
@@ -331,23 +334,33 @@ class Simulation(object):
def
simulate_distributed
(
self
,
raise_simulation_errors
=
True
):
try
:
with
tempfile
.
TemporaryDirectory
(
prefix
=
"
h2launcher_
"
)
as
tmpdirname
:
self
.
tmp_modelpath
=
tmpdirname
+
"
/
"
self
.
tmp_exepath
=
os
.
path
.
join
(
self
.
tmp_modelpath
,
os
.
path
.
relpath
(
self
.
exepath
,
self
.
modelpath
))
+
"
/
"
self
.
prepare_simulation
()
tmpdirname
=
tempfile
.
TemporaryDirectory
(
prefix
=
"
h2launcher_%s_
"
%
os
.
path
.
basename
(
self
.
filename
)).
name
self
.
tmp_modelpath
=
tmpdirname
+
"
/
"
self
.
tmp_exepath
=
os
.
path
.
join
(
self
.
tmp_modelpath
,
os
.
path
.
relpath
(
self
.
exepath
,
self
.
modelpath
))
+
"
/
"
self
.
prepare_simulation
()
try
:
self
.
simulate
()
except
Warning
as
e
:
print
(
"
simulation failed
"
,
str
(
self
))
print
(
"
Trying to finish
"
)
raise
finally
:
try
:
self
.
s
imulate
()
except
Warning
as
e
:
print
(
"
simulation failed
"
,
str
(
self
))
print
(
"
Trying to finish
"
)
if
self
.
s
tatus
!=
ABORTED
:
self
.
finish_simulation
()
except
Exception
:
print
(
"
finish_simulation failed
"
,
str
(
self
)
)
raise
finally
:
try
:
if
self
.
status
!=
ABORTED
:
self
.
finish_simulation
()
except
Exception
:
print
(
"
finish_simulation failed
"
,
str
(
self
))
raise
def
remove_readonly
(
fn
,
path
,
excinfo
):
try
:
os
.
chmod
(
path
,
stat
.
S_IWRITE
)
fn
(
path
)
except
Exception
as
exc
:
print
(
"
Skipped:
"
,
path
,
"
because:
\n
"
,
exc
)
shutil
.
rmtree
(
tmpdirname
,
onerror
=
remove_readonly
)
except
Exception
as
e
:
self
.
status
=
ERROR
self
.
errors
.
append
(
str
(
e
))
...
...
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