Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor 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
calibration
pycalibration
Commits
1290575a
Commit
1290575a
authored
5 years ago
by
Mikhail Karnevskiy
Browse files
Options
Downloads
Patches
Plain Diff
Use templates for parameters table
parent
f6fa53d5
No related branches found
No related tags found
1 merge request
!72
Feat: Change formatting of list of input parameters
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xfel_calibrate/calibrate.py
+37
-31
37 additions, 31 deletions
xfel_calibrate/calibrate.py
with
37 additions
and
31 deletions
xfel_calibrate/calibrate.py
+
37
−
31
View file @
1290575a
...
...
@@ -17,7 +17,8 @@ from uuid import uuid4
import
warnings
from
.settings
import
*
from
.notebooks
import
notebooks
from
jinja2
import
Template
import
textwrap
# Add a class combining raw description formatting with
# Metavariable default outputs
...
...
@@ -443,59 +444,64 @@ def concurrent_run(temp_path, nb, nbname, args, cparm=None, cval=None,
def
make_par_table
(
parms
,
temp_path
,
run_uuid
):
'''
"""
Create a table with input parameters if the notebook
:param parms: parameters of the notebook
:param temp_path: path to temporary directory for job outputs
:param run_uuid: inset of folder name containing job output
'''
"""
# Add space in long strings to wrap them in latex
def
split_len
(
seq
,
length
):
l
=
[
seq
[
i
:
i
+
length
]
for
i
in
range
(
0
,
len
(
seq
),
length
)]
l
=
[
seq
[
i
:
i
+
length
]
for
i
in
range
(
0
,
len
(
seq
),
length
)]
return
'
'
.
join
(
l
)
#
p
repare strings and estimate their length
#
P
repare strings and estimate their length
l_parms
=
[]
len_parms
=
[
0
,
0
]
max_len
=
[
30
,
30
]
for
p
in
parms
:
name
=
p
.
name
.
replace
(
'
_
'
,
'
-
'
)
if
len
(
name
)
>
max_len
[
0
]:
if
len
(
name
)
>
max_len
[
0
]:
len_parms
[
0
]
=
max_len
[
0
]
name
=
split_len
(
name
,
max_len
[
0
])
value
=
str
(
p
.
value
)
if
len
(
value
)
>
max_len
[
1
]:
if
len
(
value
)
>
max_len
[
1
]:
len_parms
[
1
]
=
max_len
[
1
]
value
=
split_len
(
value
,
max_len
[
1
])
if
p
.
type
is
str
:
value
=
"
``{}
''"
.
format
(
value
)
value
=
value
.
replace
(
'
_
'
,
'
\\
_
'
)
comment
=
str
(
p
.
comment
)[
1
:].
replace
(
'
_
'
,
'
\\
_
'
)
l_parms
.
append
([
name
,
value
,
comment
])
with
open
(
"
{}/slurm_tmp_{}/InputParameters.rst
"
.
format
(
temp_path
,
run_uuid
),
"
w
"
)
as
finfile
:
finfile
.
write
(
"
Input of the calibration pipeline
\n
"
)
finfile
.
write
(
"
=================================
\n\n
"
)
finfile
.
write
(
"
.. math::
\n
"
)
col_type
=
[
'
l
'
,
'
c
'
,
'
p{.3
\\
textwidth}
'
]
# fix column width is needed
if
len_parms
[
0
]
==
max_len
[
0
]:
col_type
[
0
]
=
'
p{.3
\\
textwidth}
'
if
len_parms
[
1
]
==
max_len
[
1
]:
col_type
[
1
]
=
'
p{.3
\\
textwidth}
'
finfile
.
write
(
"
\\
begin{{tabular}}{{ {} {} {} }}
\n
"
.
format
(
*
col_type
))
finfile
.
write
(
"
\\
hline
\n
"
)
for
p
in
l_parms
:
tmpl
=
"
\\
textbf{{-{{}}-{} }} & {} & {}
\\\\\n
"
finfile
.
write
(
tmpl
.
format
(
*
p
))
finfile
.
write
(
"
\\
hline
\n
"
)
finfile
.
write
(
"
\\
end{tabular}
\n
"
)
l_parms
.
append
([
name
,
value
,
comment
])
# Fix column width is needed
col_type
=
[
'
l
'
,
'
c
'
,
'
p{.3
\\
textwidth}
'
]
if
len_parms
[
0
]
==
max_len
[
0
]:
col_type
[
0
]
=
'
p{.3
\\
textwidth}
'
if
len_parms
[
1
]
==
max_len
[
1
]:
col_type
[
1
]
=
'
p{.3
\\
textwidth}
'
tmpl
=
Template
(
'''
Input of the calibration pipeline
=================================
.. math::
\\
begin{tabular}{ {% for k in p %}{{ k }}{%- endfor %} }
\hline
{% for k in lines %}
{{ k[0] }} & {{ k[1] }} & {{ k[2] }}
\\\\
{%- endfor %}
\hline
\end{tabular}
'''
)
f_name
=
"
{}/slurm_tmp_{}/InputParameters.rst
"
.
format
(
temp_path
,
run_uuid
)
with
open
(
f_name
,
"
w
"
)
as
finfile
:
finfile
.
write
(
textwrap
.
dedent
(
tmpl
.
render
(
p
=
col_type
,
lines
=
l_parms
)))
def
run
():
...
...
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