Skip to content

Fix/incorrect handling of error/warning when idslist is applied to a uda uri#38

Open
prasad-sawantdesai wants to merge 3 commits into
iterorganization:developfrom
prasad-sawantdesai:fix/Incorrect-handling-of-error/warning-when-idslist-is-applied-to-a-UDA-URI
Open

Fix/incorrect handling of error/warning when idslist is applied to a uda uri#38
prasad-sawantdesai wants to merge 3 commits into
iterorganization:developfrom
prasad-sawantdesai:fix/Incorrect-handling-of-error/warning-when-idslist-is-applied-to-a-UDA-URI

Conversation

@prasad-sawantdesai

Copy link
Copy Markdown
Contributor

Automatically adds cache_mode=none to UDA URIs.

$ idslist --uri "imas://uda.iter.org:56565/uda?path=/work/imas/shared/imasdb/ITER/3/134173/106;backend=hdf5"
13:07:55 INFO     Parsing data dictionary version 4.1.1 @dd_zip.py:89
13:07:56 INFO     Parsing data dictionary version 3.38.1 @dd_zip.py:89
                                      List of IDSes
┏━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ IDS            ┃ SLICES ┃ TIME                                                         ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ core_profiles  │ 871    │ array([  3.99,   3.99,   3.99, ..., 792.  , 792.  , 792.  ]) │
│ core_sources   │ 871    │ array([  3.99,   3.99,   3.99, ..., 792.  , 792.  , 792.  ]) │
│ core_transport │ 871    │ array([  3.99,   3.99,   3.99, ..., 792.  , 792.  , 792.  ]) │
│ equilibrium    │ 871    │ array([  1.2 ,   1.4 ,   1.6 , ..., 797.92, 798.42, 798.92]) │
│ summary        │ 871    │ array([  3.99,   3.99,   3.99, ..., 792.  , 792.  , 792.  ]) │
└────────────────┴────────┴──────────────────────────────────────────────────────────────┘

Comment thread idstools/database.py
logger = logging.getLogger(f"module.{__name__}")


def add_default_uda_cache_mode(uri):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised to find this function in database module and not in the utils


if len(args.uri) >= 1:
connection1 = imas.DBEntry(args.uri[0], "r")
connection1 = imas.DBEntry(add_default_uda_cache_mode(args.uri[0]), "r")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of this script, we don't lazy read the equilibrium, either it will be beneficial and we should do it (then it's fine to use cache_mode=none), or we need everything and cache_mode=none is going to kill perfs...

Comment thread idstools/database.py
if not isinstance(uri, str):
return uri

uri_part, fragment_separator, fragment = uri.partition("#")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that we don't use or have a nicer API to interact with URIs in Python

Comment thread idstools/database.py

def add_default_uda_cache_mode(uri):
"""Add ``cache_mode=none`` to UDA URIs unless it is already specified."""
if not isinstance(uri, str):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A URI is always a string no?

Comment thread idstools/database.py
if any(parameter.partition("=")[0] == "cache_mode" for parameter in parameters):
return uri

parameter_separator = ";" if query_separator else "?"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else case can't be true here (the uri would miss the query)

Comment thread idstools/database.py
logger = logging.getLogger(f"module.{__name__}")


def add_default_uda_cache_mode(uri):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are overcomplicating stuff here, we just want to append cache_mode=none in case the URI is a UDA one (it does not harm if the same query is already present, so you don't need the if line 28)

Ideally, you could make a more general function that would append a given query pair to a URI of a given backend type:
add_query_to_uri(backend="uda", query="cache_mode=none")
--> this would then allow to append a different option for a different use case, e.g. equicomp which needs the entire IDS could use "fetch=1"

Or if we had a better API to interact with the URI (and extract the backend), then you won't even need to pass the backend and could do:
add_query_to_uri("cache_mode=none") if from_uri(uri, "backend")==uda else uri

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect handling of error/warning when idslist is applied to a UDA URI

2 participants