Esempio n. 1
0
    def test_find_by_study_and_objective(session: Session) -> None:

        study = TestStudyDirectionModel._create_model(session)
        direction = StudyDirectionModel.find_by_study_and_objective(study, 0, session)
        assert direction is not None
        assert direction.direction == StudyDirection.MINIMIZE

        assert StudyDirectionModel.find_by_study_and_objective(study, 1, session) is None
Esempio n. 2
0
    def _create_model(session: Session) -> StudyModel:

        study = StudyModel(study_id=1, study_name="test-study")
        dummy_study = StudyModel(study_id=2, study_name="dummy-study")
        session.add(
            StudyDirectionModel(study_id=study.study_id,
                                direction=StudyDirection.MINIMIZE,
                                objective=0))
        session.add(
            StudyDirectionModel(study_id=dummy_study.study_id,
                                direction=StudyDirection.MINIMIZE,
                                objective=0))
        session.commit()
        return study
Esempio n. 3
0
    def test_cascade_delete_on_trial(session: Session) -> None:

        trial_id = 1
        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE,
                                        objective=0)
        study = StudyModel(study_id=1,
                           study_name="test-study",
                           directions=[direction])
        trial = TrialModel(trial_id=trial_id,
                           study_id=study.study_id,
                           state=TrialState.COMPLETE)
        trial.system_attributes.append(
            TrialSystemAttributeModel(trial_id=trial_id,
                                      key="sample-key1",
                                      value_json="1"))
        trial.system_attributes.append(
            TrialSystemAttributeModel(trial_id=trial_id,
                                      key="sample-key2",
                                      value_json="2"))
        study.trials.append(trial)
        session.add(study)
        session.commit()

        assert 2 == len(
            TrialSystemAttributeModel.where_trial_id(trial_id, session))

        session.delete(trial)
        session.commit()

        assert 0 == len(
            TrialSystemAttributeModel.where_trial_id(trial_id, session))
Esempio n. 4
0
    def test_cascade_delete_on_study(session: Session) -> None:

        study_id = 1
        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE,
                                        objective=0)
        study = StudyModel(study_id=study_id,
                           study_name="test-study",
                           directions=[direction])
        study.system_attributes.append(
            StudySystemAttributeModel(study_id=study_id,
                                      key="sample-key1",
                                      value_json="1"))
        study.system_attributes.append(
            StudySystemAttributeModel(study_id=study_id,
                                      key="sample-key2",
                                      value_json="2"))
        session.add(study)
        session.commit()

        assert 2 == len(
            StudySystemAttributeModel.where_study_id(study_id, session))

        session.delete(study)
        session.commit()

        assert 0 == len(
            StudySystemAttributeModel.where_study_id(study_id, session))
Esempio n. 5
0
    def test_cascade_delete_on_study(session: Session) -> None:

        directions = [
            StudyDirectionModel(study_id=1, direction=StudyDirection.MINIMIZE, objective=0),
            StudyDirectionModel(study_id=1, direction=StudyDirection.MAXIMIZE, objective=1),
        ]
        study = StudyModel(study_id=1, study_name="test-study", directions=directions)
        session.add(study)
        session.commit()

        assert 2 == len(StudyDirectionModel.where_study_id(study.study_id, session))

        session.delete(study)
        session.commit()

        assert 0 == len(StudyDirectionModel.where_study_id(study.study_id, session))
Esempio n. 6
0
    def test_where_study(session: Session) -> None:

        study = TestStudyDirectionModel._create_model(session)
        directions = StudyDirectionModel.where_study(study, session)
        assert 1 == len(directions)
        assert directions[0].objective == 0
        assert directions[0].direction == StudyDirection.MINIMIZE
Esempio n. 7
0
    def _create_model(session: Session) -> TrialModel:

        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE, objective=0)
        study = StudyModel(study_id=1, study_name="test-study", directions=[direction])
        trial = TrialModel(trial_id=1, study_id=study.study_id, state=TrialState.COMPLETE)
        session.add(study)
        session.add(trial)
        session.add(TrialHeartbeatModel(trial_id=trial.trial_id))
        session.commit()
        return trial
Esempio n. 8
0
    def test_cascade_delete_on_study(session: Session) -> None:

        study_id = 1
        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE, objective=0)
        study = StudyModel(study_id=study_id, study_name="test-study", directions=[direction])
        study.trials.append(TrialModel(study_id=study.study_id, state=TrialState.COMPLETE))
        study.trials.append(TrialModel(study_id=study.study_id, state=TrialState.RUNNING))
        session.add(study)
        session.commit()

        assert 2 == TrialModel.count(session, study)

        session.delete(study)
        session.commit()

        assert 0 == TrialModel.count(session, study)
Esempio n. 9
0
    def _create_model(session: Session) -> TrialModel:

        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE, objective=0)
        study = StudyModel(study_id=1, study_name="test-study", directions=[direction])
        trial = TrialModel(trial_id=1, study_id=study.study_id, state=TrialState.COMPLETE)
        session.add(study)
        session.add(trial)
        session.add(
            TrialIntermediateValueModel(
                trial_id=trial.trial_id,
                step=0,
                intermediate_value=10,
                intermediate_value_type=TrialIntermediateValueModel.TrialIntermediateValueType.FINITE,  # noqa: E501
            )
        )
        session.commit()
        return trial
Esempio n. 10
0
    def test_all(session: Session) -> None:

        direction = StudyDirectionModel(direction=StudyDirection.MINIMIZE,
                                        objective=0)
        study = StudyModel(study_id=1,
                           study_name="test-study",
                           directions=[direction])
        trial = TrialModel(trial_id=1,
                           study_id=study.study_id,
                           state=TrialState.COMPLETE)

        session.add(
            TrialSystemAttributeModel(trial_id=trial.trial_id,
                                      key="sample-key",
                                      value_json="1"))
        session.commit()

        system_attributes = TrialSystemAttributeModel.all(session)
        assert 1 == len(system_attributes)
        assert "sample-key" == system_attributes[0].key
        assert "1" == system_attributes[0].value_json
Esempio n. 11
0
    def test_where_study_id(session: Session) -> None:

        study = TestStudyDirectionModel._create_model(session)
        assert 1 == len(
            StudyDirectionModel.where_study_id(study.study_id, session))
        assert 0 == len(StudyDirectionModel.where_study_id(-1, session))