def test_optimization_result_try_get_final_models_for_successful_optimization( ) -> None: models = {"foo": _PseudoTrainableQuadratic()} result: OptimizationResult[None] = OptimizationResult( Ok(Record({"foo": empty_dataset([1], [1])}, models, None)), []) assert result.try_get_final_models() is models assert result.try_get_final_model() is models["foo"]
def test_optimization_result_try_get_final_models_for_multiple_models() -> None: data = {"foo": empty_dataset([1], [1]), "bar": empty_dataset([2], [2])} models = {"foo": _PseudoTrainableQuadratic(), "bar": _PseudoTrainableQuadratic()} result: OptimizationResult[None] = OptimizationResult(Ok(Record(data, models, None)), []) assert result.try_get_final_models() is models with pytest.raises(ValueError): result.try_get_final_model()
def test_optimization_result_try_get_final_datasets_for_successful_optimization( ) -> None: data = {"foo": empty_dataset([1], [1])} result: OptimizationResult[None] = OptimizationResult( Ok(Record(data, {"foo": _PseudoTrainableQuadratic()}, None)), []) assert result.try_get_final_datasets() is data assert result.try_get_final_dataset() is data["foo"]
def test_optimization_result_astuple() -> None: opt_result: OptimizationResult[None] = OptimizationResult( Err(_Whoops()), [Record({}, {}, None)] ) final_result, history = opt_result.astuple() assert final_result is opt_result.final_result assert history is opt_result.history
def test_optimization_result_try_get_final_datasets_for_failed_optimization( ) -> None: result: OptimizationResult[object] = OptimizationResult(Err(_Whoops()), []) with pytest.raises(_Whoops): result.try_get_final_datasets()