ewatercycle.container ===================== .. py:module:: ewatercycle.container .. autoapi-nested-parse:: Container utilities. Module Contents --------------- .. py:class:: ContainerImage Bases: :py:obj:`str` Custom type for parsing and utilizing container images. Given a docker url with the following structure //: The corresponding apptainer filename is assumed to be -_.sif The repository in the docker url is optional. Conversion from docker to apptainer is always possible Conversion from apptainer can lead to unexpected behaviour in some cases: * when image name contains '_' but no version tag * when image name contains '-' but no organisation eWatercycle containers typically don't have these issues. Initialize self. See help(type(self)) for accurate signature. .. py:property:: apptainer_filename :type: str Return self as apptainer filename. .. py:property:: docker_url :type: str Return self as docker url. .. py:property:: version :type: str .. py:function:: start_container(work_dir: str | pathlib.Path, image: ContainerImage, input_dirs: collections.abc.Iterable[str] | None = None, image_port=55555, timeout=None, delay=0, wrappers: collections.abc.Sequence[type[Any]] = (MemoizedBmi, OptionalDestBmi), protocol: Literal['grpc', 'openapi'] = 'grpc') -> grpc4bmi.bmi_optionaldest.OptionalDestBmi Start container with model inside. The :attr:`CFG.container_engine ` value determines the engine used to start a container. :param work_dir: Work directory :param image: Image name for container. :param input_dirs: Additional directories to mount inside container. :param image_port: Docker port inside container where grpc4bmi server is running. :param timeout: Number of seconds to wait for grpc connection. :param delay: Number of seconds to wait before connecting. :param wrappers: List of classes to wrap around the grcp4bmi object from container. Order is important. The first wrapper is the most inner wrapper. :param protocol: Which protocol to use, grpc or openapi. :raises ValueError: When unknown container technology is requested. :raises TimeoutError: When model inside container did not start quickly enough. :returns: When default wrappers are used then returns the :py:class:`Bmi object which wraps the container `, has :py:class:`memoization ` and has :py:class:`optional dest arguments ` . When no wrappers are used then returns the :py:class:`Bmi object which wraps the container `. .. rubric:: Example Given CFG.container_engine == docker a marrmot container can be started with:: from ewatercycle.container import start_container model = start_container( work_dir='.', image="ewatercycle/marrmot-grpc4bmi", ) .. py:function:: start_apptainer_container(work_dir: str | pathlib.Path, image: ContainerImage, input_dirs: collections.abc.Iterable[str] = (), timeout: int | None = None, delay: int = 0, protocol: Literal['grpc', 'openapi'] = 'grpc') -> bmipy.Bmi Start Apptainer container with model inside. :param work_dir: Work directory :param image: Name of apptainer (sif file) or docker image (url). If a docker url is passed, will try to derive the apptainer filename following the format specified in `apptainer manual`_. :param input_dirs: Additional directories to mount inside container. :param timeout: Number of seconds to wait for grpc connection. :param delay: Number of seconds to wait before connecting. :param protocol: Which protocol to use, grpc or openapi. .. _apptainer manual: https://apptainer.org/docs/user/latest/cli/apptainer_run.html :raises TimeoutError: When model inside container did not start quickly enough. :returns: Bmi object which wraps the container. .. py:function:: start_docker_container(work_dir: str | pathlib.Path, image: ContainerImage, input_dirs: collections.abc.Iterable[str] = (), image_port=55555, timeout=None, delay=0, protocol: Literal['grpc', 'openapi'] = 'grpc') Start Docker container with model inside. :param work_dir: Work directory :param image: Name of Docker image. :param input_dirs: Additional directories to mount inside container. :param image_port: Docker port inside container where grpc4bmi server is running. :param timeout: Number of seconds to wait for grpc connection. :param delay: Number of seconds to wait before connecting. :param protocol: Which protocol to use, grpc or openapi. :raises TimeoutError: When model inside container did not start quickly enough. :returns: Bmi object which wraps the container. .. py:class:: BmiFromOrigin(origin: bmipy.Bmi) Bases: :py:obj:`Protocol` Protocol for a BMI that can be used as a BMI itself. .. py:class:: BmiProxy(origin: bmipy.Bmi) Bases: :py:obj:`bmipy.Bmi` Proxy for a BMI that can be used as a BMI itself. :param origin: the BMI object to proxy .. rubric:: Example To overwrite the `get_value` method of a BMI class, you can use the following >>> class MyBmi(BmiProxy): ... def get_value(self, name: str, dest: np.ndarray) -> np.ndarray: ... dest[:] = 1 ... return dest >>> bmi = MyBmi(BmiImplementation()) >>> bmi.get_value("my_var", np.empty((2,3), dtype=np.float64)) array([[1., 1., 1.], [1., 1., 1.]]) All other methods are forwarded to the origin. .. py:attribute:: origin .. py:method:: finalize() -> None .. py:method:: get_component_name() -> str .. py:method:: get_current_time() -> float .. py:method:: get_end_time() -> float .. py:method:: get_grid_edge_count(grid: int) -> int .. py:method:: get_grid_edge_nodes(grid: int, edge_nodes: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_face_count(grid: int) -> int .. py:method:: get_grid_face_edges(grid: int, face_edges: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_face_nodes(grid: int, face_nodes: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_node_count(grid: int) -> int .. py:method:: get_grid_nodes_per_face(grid: int, nodes_per_face: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_origin(grid: int, shape: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_rank(grid: int) -> int .. py:method:: get_grid_shape(grid: int, shape: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_size(grid: int) -> int .. py:method:: get_grid_spacing(grid: int, shape: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_type(grid: int) -> str .. py:method:: get_grid_x(grid: int, x: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_y(grid: int, y: numpy.ndarray) -> numpy.ndarray .. py:method:: get_grid_z(grid: int, z: numpy.ndarray) -> numpy.ndarray .. py:method:: get_input_item_count() -> int .. py:method:: get_input_var_names() -> tuple[str, ...] .. py:method:: get_output_item_count() -> int .. py:method:: get_output_var_names() -> tuple[str, ...] .. py:method:: get_start_time() -> float .. py:method:: get_time_step() -> float .. py:method:: get_time_units() -> str .. py:method:: get_value(name: str, dest: numpy.ndarray) -> numpy.ndarray .. py:method:: get_value_at_indices(name: str, dest: numpy.ndarray, inds: numpy.ndarray) -> numpy.ndarray .. py:method:: get_value_ptr(name: str) -> numpy.ndarray .. py:method:: get_var_itemsize(name: str) -> int .. py:method:: get_var_grid(name: str) -> int .. py:method:: get_var_location(name: str) -> str .. py:method:: get_var_nbytes(name: str) -> int .. py:method:: get_var_type(name: str) -> str .. py:method:: get_var_units(name: str) -> str .. py:method:: initialize(filename: str) -> None .. py:method:: set_value(name: str, src: numpy.ndarray) -> None .. py:method:: set_value_at_indices(name: str, inds: numpy.ndarray, src: numpy.ndarray) -> None .. py:method:: update() -> None .. py:method:: update_until(time: float) -> None