Skip to content

Context API

Context API allows the user to get information about the resources available to be requested for a session on the CANFAR Science Platform. This information can be used to configure the session to request the appropriate resources for your

Getting Reosources Information

Get context information
from skaha.context import Context

context = Context()
context.resources()
{
    "defaultCores": 2,
    "defaultCoresHeadless": 1,
    "availableCores": [1, 2, 4, 8, 16],
    "defaultRAM": 16,
    "defaultRAMHeadless": 4,
    "availableRAM": [1, 2, 4, 8, 16, 32, 64, 128, 192],
    "availableGPUs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...],
}

Bases: SkahaClient

Get available resources from the skaha server.

Source code in skaha/context.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Context(SkahaClient):
    """Get available resources from the skaha server."""

    @model_validator(mode="after")
    def _set_server(self) -> Self:
        """Sets the server path after validation."""
        self.server = f"{self.server}/{self.version}/context"  # type: ignore
        return self

    def resources(self) -> Dict[str, Any]:
        """Get available resources from the skaha server.

        Returns:
            A dictionary of available resources.

        Examples:
            >>> from skaha.context import Context
            >>> context = Context()
            >>> context.resources()
            {'defaultCores': 2,
             'defaultCoresHeadless': 1,
             'availableCores': [1, 2, 4, 8, 16],
             'defaultRAM': 16,
             'defaultRAMHeadless': 4,
             'availableRAM': [1, 2, 4, 8, 16, 32, 64, 128, 192],
             'availableGPUs': [1,2,3,...],
            }
        """
        response: Response = self.session.get(url=self.server)  # type: ignore
        response.raise_for_status()
        return response.json()

resources()

Get available resources from the skaha server.

Returns:

Type Description
Dict[str, Any]

A dictionary of available resources.

Examples:

>>> from skaha.context import Context
>>> context = Context()
>>> context.resources()
{'defaultCores': 2,
 'defaultCoresHeadless': 1,
 'availableCores': [1, 2, 4, 8, 16],
 'defaultRAM': 16,
 'defaultRAMHeadless': 4,
 'availableRAM': [1, 2, 4, 8, 16, 32, 64, 128, 192],
 'availableGPUs': [1,2,3,...],
}
Source code in skaha/context.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def resources(self) -> Dict[str, Any]:
    """Get available resources from the skaha server.

    Returns:
        A dictionary of available resources.

    Examples:
        >>> from skaha.context import Context
        >>> context = Context()
        >>> context.resources()
        {'defaultCores': 2,
         'defaultCoresHeadless': 1,
         'availableCores': [1, 2, 4, 8, 16],
         'defaultRAM': 16,
         'defaultRAMHeadless': 4,
         'availableRAM': [1, 2, 4, 8, 16, 32, 64, 128, 192],
         'availableGPUs': [1,2,3,...],
        }
    """
    response: Response = self.session.get(url=self.server)  # type: ignore
    response.raise_for_status()
    return response.json()