def test_project_no_children(requests_mock): project = create_project(project_id="project-1") mock_get_project(requests_mock, project) with temporary_cd(): InputFactory.generate( project, "test-env", "12:34", "lilac-dask", 8000, 1, False )
def create_model(cls, include_children=False, index=1): project = create_project(f"project-{index}") if include_children: project.studies = [ create_study(project.id, "study-1"), create_study(project.id, "study-2"), ] return project
def commit_project(db: Session) -> Project: """Creates a new project and commits it the current session. Parameters ---------- db The current data base session. """ db_project = ProjectCRUD.create(db, create_project("project-1")) db.add(db_project) db.commit() return ProjectCRUD.db_to_model(db_project)
def test_project_with_children(requests_mock): project = create_project(project_id="project-1") project.studies = [create_study(project.id, "study-1")] mock_get_project(requests_mock, project) mock_get_study(requests_mock, project.studies[0]) with temporary_cd(): InputFactory.generate( project, "test-env", "12:34", "lilac-dask", 8000, 1, False ) assert os.path.isdir(project.id) assert os.path.isdir(os.path.join(project.id, "studies"))
def commit_study(db: Session) -> Tuple[Project, Study]: """Commits a new project to the current session and appends an empty study onto it. Parameters ---------- db The current data base session. """ project = create_project("project-1") project.studies = [create_study(project.id, "study-1")] db_project = ProjectCRUD.create(db, project) db.add(db_project) db.commit() project = ProjectCRUD.db_to_model(db_project) return project, project.studies[0]
def commit_optimization( db: Session, ) -> Tuple[Project, Study, Optimization, DataSetCollection, QCDataSetCollection]: """Commits a new project and study to the current session and appends an empty optimization onto it. Additionally, this function commits two data sets to the session to use as the training set. Parameters ---------- db The current data base session. """ training_set = commit_data_set_collection(db) training_set_ids = [x.id for x in training_set.data_sets] qc_data_set = commit_qc_data_set_collection(db) qc_data_set_ids = [x.id for x in qc_data_set.data_sets] study = create_study("project-1", "study-1") study.optimizations = [ create_optimization( "project-1", "study-1", "optimization-1", [ create_evaluator_target("evaluator-target-1", training_set_ids), create_recharge_target("recharge-target-1", qc_data_set_ids), ], ) ] project = create_project(study.project_id) project.studies = [study] db_project = ProjectCRUD.create(db, project) db.add(db_project) db.commit() project = ProjectCRUD.db_to_model(db_project) return project, study, study.optimizations[0], training_set, qc_data_set
def _create_model(cls, db, create_dependencies=True): project = create_project("project-1") return project, {"project_id": project.id}
def create_dependencies(db: Session, dependencies: List[str]): """Create any dependencies such as parent studies, projects, or data sets and commit them to the database. Parameters ---------- db The current database session. dependencies The required dependencies. """ project = None data_set_ids = [] qc_data_set_ids = [] if "data-set" in dependencies: data_set_ids.append("data-set-1") if "qc-data-set" in dependencies: qc_data_set_ids.append("qc-data-set-1") for data_set_id in data_set_ids: data_set = create_data_set(data_set_id) db_data_set = DataSetCRUD.create(db, data_set) db.add(db_data_set) for qc_data_set_id in qc_data_set_ids: qc_data_set = create_qc_data_set(qc_data_set_id) db_qc_data_set = QCDataSetCRUD.create(db, qc_data_set) db.add(db_qc_data_set) db.commit() if ("project" in dependencies or "study" in dependencies or "evaluator-target" in dependencies or "recharge-target" in dependencies or "benchmark" in dependencies): project = create_project("project-1") if ("study" in dependencies or "evaluator-target" in dependencies or "recharge-target" in dependencies or "benchmark" in dependencies): project.studies = [create_study(project.id, "study-1")] if "evaluator-target" in dependencies or "recharge-target" in dependencies: targets = [] if "evaluator-target" in dependencies: targets.append( create_evaluator_target("evaluator-target-1", ["data-set-1"])) if "recharge-target" in dependencies: targets.append( create_recharge_target("recharge-target-1", ["qc-data-set-1"])) optimization = create_optimization(project.id, project.studies[0].id, "optimization-1", targets) project.studies[0].optimizations = [optimization] if "benchmark" in dependencies: benchmark = create_benchmark( project.id, project.studies[0].id, "benchmark-1", ["data-set-1"], None, create_force_field(), ) project.studies[0].benchmarks = [benchmark] if project is not None: db_project = ProjectCRUD.create(db, project) db.add(db_project) db.commit()