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()
Python
{
    "cores": {
        "default": 1,
        "defaultRequest": 1,
        "defaultLimit": 16,
        "defaultHeadless": 1,
        "options": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
    },
    "memoryGB": {
        "default": 2,
        "defaultRequest": 4,
        "defaultLimit": 192,
        "defaultHeadless": 4,
        "options": [1, 2, ..., 192],
    },
    "gpus": {
        "options": [1, ..., 8],
    },
}

Bases: SkahaClient

Skaha Context.

Parameters:

Name Type Description Default
SkahaClient SkahaClient

Configured Skaha Client.

required

resources

Python
resources() -> Dict[str, Any]

Get available resources from the skaha server.

Returns:

Type Description
Dict[str, Any]

A dictionary of available resources.

Examples:

Python Console Session
>>> from skaha.context import Context
>>> context = Context()
>>> context.resources()
{'cores': {
  'default': 1,
  'defaultRequest': 1,
  'defaultLimit': 16,
  'defaultHeadless': 1,
  'options': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
  },
 'memoryGB': {
  'default': 2,
  'defaultRequest': 4,
  'defaultLimit': 192,
  'defaultHeadless': 4,
  'options': [1,2,4...192]
 },
'gpus': {
 'options': [1,2, ... 28]
 }
}
Source code in skaha/context.py
Python
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()
        {'cores': {
          'default': 1,
          'defaultRequest': 1,
          'defaultLimit': 16,
          'defaultHeadless': 1,
          'options': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
          },
         'memoryGB': {
          'default': 2,
          'defaultRequest': 4,
          'defaultLimit': 192,
          'defaultHeadless': 4,
          'options': [1,2,4...192]
         },
        'gpus': {
         'options': [1,2, ... 28]
         }
        }
    """
    response: Response = self.client.get(url="context")
    response.raise_for_status()
    return response.json()