Example #1
0
 def test_simulated(self):
     exp_dataframe = pd.read_pickle(
         os.path.join(CAMD_TEST_FILES, "mn-ni-o-sb.pickle"))
     experiment = ATFSampler(exp_dataframe)
     candidate_data = exp_dataframe.iloc[:, :-11]
     # Set up agents and loop parameters
     agent = AgentStabilityAdaBoost(
         model=MLPRegressor(hidden_layer_sizes=(84, 50)),
         n_query=2,
         hull_distance=0.2,
         exploit_fraction=1.0,
         uncertainty=True,
         alpha=0.5,
         diversify=True,
         n_estimators=20)
     analyzer = StabilityAnalyzer(hull_distance=0.2)
     # Reduce seed_data
     icsd_data = load_dataframe("oqmd1.2_exp_based_entries_featurized_v2")
     seed_data = filter_dataframe_by_composition(icsd_data, "MnNiOSb")
     leftover = ~icsd_data.index.isin(seed_data.index)
     # Add some random other data to test compositional flexibility
     seed_data = seed_data.append(icsd_data.loc[leftover].sample(30))
     del icsd_data
     with ScratchDir('.'):
         campaign = ProtoDFTCampaign(candidate_data=candidate_data,
                                     agent=agent,
                                     experiment=experiment,
                                     analyzer=analyzer,
                                     seed_data=seed_data,
                                     heuristic_stopper=5)
         campaign.autorun()
         self.assertTrue(os.path.isfile('hull_finalized.png'))
Example #2
0
 def test_simple_dft(self):
     with ScratchDir('.'):
         campaign = ProtoDFTCampaign.from_chemsys("Si")
         # Nerf agent a bit
         agent = AgentStabilityML5(n_query=2)
         campaign.agent = agent
         campaign.autorun()
Example #3
0
    def run_campaign(self, **kwargs):
        """
        Runs the campaign for a given chemsys

        Args:
            **kwargs: keyword-args for a given campaign,
                specific to invocation method below i. e.

                proto-dft/oqmd-atf require {'chemsys': CHEMSYS}
                meta-agent requires {'name': NAME}

        Returns:
            None

        """
        if self.campaign == "proto-dft-2":
            campaign = ProtoDFTCampaign.from_chemsys(**kwargs)
        elif self.campaign == "oqmd-atf":
            # This is more or less just a test
            campaign = CloudATFCampaign.from_chemsys(**kwargs)
        elif self.campaign.startswith("meta-agent"):
            # For meta-agent campaigns, submit with meta_agent/CAMPAIGN_NAME
            campaign = MetaAgentCampaign.from_reserved_name(**kwargs)
        else:
            raise ValueError("Campaign {} is not valid".format(self.campaign))
        campaign.autorun()
Example #4
0
def main():
    """Utility function to run a reserved name campaign"""
    args = docopt(__doc__)
    campaign_type = args['CAMPAIGN_TYPE']
    campaign_name = args['CAMPAIGN_NAME']
    cwd = os.getcwd()
    if args['--scratch']:
        dirpath = tempfile.mkdtemp()
        os.chdir(dirpath)

    # Switch for different campaign types
    if campaign_type.startswith("proto-dft"):
        prefix = "{}/runs".format(campaign_type)
        campaign = ProtoDFTCampaign.from_chemsys(campaign_name, prefix=prefix)
    elif campaign_type == "meta_agent":
        campaign = MetaAgentCampaign.from_reserved_name(campaign_name)
    else:
        raise ValueError(
            "{} is not a supported campaign type".format(campaign_type))

    campaign.autorun()

    # Cleanup
    if args['--scratch']:
        os.chdir(cwd)
        shutil.rmtree(dirpath)
Example #5
0
    def run_campaign(self, *args):
        """
        Runs the campaign for a given chemsys

        Args:
            *args: args for a given campaign,
                specific to invocation method below i. e.

                proto-dft/oqmd-atf require CHEMSYS
                meta-agent requires NAME

        Returns:
            None

        """
        if self.campaign.startswith("proto-dft-high"):
            campaign = ProtoDFTCampaign.from_chemsys_high_quality(*args)
        elif self.campaign.startswith("proto-dft"):
            campaign = ProtoDFTCampaign.from_chemsys(*args)
        elif self.campaign.startswith("oqmd-atf"):
            # This is more or less just a test
            campaign = CloudATFCampaign.from_chemsys(*args)
        elif self.campaign.startswith("meta-agent"):
            # For meta-agent campaigns, submit with meta_agent/CAMPAIGN_NAME
            campaign = MetaAgentCampaign.from_reserved_name(*args)
        else:
            raise ValueError("Campaign {} is not valid".format(self.campaign))

        # Capture errors and store
        if self.catch_errors:
            try:
                campaign.autorun()
            except Exception as e:
                error_msg = {
                    "error": "{}".format(e),
                    "traceback": traceback.format_exc()
                }
                campaign.logger.info("Error: {}".format(e))
                campaign.logger.info("Traceback: {}".format(
                    traceback.format_exc()))
                dumpfn(error_msg, "error.json")
                dumpfn({"status": "error"}, "job_status.json")
                campaign.s3_sync()
        else:
            campaign.autorun()
Example #6
0
 def test_simulated(self):
     exp_dataframe = pd.read_pickle(
         os.path.join(CAMD_TEST_FILES, "mn-ni-o-sb.pickle"))
     experiment = ATFSampler(exp_dataframe)
     candidate_data = exp_dataframe.iloc[:, :-11]
     agent = RandomAgent(n_query=2)
     analyzer = StabilityAnalyzer(hull_distance=0.2)
     # Reduce seed_data
     seed_data = load_dataframe("oqmd1.2_exp_based_entries_featurized_v2")
     seed_data = filter_dataframe_by_composition(seed_data, "MnNiOSb")
     with ScratchDir('.'):
         campaign = ProtoDFTCampaign(candidate_data=candidate_data,
                                     agent=agent,
                                     experiment=experiment,
                                     analyzer=analyzer,
                                     seed_data=seed_data,
                                     heuristic_stopper=5)
         campaign.autorun()
Example #7
0
 def test_cached_campaign(self):
     with ScratchDir('.'):
         campaign = ProtoDFTCampaign.from_chemsys_high_quality("Si")
         # Test seed data has other data
         self.assertGreater(len(campaign.seed_data), 36581)