Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bilby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
lscsoft
bilby
Commits
29b42cc9
Commit
29b42cc9
authored
6 years ago
by
Gregory Ashton
Browse files
Options
Downloads
Patches
Plain Diff
Clean up for core logging output
Adds a line to print the result and indicate where results are saved
parent
c461bba6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!66
Clean up output
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
tupak/core/prior.py
+6
-6
6 additions, 6 deletions
tupak/core/prior.py
tupak/core/result.py
+3
-3
3 additions, 3 deletions
tupak/core/result.py
tupak/core/sampler.py
+10
-8
10 additions, 8 deletions
tupak/core/sampler.py
tupak/core/utils.py
+5
-4
5 additions, 4 deletions
tupak/core/utils.py
with
24 additions
and
21 deletions
tupak/core/prior.py
+
6
−
6
View file @
29b42cc9
...
...
@@ -94,10 +94,10 @@ class PriorSet(dict):
continue
elif
isinstance
(
self
[
key
],
float
)
or
isinstance
(
self
[
key
],
int
):
self
[
key
]
=
DeltaFunction
(
self
[
key
])
logging
.
info
(
logging
.
debug
(
"
{} converted to delta function prior.
"
.
format
(
key
))
else
:
logging
.
info
(
logging
.
debug
(
"
{} cannot be converted to delta function prior.
"
.
format
(
key
))
...
...
@@ -139,7 +139,7 @@ class PriorSet(dict):
if
isinstance
(
self
[
key
],
Prior
):
samples
[
key
]
=
self
[
key
].
sample
(
size
=
size
)
else
:
logging
.
info
(
'
{} not a known prior.
'
.
format
(
key
))
logging
.
debug
(
'
{} not a known prior.
'
.
format
(
key
))
return
samples
def
prob
(
self
,
sample
):
...
...
@@ -180,7 +180,7 @@ def create_default_prior(name, default_priors_file=None):
"""
if
default_priors_file
is
None
:
logging
.
info
(
logging
.
debug
(
"
No prior file given.
"
)
prior
=
None
else
:
...
...
@@ -188,7 +188,7 @@ def create_default_prior(name, default_priors_file=None):
if
name
in
default_priors
.
keys
():
prior
=
default_priors
[
name
]
else
:
logging
.
info
(
logging
.
debug
(
"
No default prior found for variable {}.
"
.
format
(
name
))
prior
=
None
return
prior
...
...
@@ -579,7 +579,7 @@ class Interped(Prior):
def
__initialize_attributes
(
self
):
if
np
.
trapz
(
self
.
yy
,
self
.
xx
)
!=
1
:
logging
.
info
(
'
Supplied PDF for {} is not normalised, normalising.
'
.
format
(
self
.
name
))
logging
.
debug
(
'
Supplied PDF for {} is not normalised, normalising.
'
.
format
(
self
.
name
))
self
.
yy
/=
np
.
trapz
(
self
.
yy
,
self
.
xx
)
self
.
YY
=
cumtrapz
(
self
.
yy
,
self
.
xx
,
initial
=
0
)
# Need last element of cumulative distribution to be exactly one.
...
...
This diff is collapsed.
Click to expand it.
tupak/core/result.py
+
3
−
3
View file @
29b42cc9
...
...
@@ -91,12 +91,12 @@ class Result(dict):
if
os
.
path
.
isdir
(
self
.
outdir
)
is
False
:
os
.
makedirs
(
self
.
outdir
)
if
os
.
path
.
isfile
(
file_name
):
logging
.
info
(
logging
.
debug
(
'
Renaming existing file {} to {}.old
'
.
format
(
file_name
,
file_name
))
os
.
rename
(
file_name
,
file_name
+
'
.old
'
)
logging
.
info
(
"
Saving result to {}
"
.
format
(
file_name
))
logging
.
debug
(
"
Saving result to {}
"
.
format
(
file_name
))
try
:
deepdish
.
io
.
save
(
file_name
,
self
.
get_result_dictionary
())
except
Exception
as
e
:
...
...
@@ -183,7 +183,7 @@ class Result(dict):
if
save
:
filename
=
'
{}/{}_corner.png
'
.
format
(
self
.
outdir
,
self
.
label
)
logging
.
info
(
'
Saving corner plot to {}
'
.
format
(
filename
))
logging
.
debug
(
'
Saving corner plot to {}
'
.
format
(
filename
))
fig
.
savefig
(
filename
,
dpi
=
dpi
)
return
fig
...
...
This diff is collapsed.
Click to expand it.
tupak/core/sampler.py
+
10
−
8
View file @
29b42cc9
...
...
@@ -130,7 +130,7 @@ class Sampler(object):
logging
.
info
(
"
Search parameters:
"
)
for
key
in
self
.
__search_parameter_keys
:
logging
.
info
(
'
{}
~
{}
'
.
format
(
key
,
self
.
priors
[
key
]))
logging
.
info
(
'
{}
=
{}
'
.
format
(
key
,
self
.
priors
[
key
]))
for
key
in
self
.
__fixed_parameter_keys
:
logging
.
info
(
'
{} = {}
'
.
format
(
key
,
self
.
priors
[
key
].
peak
))
...
...
@@ -156,7 +156,8 @@ class Sampler(object):
t1
=
datetime
.
datetime
.
now
()
self
.
likelihood
.
log_likelihood
()
logging
.
info
(
"
Single likelihood eval. took {:.3e} s
"
.
format
((
datetime
.
datetime
.
now
()
-
t1
).
total_seconds
()))
"
Single likelihood evaluation took {:.3e} s
"
.
format
((
datetime
.
datetime
.
now
()
-
t1
).
total_seconds
()))
except
TypeError
as
e
:
raise
TypeError
(
"
Likelihood evaluation failed with message:
\n
'
{}
'
\n
"
...
...
@@ -212,9 +213,9 @@ class Sampler(object):
"""
draw
=
np
.
array
(
list
(
self
.
priors
.
sample_subset
(
self
.
__search_parameter_keys
).
values
()))
if
np
.
isinf
(
self
.
log_likelihood
(
draw
)):
logging
.
info
(
'
Prior draw {} has inf likelihood
'
.
format
(
draw
))
logging
.
warning
(
'
Prior draw {} has inf likelihood
'
.
format
(
draw
))
if
np
.
isinf
(
self
.
log_prior
(
draw
)):
logging
.
info
(
'
Prior draw {} has inf prior
'
.
format
(
draw
))
logging
.
warning
(
'
Prior draw {} has inf prior
'
.
format
(
draw
))
return
draw
def
_run_external_sampler
(
self
):
...
...
@@ -396,7 +397,7 @@ class Dynesty(Sampler):
def
generate_trace_plots
(
self
,
dynesty_results
):
filename
=
'
{}/{}_trace.png
'
.
format
(
self
.
outdir
,
self
.
label
)
logging
.
info
(
"
Writing trace plot to {}
"
.
format
(
filename
))
logging
.
debug
(
"
Writing trace plot to {}
"
.
format
(
filename
))
from
dynesty
import
plotting
as
dyplot
fig
,
axes
=
dyplot
.
traceplot
(
dynesty_results
,
labels
=
self
.
result
.
parameter_labels
)
...
...
@@ -504,7 +505,7 @@ class Ptemcee(Sampler):
fig
.
tight_layout
()
filename
=
'
{}/{}_walkers.png
'
.
format
(
self
.
outdir
,
self
.
label
)
logging
.
info
(
'
Saving walkers plot to {}
'
.
format
(
'
filename
'
))
logging
.
debug
(
'
Saving walkers plot to {}
'
.
format
(
'
filename
'
))
fig
.
savefig
(
filename
)
...
...
@@ -580,7 +581,7 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
**
kwargs
)
if
sampler
.
cached_result
:
logging
.
info
(
"
Using cached result
"
)
logging
.
warning
(
"
Using cached result
"
)
return
sampler
.
cached_result
start_time
=
datetime
.
datetime
.
now
()
...
...
@@ -592,7 +593,6 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
end_time
=
datetime
.
datetime
.
now
()
result
.
sampling_time
=
(
end_time
-
start_time
).
total_seconds
()
logging
.
info
(
''
)
logging
.
info
(
'
Sampling time: {}
'
.
format
(
end_time
-
start_time
))
if
sampler
.
use_ratio
:
...
...
@@ -615,6 +615,8 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
result
.
save_to_file
()
if
plot
:
result
.
plot_corner
()
logging
.
info
(
"
Sampling finished, results saved to {}/
"
.
format
(
outdir
))
logging
.
info
(
"
Summary of results:
\n
{}
"
.
format
(
result
))
return
result
else
:
raise
ValueError
(
...
...
This diff is collapsed.
Click to expand it.
tupak/core/utils.py
+
5
−
4
View file @
29b42cc9
...
...
@@ -219,9 +219,10 @@ def setup_logger(outdir=None, label=None, log_level=None):
file_handler
.
setLevel
(
LEVEL
)
logger
.
addHandler
(
file_handler
)
version_file
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
)),
'
.version
'
)
version_file
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
)),
'
.version
'
)
with
open
(
version_file
,
'
r
'
)
as
f
:
version
=
f
.
readline
()
version
=
f
.
readline
()
.
rstrip
()
logging
.
info
(
'
Running tupak version: {}
'
.
format
(
version
))
...
...
@@ -300,8 +301,8 @@ command_line_args = set_up_command_line_arguments()
if
'
DISPLAY
'
in
os
.
environ
:
pass
else
:
logging
.
info
(
'
No $DISPLAY environment variable found, so importing
\
matplotlib.pyplot with non-interactive
"
Agg
"
backend.
'
)
logging
.
debug
(
'
No $DISPLAY environment variable found, so importing
\
matplotlib.pyplot with non-interactive
"
Agg
"
backend.
'
)
import
matplotlib
matplotlib
.
use
(
'
Agg
'
)
...
...
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