Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send data-related warnings from backend in HTTP header and view frontend in respective modules #836

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/main' into migrate-to-openapi-ts
  • Loading branch information
rubenthoms committed Jan 9, 2025
commit 3b37580e6c540a16e8c8a27714cd20d4dd9166b9
4 changes: 2 additions & 2 deletions .github/workflows/webviz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ jobs:
working-directory: ./backend_py/primary
run: |
pip install --upgrade pip
pip install poetry
pip install poetry==1.8.5 # Pin Poetry to version 1.8.5
poetry config virtualenvs.create false
poetry lock --check --no-update # Check lock file is consistent with pyproject.toml
poetry check --lock # Check lock file is consistent with pyproject.toml
poetry install --with dev

- name: 🕵️ Check code style & linting
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ in the following folders are changed:
./backend/src
```

If other files are changed through the host operativey system,
If other files are changed through the host operating system,
e.g. typically when a new dependency is added, the relevant component needs to be rebuilt. I.e.
`docker-compose up --build frontend` or `docker-compose up --build backend`.

Expand All @@ -51,9 +51,9 @@ as stated above).
### Radix applications

We have two applications in Radix built from this repository:
* [Main application](https://webviz.app.radix.equinor.com/) built from the `main` branch.
* [Review application](https://frontend-webviz-review.radix.equinor.com/) built from the `review` branch.
* [Dev application](https://frontend-webviz-dev.radix.equinor.com/) built from the `dev` branch.
* [Main application](https://webviz.app.c2.radix.equinor.com/) built from the `main` branch.
* [Review application](https://frontend-webviz-review.c2.radix.equinor.com/) built from the `review` branch.
* [Dev application](https://frontend-webviz-dev.c2.radix.equinor.com/) built from the `dev` branch.

The applications are automatically built and redeployed when pushing commits to the respective branch.

Expand Down
10 changes: 5 additions & 5 deletions backend_py/primary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ docker stop $CONTAINER_ID

# Cache data in memory

Sometimes large data sets must to be loaded from external sources. If the user interacts
Sometimes large data sets must be loaded from external sources. If the user interacts
with this data through a series of requests to the backend, it is inefficient to load
the same data every time. Instead the recommended pattern is to load these large data sets
using a separate job container instance bound to the user where it can then easily be cached.

Technically this is done like this:
1) The frontend makes a requests to the (primary) backend as usual.
1) The frontend makes a request to the (primary) backend as usual.
2) The "data demanding endpoints" in the primary backend proxies the request to a separate
job container runnings its own server (also using `FastAPI` as framework).
job container running its own server (also using `FastAPI` as framework).
3) If the user does not already have a job container bound to her/his user ID, the
cloud infrastructure will spin it up (takes some seconds). The job container will
have single-user scope and automatically stop when it has not seen any new requests
Expand All @@ -41,11 +41,11 @@ Technically this is done like this:

Locally during development (single user scenario) there is a single job container
continuously running, started automatically by `docker-compose`.
Except from starting at the same time as the primary backend, not stopping after user
Except for starting at the same time as the primary backend, not stopping after user
inactivity, and being limited by the developer machine resources (CPU / memory),
this job container during development behave similar to the on demand started job containers in cloud.

On route level this is implemented like the following:
At the route level this is implemented like the following:

**In `src/backend/primary`:**
```python
Expand Down
6 changes: 2 additions & 4 deletions backend_py/primary/primary/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
from primary.auth.auth_helper import AuthHelper
from primary.auth.enforce_logged_in_middleware import EnforceLoggedInMiddleware
from primary.middleware.add_process_time_to_server_timing_middleware import AddProcessTimeToServerTimingMiddleware
from primary.routers.correlations.router import router as correlations_router
from primary.routers.dev.router import router as dev_router
from primary.routers.explore import router as explore_router
from primary.routers.general import router as general_router
from primary.routers.graph.router import router as graph_router
from primary.routers.grid3d.router import router as grid3d_router
from primary.routers.group_tree.router import router as group_tree_router
from primary.routers.flow_network.router import router as flow_network_router
from primary.routers.inplace_volumetrics.router import router as inplace_volumetrics_router
from primary.routers.observations.router import router as observations_router
from primary.routers.parameters.router import router as parameters_router
Expand Down Expand Up @@ -77,9 +76,8 @@ def custom_generate_unique_id(route: APIRoute) -> str:
app.include_router(inplace_volumetrics_router, prefix="/inplace_volumetrics", tags=["inplace_volumetrics"])
app.include_router(surface_router, prefix="/surface", tags=["surface"])
app.include_router(parameters_router, prefix="/parameters", tags=["parameters"])
app.include_router(correlations_router, prefix="/correlations", tags=["correlations"])
app.include_router(grid3d_router, prefix="/grid3d", tags=["grid3d"])
app.include_router(group_tree_router, prefix="/group_tree", tags=["group_tree"])
app.include_router(flow_network_router, prefix="/flow_network", tags=["flow_network"])
app.include_router(pvt_router, prefix="/pvt", tags=["pvt"])
app.include_router(well_completions_router, prefix="/well_completions", tags=["well_completions"])
app.include_router(well_router, prefix="/well", tags=["well"])
Expand Down
65 changes: 0 additions & 65 deletions backend_py/primary/primary/routers/correlations/router.py

This file was deleted.

3 changes: 3 additions & 0 deletions backend_py/primary/primary/routers/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EnsembleInfo(BaseModel):
class EnsembleDetails(BaseModel):
name: str
field_identifier: str
stratigraphic_column_identifier: str
case_name: str
case_uuid: str
realizations: Sequence[int]
Expand Down Expand Up @@ -91,6 +92,7 @@ async def get_ensemble_details(
case_name = await case_inspector.get_case_name_async()
realizations = await case_inspector.get_realizations_in_iteration_async(ensemble_name)
field_identifiers = await case_inspector.get_field_identifiers_async()
stratigraphic_column_identifier = await case_inspector.get_stratigraphic_column_identifier_async()

if len(field_identifiers) != 1:
raise NotImplementedError("Multiple field identifiers not supported")
Expand All @@ -101,4 +103,5 @@ async def get_ensemble_details(
case_uuid=case_uuid,
realizations=realizations,
field_identifier=field_identifiers[0],
stratigraphic_column_identifier=stratigraphic_column_identifier,
)
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import logging
from fastapi import APIRouter, Depends, Query
from webviz_pkg.core_utils.perf_timer import PerfTimer
from primary.auth.auth_helper import AuthHelper
from primary.services.group_tree_assembler.group_tree_assembler import GroupTreeAssembler

from primary.services.flow_network_assembler.flow_network_assembler import FlowNetworkAssembler
from primary.services.flow_network_assembler.flow_network_types import NetworkModeOptions, NodeType
from primary.services.sumo_access.group_tree_access import GroupTreeAccess
from primary.services.sumo_access.group_tree_types import TreeModeOptions, NodeType
from primary.services.sumo_access.summary_access import Frequency, SummaryAccess
from primary.services.utils.authenticated_user import AuthenticatedUser

from . import schemas

from webviz_pkg.core_utils.perf_timer import PerfTimer
import logging

LOGGER = logging.getLogger(__name__)

router = APIRouter()


@router.get("/realization_group_tree_data/")
async def get_realization_group_tree_data(
@router.get("/realization_flow_network/")
async def get_realization_flow_network(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -26,7 +26,7 @@ async def get_realization_group_tree_data(
resampling_frequency: schemas.Frequency = Query(description="Resampling frequency"),
node_type_set: set[schemas.NodeType] = Query(description="Node types"),
# fmt:on
) -> schemas.GroupTreeData:
) -> schemas.FlowNetworkData:
timer = PerfTimer()

group_tree_access = await GroupTreeAccess.from_case_uuid_async(
Expand All @@ -38,33 +38,33 @@ async def get_realization_group_tree_data(
summary_frequency = Frequency.YEARLY

# Convert to NodeType enum in group_tree_types
unique_node_types = set([NodeType(elm.value) for elm in node_type_set])
unique_node_types = {NodeType(elm.value) for elm in node_type_set}

group_tree_data = GroupTreeAssembler(
network_assembler = FlowNetworkAssembler(
group_tree_access=group_tree_access,
summary_access=summary_access,
realization=realization,
summary_frequency=summary_frequency,
node_types=unique_node_types,
group_tree_mode=TreeModeOptions.SINGLE_REAL,
flow_network_mode=NetworkModeOptions.SINGLE_REAL,
)

timer.lap_ms()
await group_tree_data.fetch_and_initialize_async()
await network_assembler.fetch_and_initialize_async()
initialize_time_ms = timer.lap_ms()

(
dated_trees,
dated_networks,
edge_metadata,
node_metadata,
) = await group_tree_data.create_dated_trees_and_metadata_lists()
) = await network_assembler.create_dated_networks_and_metadata_lists()
create_data_time_ms = timer.lap_ms()

LOGGER.info(
f"Group tree data for single realization fetched and processed in: {timer.elapsed_ms()}ms "
f"(initialize={initialize_time_ms}ms, create group tree={create_data_time_ms}ms)"
)

return schemas.GroupTreeData(
edge_metadata_list=edge_metadata, node_metadata_list=node_metadata, dated_trees=dated_trees
return schemas.FlowNetworkData(
edgeMetadataList=edge_metadata, nodeMetadataList=node_metadata, datedNetworks=dated_networks
)
36 changes: 36 additions & 0 deletions backend_py/primary/primary/routers/flow_network/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from enum import Enum, StrEnum

from pydantic import BaseModel, ConfigDict
from primary.services.flow_network_assembler.flow_network_types import DatedFlowNetwork, FlowNetworkMetadata


class Frequency(str, Enum):
DAILY = "DAILY"
WEEKLY = "WEEKLY"
MONTHLY = "MONTHLY"
QUARTERLY = "QUARTERLY"
YEARLY = "YEARLY"


class StatOption(str, Enum):
MEAN = "MEAN"
P10 = "P10"
P90 = "P90"
P50 = "P50"
MIN = "MIN"
MAX = "MAX"


# ! Copy of the flow network service NodeType enum
class NodeType(StrEnum):
PROD = "prod"
INJ = "inj"
OTHER = "other"


class FlowNetworkData(BaseModel):
model_config = ConfigDict(revalidate_instances="always")

edgeMetadataList: list[FlowNetworkMetadata]
nodeMetadataList: list[FlowNetworkMetadata]
datedNetworks: list[DatedFlowNetwork]
34 changes: 0 additions & 34 deletions backend_py/primary/primary/routers/group_tree/schemas.py

This file was deleted.

25 changes: 19 additions & 6 deletions backend_py/primary/primary/routers/inplace_volumetrics/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from primary.services.utils.authenticated_user import AuthenticatedUser
from primary.auth.auth_helper import AuthHelper
from primary.utils.response_perf_metrics import ResponsePerfMetrics
from primary.utils.query_string_utils import decode_uint_list_str

from . import schemas
from . import converters
Expand Down Expand Up @@ -52,10 +53,10 @@ async def post_get_aggregated_per_realization_table_data(
group_by_identifiers: Annotated[
list[schemas.InplaceVolumetricsIdentifier] | None, Query(description="The identifiers to group table data by")
] = None,
realizations: Annotated[
list[int] | None,
realizations_encoded_as_uint_list_str: Annotated[
str | None,
Query(
description="Optional list of realizations to include. If not specified, all realizations will be returned."
description="Optional list of realizations encoded as string to include. If not specified, all realizations will be included."
),
] = None,
) -> schemas.InplaceVolumetricTableDataPerFluidSelection:
Expand All @@ -67,6 +68,12 @@ async def post_get_aggregated_per_realization_table_data(
"""
perf_metrics = ResponsePerfMetrics(response)

realizations = None
if realizations_encoded_as_uint_list_str:
realizations = decode_uint_list_str(realizations_encoded_as_uint_list_str)

perf_metrics.record_lap("decode realizations array")

access = await InplaceVolumetricsAccess.from_case_uuid_async(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
Expand Down Expand Up @@ -110,10 +117,10 @@ async def post_get_aggregated_statistical_table_data(
group_by_identifiers: Annotated[
list[schemas.InplaceVolumetricsIdentifier] | None, Query(description="The identifiers to group table data by")
] = None,
realizations: Annotated[
list[int] | None,
realizations_encoded_as_uint_list_str: Annotated[
str | None,
Query(
description="Optional list of realizations to include. If not specified, all realizations will be returned."
description="Optional list of realizations encoded as string to include. If not specified, all realizations will be included."
),
] = None,
) -> schemas.InplaceStatisticalVolumetricTableDataPerFluidSelection:
Expand All @@ -125,6 +132,12 @@ async def post_get_aggregated_statistical_table_data(
"""
perf_metrics = ResponsePerfMetrics(response)

realizations: list[int] | None = None
if realizations_encoded_as_uint_list_str:
realizations = decode_uint_list_str(realizations_encoded_as_uint_list_str)

perf_metrics.record_lap("decode realizations array")

access = await InplaceVolumetricsAccess.from_case_uuid_async(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
Expand Down
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.