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
b30462d0
Commit
b30462d0
authored
5 years ago
by
Colm Talbot
Committed by
Moritz Huebner
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add basic waveform caching
parent
971deb31
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bilby/gw/waveform_generator.py
+5
-0
5 additions, 0 deletions
bilby/gw/waveform_generator.py
test/waveform_generator_test.py
+27
-0
27 additions, 0 deletions
test/waveform_generator_test.py
with
32 additions
and
0 deletions
bilby/gw/waveform_generator.py
+
5
−
0
View file @
b30462d0
...
...
@@ -62,6 +62,7 @@ class WaveformGenerator(object):
self
.
waveform_arguments
=
dict
()
if
isinstance
(
parameters
,
dict
):
self
.
parameters
=
parameters
self
.
_cache
=
dict
(
parameters
=
None
,
waveform
=
None
)
def
__repr__
(
self
):
if
self
.
frequency_domain_source_model
is
not
None
:
...
...
@@ -147,6 +148,8 @@ class WaveformGenerator(object):
transformed_model_data_points
,
parameters
):
if
parameters
is
not
None
:
self
.
parameters
=
parameters
if
self
.
parameters
==
self
.
_cache
[
'
parameters
'
]:
return
self
.
_cache
[
'
waveform
'
]
if
model
is
not
None
:
model_strain
=
self
.
_strain_from_model
(
model_data_points
,
model
)
elif
transformed_model
is
not
None
:
...
...
@@ -154,6 +157,8 @@ class WaveformGenerator(object):
transformation_function
)
else
:
raise
RuntimeError
(
"
No source model given
"
)
self
.
_cache
[
'
waveform
'
]
=
model_strain
self
.
_cache
[
'
parameters
'
]
=
self
.
parameters
.
copy
()
return
model_strain
def
_strain_from_model
(
self
,
model_data_points
,
model
):
...
...
This diff is collapsed.
Click to expand it.
test/waveform_generator_test.py
+
27
−
0
View file @
b30462d0
...
...
@@ -263,6 +263,19 @@ class TestFrequencyDomainStrainMethod(unittest.TestCase):
self
.
assertListEqual
(
sorted
(
self
.
waveform_generator
.
parameters
.
keys
()),
sorted
([
'
amplitude
'
,
'
mu
'
,
'
sigma
'
,
'
ra
'
,
'
dec
'
,
'
geocent_time
'
,
'
psi
'
]))
def
test_caching_with_parameters
(
self
):
original_waveform
=
self
.
waveform_generator
.
frequency_domain_strain
(
parameters
=
self
.
simulation_parameters
)
new_waveform
=
self
.
waveform_generator
.
frequency_domain_strain
(
parameters
=
self
.
simulation_parameters
)
self
.
assertDictEqual
(
original_waveform
,
new_waveform
)
def
test_caching_without_parameters
(
self
):
original_waveform
=
self
.
waveform_generator
.
frequency_domain_strain
(
parameters
=
self
.
simulation_parameters
)
new_waveform
=
self
.
waveform_generator
.
frequency_domain_strain
()
self
.
assertDictEqual
(
original_waveform
,
new_waveform
)
class
TestTimeDomainStrainMethod
(
unittest
.
TestCase
):
...
...
@@ -354,6 +367,20 @@ class TestTimeDomainStrainMethod(unittest.TestCase):
self
.
assertListEqual
(
sorted
(
self
.
waveform_generator
.
parameters
.
keys
()),
sorted
([
'
amplitude
'
,
'
mu
'
,
'
sigma
'
,
'
ra
'
,
'
dec
'
,
'
geocent_time
'
,
'
psi
'
]))
def
test_caching_with_parameters
(
self
):
original_waveform
=
self
.
waveform_generator
.
time_domain_strain
(
parameters
=
self
.
simulation_parameters
)
new_waveform
=
self
.
waveform_generator
.
time_domain_strain
(
parameters
=
self
.
simulation_parameters
)
self
.
assertDictEqual
(
original_waveform
,
new_waveform
)
def
test_caching_without_parameters
(
self
):
original_waveform
=
self
.
waveform_generator
.
time_domain_strain
(
parameters
=
self
.
simulation_parameters
)
new_waveform
=
self
.
waveform_generator
.
time_domain_strain
()
self
.
assertDictEqual
(
original_waveform
,
new_waveform
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
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