-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from joezuntz/fix-sampler-chain
Fix bug in sampler chaining and add test
- Loading branch information
Showing
4 changed files
with
77 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from cosmosis.runtime.config import Inifile | ||
from cosmosis.main import run_cosmosis, parser | ||
import tempfile | ||
import os | ||
import sys | ||
import pytest | ||
import numpy as np | ||
|
||
|
||
def test_sampler_chain(): | ||
|
||
|
||
with tempfile.TemporaryDirectory() as dirname: | ||
values_file = f"{dirname}/values.txt" | ||
maxlike_file = f"{dirname}/chain.maxlike.txt" | ||
fisher_file = f"{dirname}/chain.fisher.txt" | ||
emcee_file = f"{dirname}/chain.txt" | ||
with open(values_file, "w") as values: | ||
values.write( | ||
"[parameters]\n" | ||
"p1=-3.0 0.0 3.0\n" | ||
"p2=-3.0 0.0 3.0\n") | ||
|
||
params = { | ||
('runtime', 'root'): os.path.split(os.path.abspath(__file__))[0], | ||
('runtime', 'sampler'): "maxlike fisher emcee", | ||
("pipeline", "debug"): "T", | ||
("pipeline", "quiet"): "F", | ||
("pipeline", "modules"): "test1", | ||
("pipeline", "extra_output"): "parameters/p3", | ||
("pipeline", "values"): values_file, | ||
("test1", "file"): "test_module.py", | ||
("output", "filename"): emcee_file, | ||
("emcee", "walkers"): "8", | ||
("emcee", "samples"): "100", | ||
("maxlike", "tolerance"): "0.05", | ||
("fisher", "step_size"): "0.01" | ||
} | ||
|
||
|
||
args = parser.parse_args(["not_a_real_file"]) | ||
ini = Inifile(None, override=params) | ||
|
||
status = run_cosmosis(args, ini=ini) | ||
|
||
data = np.loadtxt(fisher_file) | ||
print(data.shape) | ||
|
||
data = np.loadtxt(maxlike_file) | ||
print(data.shape) | ||
|
||
data = np.loadtxt(emcee_file) | ||
print(data.shape) | ||
|
||
|
||
|
||
assert status == 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '2.0.1' | ||
__version__ = '2.0.2' |