def profile_system(): import pycuda.driver # pycuda.driver.initialize_profiler() # initialize sampler myDriver = orbitize.driver.Driver(input_file, 'OFTI', 1, 1.22, 56.95, mass_err=0.08, plx_err=0.26) s = myDriver.sampler # change eccentricity prior myDriver.system.sys_priors[1] = priors.LinearPrior(-2.18, 2.01) # test num_samples=1 s.run_sampler(0, num_samples=1) # test to make sure outputs are reasonable pycuda.driver.start_profiler() start = time.time() orbitize.cext = True orbitize.cuda_ext = True orbits = s.run_sampler(30000, num_samples=10000, num_cores=1) end = time.time() print() print("CUDA Runtime: " + str(end - start) + " s") print() print(orbits[0]) start = time.time() orbitize.cext = True orbitize.cuda_ext = False orbits = s.run_sampler(30000) end = time.time() pycuda.driver.stop_profiler() print() print("MULTIPROCESSING Runtime: " + str(end - start) + " s") print() print(orbits[0]) start = time.time() orbitize.cext = True orbitize.cuda_ext = False orbits = s.run_sampler(30000, num_cores=1) end = time.time() pycuda.driver.stop_profiler() pycuda.autoinit.context.detach() print() print("single threaded Runtime: " + str(end - start) + " s") print() print(orbits[0])
def test_run_sampler(): # initialize sampler myDriver = orbitize.driver.Driver(input_file, 'OFTI', 1, 1.22, 56.95,mass_err=0.08, plx_err=0.26) s = myDriver.sampler # change eccentricity prior myDriver.system.sys_priors[1] = priors.LinearPrior(-2.18, 2.01) # test num_samples=1 s.run_sampler(0,num_samples=1) # test to make sure outputs are reasonable start=time.time() orbits = s.run_sampler(1000,num_cores=4) end=time.time() print() print("Runtime: "+str(end-start) +" s") print() print(orbits[0]) # test that lnlikes being saved are correct returned_lnlike_test = s.results.lnlike[0] computed_lnlike_test = s._logl(orbits[0]) assert returned_lnlike_test == pytest.approx(computed_lnlike_test, abs=0.01) print() idx = s.system.param_idx sma = np.median([x[idx['sma1']] for x in orbits]) ecc = np.median([x[idx['ecc1']] for x in orbits]) inc = np.median([x[idx['inc1']] for x in orbits]) # expected values from Blunt et al. (2017) sma_exp = 48. ecc_exp = 0.19 inc_exp = np.radians(140) # test to make sure OFTI values are within 20% of expectations assert sma == pytest.approx(sma_exp, abs=0.2*sma_exp) assert ecc == pytest.approx(ecc_exp, abs=0.2*ecc_exp) assert inc == pytest.approx(inc_exp, abs=0.2*inc_exp) # test with only one core orbits = s.run_sampler(100,num_cores=1) # test with only one epoch myDriver = orbitize.driver.Driver(input_file_1epoch, 'OFTI', 1, 1.22, 56.95,mass_err=0.08, plx_err=0.26) s = myDriver.sampler s.run_sampler(1) print()
def test_run_sampler(): # initialize sampler myDriver = orbitize.driver.Driver(input_file, 'OFTI', 1, 1.22, 56.95, mass_err=0.08, plx_err=0.26) s = myDriver.sampler # change eccentricity prior myDriver.system.sys_priors[1] = priors.LinearPrior(-2.18, 2.01) # test num_samples=1 s.run_sampler(0, num_samples=1) # test to make sure outputs are reasonable orbits = s.run_sampler(1000) print() idx = s.system.param_idx sma = np.median([x[idx['sma1']] for x in orbits]) ecc = np.median([x[idx['ecc1']] for x in orbits]) inc = np.median([x[idx['inc1']] for x in orbits]) # expected values from Blunt et al. (2017) sma_exp = 48. ecc_exp = 0.19 inc_exp = np.radians(140) # test to make sure OFTI values are within 20% of expectations assert sma == pytest.approx(sma_exp, abs=0.2 * sma_exp) assert ecc == pytest.approx(ecc_exp, abs=0.2 * ecc_exp) assert inc == pytest.approx(inc_exp, abs=0.2 * inc_exp) # test with only one epoch myDriver = orbitize.driver.Driver(input_file_1epoch, 'OFTI', 1, 1.22, 56.95, mass_err=0.08, plx_err=0.26) s = myDriver.sampler s.run_sampler(1) print()
def test_OFTI_covariances(): """ Test OFTI fits by turning sep/pa measurements to RA/Dec measurements with covariances Needs to be run after test_run_sampler()!! """ # only run if these variables are set. if sma_seppa == 0 or seppa_lnprob_compare is None: print( "Skipping OFTI covariances test because reference data not initalized. Please make sure test_run_sampler is run first." ) return # read in seppa data table and turn into raddec data table data_table = orbitize.read_input.read_file(input_file) data_ra, data_dec = system.seppa2radec(data_table['quant1'], data_table['quant2']) data_raerr, data_decerr, data_radeccorr = [], [], [] for row in data_table: raerr, decerr, radec_corr = system.transform_errors(row['quant1'], row['quant2'], row['quant1_err'], row['quant2_err'], 0, system.seppa2radec, nsamps=10000000) data_raerr.append(raerr) data_decerr.append(decerr) data_radeccorr.append(radec_corr) data_table['quant1'] = data_ra data_table['quant2'] = data_dec data_table['quant1_err'] = np.array(data_raerr) data_table['quant2_err'] = np.array(data_decerr) data_table['quant12_corr'] = np.array(data_radeccorr) data_table['quant_type'] = np.array(['radec' for _ in data_table]) # initialize system my_sys = system.System(1, data_table, 1.22, 56.95, mass_err=0.08, plx_err=0.26) # initialize sampler s = sampler.OFTI(my_sys) # change eccentricity prior my_sys.sys_priors[1] = priors.LinearPrior(-2.18, 2.01) # test num_samples=1 s.run_sampler(0, num_samples=1) # test to make sure outputs are reasonable orbits = s.run_sampler(1000, num_cores=4) # test that lnlikes being saved are correct returned_lnlike_test = s.results.lnlike[0] computed_lnlike_test = s._logl(orbits[0]) assert returned_lnlike_test == pytest.approx(computed_lnlike_test, abs=0.01) # test that the lnlike is very similar to the values computed in seppa space ref_params, ref_lnlike = seppa_lnprob_compare computed_lnlike_ref = s._logl(ref_params) assert ref_lnlike == pytest.approx( computed_lnlike_ref, abs=0.05) # 5% differencesin lnprob is allowable. idx = s.system.param_idx sma = np.median([x[idx['sma1']] for x in orbits]) ecc = np.median([x[idx['ecc1']] for x in orbits]) inc = np.median([x[idx['inc1']] for x in orbits]) # test against seppa fits to see they are similar assert sma_seppa == pytest.approx(sma, abs=0.2 * sma_seppa)