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
3eb8f017
Commit
3eb8f017
authored
6 years ago
by
Colm Talbot
Browse files
Options
Downloads
Patches
Plain Diff
make pickle names consistent
parent
6e249e8a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!385
make pickle names consistent
Pipeline
#50612
passed
6 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bilby/core/sampler/dynesty.py
+30
-74
30 additions, 74 deletions
bilby/core/sampler/dynesty.py
with
30 additions
and
74 deletions
bilby/core/sampler/dynesty.py
+
30
−
74
View file @
3eb8f017
...
...
@@ -104,6 +104,8 @@ class Dynesty(NestedSampler):
n_check_point_rnd
=
int
(
float
(
"
{:1.0g}
"
.
format
(
n_check_point_raw
)))
self
.
n_check_point
=
n_check_point_rnd
self
.
resume_file
=
'
{}/{}_resume.pickle
'
.
format
(
self
.
outdir
,
self
.
label
)
signal
.
signal
(
signal
.
SIGTERM
,
self
.
write_current_state_and_exit
)
signal
.
signal
(
signal
.
SIGINT
,
self
.
write_current_state_and_exit
)
...
...
@@ -240,15 +242,15 @@ class Dynesty(NestedSampler):
def
_remove_checkpoint
(
self
):
"""
Remove checkpointed state
"""
if
os
.
path
.
isfile
(
'
{}/{}_resume.h5
'
.
format
(
self
.
outdir
,
self
.
label
)
):
os
.
remove
(
'
{}/{}_resume.h5
'
.
format
(
self
.
outdir
,
self
.
label
)
)
if
os
.
path
.
isfile
(
self
.
resume_file
):
os
.
remove
(
self
.
resume_file
)
def
read_saved_state
(
self
,
continuing
=
False
):
"""
Read a saved state of the sampler to disk.
The required information to reconstruct the state of the run is read
from a
n hdf5
file.
from a
pickle
file.
This currently adds the whole chain to the sampler.
We then remove the old checkpoint and write all unnecessary items back
to disk.
...
...
@@ -262,13 +264,14 @@ class Dynesty(NestedSampler):
Whether the run is continuing or terminating, if True, the loaded
state is mostly written back to disk.
"""
resume_file
=
'
{}/{}_resume.pickle
'
.
format
(
self
.
outdir
,
self
.
label
)
logger
.
debug
(
"
Reading resume file {}
"
.
format
(
resume_file
))
if
os
.
path
.
isfile
(
resume_file
):
with
open
(
resume_file
,
'
rb
'
)
as
file
:
logger
.
debug
(
"
Reading resume file {}
"
.
format
(
self
.
resume_file
))
if
os
.
path
.
isfile
(
self
.
resume_file
):
with
open
(
self
.
resume_file
,
'
rb
'
)
as
file
:
saved
=
pickle
.
load
(
file
)
logger
.
debug
(
"
Succesfuly read resume file {}
"
.
format
(
resume_file
))
logger
.
debug
(
"
Succesfuly read resume file {}
"
.
format
(
self
.
resume_file
))
self
.
sampler
.
saved_u
=
list
(
saved
[
'
unit_cube_samples
'
])
self
.
sampler
.
saved_v
=
list
(
saved
[
'
physical_samples
'
])
...
...
@@ -299,6 +302,8 @@ class Dynesty(NestedSampler):
return
True
else
:
logger
.
debug
(
"
Failed to read resume file {}
"
.
format
(
self
.
resume_file
))
return
False
def
write_current_state_and_exit
(
self
,
signum
=
None
,
frame
=
None
):
...
...
@@ -323,57 +328,23 @@ class Dynesty(NestedSampler):
NestedSampler to write to disk.
"""
check_directory_exists_and_if_not_mkdir
(
self
.
outdir
)
resume_file
=
'
{}/{}_resume.pickle
'
.
format
(
self
.
outdir
,
self
.
label
)
if
os
.
path
.
isfile
(
resume_file
):
with
open
(
resume_file
,
'
rb
'
)
as
file
:
saved
=
pickle
.
load
(
file
)
current_state
=
dict
(
unit_cube_samples
=
np
.
vstack
([
saved
[
'
unit_cube_samples
'
],
self
.
sampler
.
saved_u
[
1
:]]),
physical_samples
=
np
.
vstack
([
saved
[
'
physical_samples
'
],
self
.
sampler
.
saved_v
[
1
:]]),
sample_likelihoods
=
np
.
concatenate
([
saved
[
'
sample_likelihoods
'
],
self
.
sampler
.
saved_logl
[
1
:]]),
sample_log_volume
=
np
.
concatenate
([
saved
[
'
sample_log_volume
'
],
self
.
sampler
.
saved_logvol
[
1
:]]),
sample_log_weights
=
np
.
concatenate
([
saved
[
'
sample_log_weights
'
],
self
.
sampler
.
saved_logwt
[
1
:]]),
cumulative_log_evidence
=
np
.
concatenate
([
saved
[
'
cumulative_log_evidence
'
],
self
.
sampler
.
saved_logz
[
1
:]]),
cumulative_log_evidence_error
=
np
.
concatenate
([
saved
[
'
cumulative_log_evidence_error
'
],
self
.
sampler
.
saved_logzvar
[
1
:]]),
cumulative_information
=
np
.
concatenate
([
saved
[
'
cumulative_information
'
],
self
.
sampler
.
saved_h
[
1
:]]),
id
=
np
.
concatenate
([
saved
[
'
id
'
],
self
.
sampler
.
saved_id
[
1
:]]),
it
=
np
.
concatenate
([
saved
[
'
it
'
],
self
.
sampler
.
saved_it
[
1
:]]),
nc
=
np
.
concatenate
([
saved
[
'
nc
'
],
self
.
sampler
.
saved_nc
[
1
:]]),
boundidx
=
np
.
concatenate
([
saved
[
'
boundidx
'
],
self
.
sampler
.
saved_boundidx
[
1
:]]),
bounditer
=
np
.
concatenate
([
saved
[
'
bounditer
'
],
self
.
sampler
.
saved_bounditer
[
1
:]]),
scale
=
np
.
concatenate
([
saved
[
'
scale
'
],
self
.
sampler
.
saved_scale
[
1
:]]),
)
else
:
current_state
=
dict
(
unit_cube_samples
=
self
.
sampler
.
saved_u
,
physical_samples
=
self
.
sampler
.
saved_v
,
sample_likelihoods
=
self
.
sampler
.
saved_logl
,
sample_log_volume
=
self
.
sampler
.
saved_logvol
,
sample_log_weights
=
self
.
sampler
.
saved_logwt
,
cumulative_log_evidence
=
self
.
sampler
.
saved_logz
,
cumulative_log_evidence_error
=
self
.
sampler
.
saved_logzvar
,
cumulative_information
=
self
.
sampler
.
saved_h
,
id
=
self
.
sampler
.
saved_id
,
it
=
self
.
sampler
.
saved_it
,
nc
=
self
.
sampler
.
saved_nc
,
boundidx
=
self
.
sampler
.
saved_boundidx
,
bounditer
=
self
.
sampler
.
saved_bounditer
,
scale
=
self
.
sampler
.
saved_scale
,
)
current_state
=
dict
(
unit_cube_samples
=
self
.
sampler
.
saved_u
,
physical_samples
=
self
.
sampler
.
saved_v
,
sample_likelihoods
=
self
.
sampler
.
saved_logl
,
sample_log_volume
=
self
.
sampler
.
saved_logvol
,
sample_log_weights
=
self
.
sampler
.
saved_logwt
,
cumulative_log_evidence
=
self
.
sampler
.
saved_logz
,
cumulative_log_evidence_error
=
self
.
sampler
.
saved_logzvar
,
cumulative_information
=
self
.
sampler
.
saved_h
,
id
=
self
.
sampler
.
saved_id
,
it
=
self
.
sampler
.
saved_it
,
nc
=
self
.
sampler
.
saved_nc
,
boundidx
=
self
.
sampler
.
saved_boundidx
,
bounditer
=
self
.
sampler
.
saved_bounditer
,
scale
=
self
.
sampler
.
saved_scale
,
)
current_state
.
update
(
ncall
=
self
.
sampler
.
ncall
,
live_logl
=
self
.
sampler
.
live_logl
,
...
...
@@ -392,24 +363,9 @@ class Dynesty(NestedSampler):
except
ValueError
:
logger
.
debug
(
"
Unable to create posterior
"
)
with
open
(
resume_file
,
'
wb
'
)
as
file
:
with
open
(
self
.
resume_file
,
'
wb
'
)
as
file
:
pickle
.
dump
(
current_state
,
file
)
self
.
sampler
.
saved_id
=
[
self
.
sampler
.
saved_id
[
-
1
]]
self
.
sampler
.
saved_u
=
[
self
.
sampler
.
saved_u
[
-
1
]]
self
.
sampler
.
saved_v
=
[
self
.
sampler
.
saved_v
[
-
1
]]
self
.
sampler
.
saved_logl
=
[
self
.
sampler
.
saved_logl
[
-
1
]]
self
.
sampler
.
saved_logvol
=
[
self
.
sampler
.
saved_logvol
[
-
1
]]
self
.
sampler
.
saved_logwt
=
[
self
.
sampler
.
saved_logwt
[
-
1
]]
self
.
sampler
.
saved_logz
=
[
self
.
sampler
.
saved_logz
[
-
1
]]
self
.
sampler
.
saved_logzvar
=
[
self
.
sampler
.
saved_logzvar
[
-
1
]]
self
.
sampler
.
saved_h
=
[
self
.
sampler
.
saved_h
[
-
1
]]
self
.
sampler
.
saved_nc
=
[
self
.
sampler
.
saved_nc
[
-
1
]]
self
.
sampler
.
saved_boundidx
=
[
self
.
sampler
.
saved_boundidx
[
-
1
]]
self
.
sampler
.
saved_it
=
[
self
.
sampler
.
saved_it
[
-
1
]]
self
.
sampler
.
saved_bounditer
=
[
self
.
sampler
.
saved_bounditer
[
-
1
]]
self
.
sampler
.
saved_scale
=
[
self
.
sampler
.
saved_scale
[
-
1
]]
def
generate_trace_plots
(
self
,
dynesty_results
):
check_directory_exists_and_if_not_mkdir
(
self
.
outdir
)
filename
=
'
{}/{}_trace.png
'
.
format
(
self
.
outdir
,
self
.
label
)
...
...
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