Skip to content

Commit

Permalink
Change to async SUMO calls
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer committed Oct 5, 2023
1 parent e898767 commit 90839e1
Show file tree
Hide file tree
Showing 45 changed files with 636 additions and 541 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ RUN apt-get update -y \
&& find "${HOME_DIR}" -type d | xargs -n 1 chmod g+s \
&& add-apt-repository ppa:deadsnakes/ppa -y \
&& apt-get update -y \
&& apt-get install python3.11 -y
&& apt-get install python3.11-venv -y

CMD [ "sleep", "infinity" ]
237 changes: 224 additions & 13 deletions backend/poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pandas = {version = "2.0.1", extras = ["performance"]}
httpx = "^0.24.0"
psutil = "^5.9.5"
vtk = "^9.2.6"
fmu-sumo = "^0.3.10"
sumo-wrapper-python = "^0.3.4"
fmu-sumo = "^0.5.0"
sumo-wrapper-python = "^0.4.0"


[tool.poetry.group.dev.dependencies]
Expand Down
24 changes: 11 additions & 13 deletions backend/src/backend/primary/routers/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from pydantic import BaseModel

from src.backend.auth.auth_helper import AuthHelper
from src.services.sumo_access.case_inspector import CaseInspector
from src.services.sumo_access.iteration_inspector import IterationInspector
from src.services.sumo_access.sumo_explore import SumoExplore
from src.services.utils.authenticated_user import AuthenticatedUser
from src.services.sumo_access._helpers import SumoEnsemble

router = APIRouter()

Expand All @@ -34,27 +33,27 @@ class EnsembleDetails(BaseModel):


@router.get("/fields")
def get_fields(
async def get_fields(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
) -> List[FieldInfo]:
"""
Get list of fields
"""
sumo_discovery = SumoExplore(authenticated_user.get_sumo_access_token())
field_ident_arr = sumo_discovery.get_fields()
field_ident_arr = await sumo_discovery.get_fields()
ret_arr = [FieldInfo(field_identifier=field_ident.identifier) for field_ident in field_ident_arr]

return ret_arr


@router.get("/cases")
def get_cases(
async def get_cases(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
field_identifier: str = Query(description="Field identifier"),
) -> List[CaseInfo]:
"""Get list of cases for specified field"""
sumo_discovery = SumoExplore(authenticated_user.get_sumo_access_token())
case_info_arr = sumo_discovery.get_cases(field_identifier=field_identifier)
case_info_arr = await sumo_discovery.get_cases(field_identifier=field_identifier)

print(case_info_arr)

Expand All @@ -75,30 +74,29 @@ def get_cases(


@router.get("/cases/{case_uuid}/ensembles")
def get_ensembles(
async def get_ensembles(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Path(description="Sumo case uuid"),
) -> List[EnsembleInfo]:
"""Get list of ensembles for a case"""
sumo_discovery = SumoExplore(authenticated_user.get_sumo_access_token())
iteration_info_arr = sumo_discovery.get_iterations(case_uuid=case_uuid)
iteration_info_arr = await sumo_discovery.get_iterations(case_uuid=case_uuid)

print(iteration_info_arr)

return [EnsembleInfo(name=it.name, realization_count=it.realization_count) for it in iteration_info_arr]


@router.get("/cases/{case_uuid}/ensembles/{ensemble_name}")
def get_ensemble_details(
async def get_ensemble_details(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Path(description="Sumo case uuid"),
ensemble_name: str = Path(description="Ensemble name"),
) -> EnsembleDetails:
"""Get more detailed information for an ensemble"""
case_inspector = CaseInspector(authenticated_user.get_sumo_access_token(), case_uuid)
case_name = case_inspector.get_case_name()

iteration_inspector: IterationInspector = case_inspector.create_iteration_inspector(ensemble_name)
realizations = iteration_inspector.get_realizations()
iteration = await SumoEnsemble.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
case_name = iteration.get_case_name()
realizations = iteration.get_realizations()

return EnsembleDetails(name=ensemble_name, case_name=case_name, case_uuid=case_uuid, realizations=realizations)
12 changes: 6 additions & 6 deletions backend/src/backend/primary/routers/grid/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@


@router.get("/grid_model_names/")
def get_grid_model_names(
async def get_grid_model_names(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
) -> List[str]:
"""
Get a list of grid model names
"""
access = GridAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
return access.grid_model_names()
access = await GridAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
return await access.grid_model_names()


@router.get("/parameter_names/")
def get_parameter_names(
async def get_parameter_names(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
Expand All @@ -36,8 +36,8 @@ def get_parameter_names(
"""
Get a list of grid parameter names
"""
access = GridAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
return access.static_parameter_names(grid_name)
access = await GridAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
return await access.static_parameter_names(grid_name)


# Primary backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@router.get("/table_names_and_descriptions/", tags=["inplace_volumetrics"])
def get_table_names_and_descriptions(
async def get_table_names_and_descriptions(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -26,13 +26,15 @@ def get_table_names_and_descriptions(
) -> List[InplaceVolumetricsTableMetaData]:
"""Get all volumetric tables for a given ensemble."""

access = InplaceVolumetricsAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await InplaceVolumetricsAccess.from_case_uuid(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
table_names = access.get_table_names_and_metadata()
return table_names


@router.post("/realizations_response/", tags=["inplace_volumetrics"])
def get_realizations_response(
async def get_realizations_response(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -44,7 +46,9 @@ def get_realizations_response(
# fmt:on
) -> EnsembleScalarResponse:
"""Get response for a given table and index filter."""
access = InplaceVolumetricsAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await InplaceVolumetricsAccess.from_case_uuid(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
response = access.get_response(table_name, response_name, categorical_filter, realizations)
return response

Expand Down
30 changes: 15 additions & 15 deletions backend/src/backend/primary/routers/parameters/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@router.get("/parameter_names_and_description/")
def get_parameter_names_and_description(
async def get_parameter_names_and_description(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -26,8 +26,8 @@ def get_parameter_names_and_description(
# fmt:on
) -> List[schemas.EnsembleParameterDescription]:
"""Retrieve parameter names and description for an ensemble"""
access = ParameterAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameters = access.get_parameters_and_sensitivities().parameters
access = await ParameterAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameters = (await access.get_parameters_and_sensitivities()).parameters
if exclude_all_values_constant:
parameters = [p for p in parameters if not p.is_constant]
if sort_order == "alphabetically":
Expand All @@ -46,55 +46,55 @@ def get_parameter_names_and_description(


@router.get("/parameter/")
def get_parameter(
async def get_parameter(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
parameter_name: str = Query(description="Parameter name"),
) -> Optional[EnsembleParameter]:
"""Get a parameter in a given Sumo ensemble"""

access = ParameterAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameters = access.get_parameters_and_sensitivities().parameters
access = await ParameterAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameters = (await access.get_parameters_and_sensitivities()).parameters
for parameter in parameters:
if parameter.name == parameter_name:
return parameter
return None


@router.get("/parameters/")
def get_parameters(
async def get_parameters(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
) -> List[EnsembleParameter]:
access = ParameterAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameters = access.get_parameters_and_sensitivities().parameters
access = await ParameterAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameters = (await access.get_parameters_and_sensitivities()).parameters
return [parameter for parameter in parameters]


@router.get("/is_sensitivity_run/")
def is_sensitivity_run(
async def is_sensitivity_run(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
) -> bool:
"""Check if a given Sumo ensemble is a sensitivity run"""

access = ParameterAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameters = access.get_parameters_and_sensitivities()
access = await ParameterAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
parameters = await access.get_parameters_and_sensitivities()
return parameters.sensitivities is not None


@router.get("/sensitivities/")
def get_sensitivities(
async def get_sensitivities(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
) -> List[EnsembleSensitivity]:
"""Get sensitivities in a given Sumo ensemble"""

access = ParameterAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await ParameterAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)

sensitivities = access.get_parameters_and_sensitivities().sensitivities
sensitivities = (await access.get_parameters_and_sensitivities()).sensitivities
return sensitivities if sensitivities else []
16 changes: 9 additions & 7 deletions backend/src/backend/primary/routers/pvt/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@router.get("/table_data/")
def table_data(
async def table_data(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -26,18 +26,20 @@ def table_data(
) -> List[PvtData]:
"""Get pvt table data for a given Sumo ensemble and realization"""

access = TableAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await TableAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)

# Get all table schemas for a given realization and find the pvt table
table_schemas = access.get_table_schemas_single_realization(realization=realization)
table_schemas = await access.get_table_schemas_single_realization(realization=realization)

table_schema = None
for schema in table_schemas:
if schema.tagname == "pvt":
table_schema = schema

if table_schema is None:
raise HTTPException(status_code=404, detail="PVT table not found")

sumo_table_data = access.get_realization_table(table_schema, realization=realization)
sumo_table_data = await access.get_realization_table(table_schema, realization=realization)

pvt_data = pvt_dataframe_to_api_data(sumo_table_data.to_pandas())

Expand All @@ -46,7 +48,7 @@ def table_data(

# DOES NOT CURRENTLY WORK
@router.get("/realizations_tables_are_equal/")
def realizations_tables_are_equal(
async def realizations_tables_are_equal(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -55,10 +57,10 @@ def realizations_tables_are_equal(
) -> bool:
"""Check if all realizations has the same pvt table"""

access = TableAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
access = await TableAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)

# Get all table schemas for a given realization and find the pvt table
table_schemas = access.get_table_schemas_single_realization(realization=0)
table_schemas = await access.get_table_schemas_single_realization(realization=0)
for schema in table_schemas:
if schema.tagname == "pvt":
# Check if all realizations of this table are equal
Expand Down
6 changes: 3 additions & 3 deletions backend/src/backend/primary/routers/seismic/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@


@router.get("/seismic_directory/")
def get_seismic_directory(
async def get_seismic_directory(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
ensemble_name: str = Query(description="Ensemble name"),
) -> List[schemas.SeismicCubeMeta]:
"""
Get a directory of seismic cubes.
"""
access = SeismicAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
seismic_cube_metas = access.get_seismic_directory()
access = await SeismicAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
seismic_cube_metas = await access.get_seismic_directory()
try:
return [schemas.SeismicCubeMeta(**meta.__dict__) for meta in seismic_cube_metas]
except ValueError as exc:
Expand Down
Loading

0 comments on commit 90839e1

Please sign in to comment.