def test_random_agent_loop(self): df = load_default_atf_data() n_seed = 200 # Starting sample size agent = RandomAgent(n_query=10) analyzer = StabilityAnalyzer(hull_distance=0.05, parallel=False) experiment = ATFSampler(dataframe=df) candidate_data = df new_loop = Campaign(candidate_data, agent, experiment, analyzer, create_seed=n_seed) new_loop.initialize() self.assertFalse(new_loop.create_seed) for _ in range(6): new_loop.run() self.assertTrue(True) # Testing the continuation new_loop = Campaign(candidate_data, agent, experiment, analyzer, create_seed=n_seed) self.assertTrue(new_loop.initialized) self.assertEqual(new_loop.iteration, 6) self.assertEqual(new_loop.loop_state, None) new_loop.run() self.assertTrue(True) self.assertEqual(new_loop.iteration, 7)
def test_mp_loop(self): df = pd.read_csv(os.path.join(CAMD_TEST_FILES, 'test_df_analysis.csv')) df['id'] = [int(mp_id.replace("mp-", "").replace('mvc-', '')) for mp_id in df['id']] df.set_index("id") df['Composition'] = df['formula'] # Just use the Ti-O-N chemsys seed = df.iloc[:38] candidates = df.iloc[38:209] agent = RandomAgent(n_query=20) analyzer = StabilityAnalyzer(hull_distance=0.05, parallel=False) experiment = ATFSampler(dataframe=df) new_loop = Campaign( candidates, agent, experiment, analyzer, seed_data=seed ) new_loop.initialize() for iteration in range(6): new_loop.run() self.assertTrue(os.path.isfile("hull.png")) if iteration >= 1: self.assertTrue( os.path.isfile("history.pickle")) # Testing the continuation new_loop = Campaign(df, agent, experiment, analyzer) self.assertTrue(new_loop.initialized) self.assertEqual(new_loop.iteration, 6) self.assertEqual(new_loop.loop_state, None) new_loop.run() self.assertTrue(True) self.assertEqual(new_loop.iteration, 7)
def test_random_agent_loop(self): df = load_dataframe("oqmd1.2_exp_based_entries_featurized_v2") n_seed = 5000 agent = RandomAgent(n_query=200) analyzer = StabilityAnalyzer(hull_distance=0.05, parallel=False) experiment = ATFSampler(dataframe=df) candidate_data = df new_loop = Campaign(candidate_data, agent, experiment, analyzer, create_seed=n_seed) new_loop.initialize() self.assertFalse(new_loop.create_seed) for _ in range(6): new_loop.run() self.assertTrue(True)
def test_gp_ucb_generic(self): def f(x): return np.sin(x) * np.sin(x) * (x ** 2) x = np.linspace(0, 10, 500) y = f(x) df = pd.DataFrame({'x': x, 'target': y}) N_query = 2 # This many experiments are requested in each iteration N_seed = 5 # This many samples are randomly acquired in the beginning to form a seed. agent = GenericGPUCB(n_query=2,kernel=ConstantKernel(100.0) + RBF(10.0) * ConstantKernel(1.0)) analyzer = GenericMaxAnalyzer(threshold=58) experiment = ATFSampler(dataframe=df) candidate_data = df new_loop = Campaign(candidate_data, agent, experiment, analyzer, create_seed=N_seed) new_loop.initialize(random_state=20) self.assertTrue(new_loop.initialized) new_loop.run() self.assertTrue(True)