@@ -276,27 +276,110 @@ You need to explicitly convert the data, which you can do as follows:
276276 entry.put(imas.convert_ids(equilibrium, entry.dd_version))
277277
278278
279+ .. _`UDA backend and DD versions` :
279280
280- .. _`DD background` :
281+ UDA backend caching and Data Dictionary versions
282+ ------------------------------------------------
281283
282- Background information
283- ----------------------
284+ If you try to load data from a different Data Dictionary version with the UDA backend,
285+ you may see the following error:
286+
287+ .. code-block :: text
288+
289+ The Data Dictionary version of the data (3.38.1) is different from the Data
290+ Dictionary version of the DBEntry (3.42.0). This is not supported when using the
291+ UDA backend.
292+
293+ There are three possible workarounds. The first two require passing an additional option
294+ in the IMAS UDA URI: please see the `imas-core documentation
295+ <https://imas-core.readthedocs.io/en/stable/user_guide/backends_guide.html#query-keys-specific-for-the-uda-backend> `__
296+ for more details on these URI options.
297+
298+ 1. Use UDA fetch to bypass the cache problem. You can do this by appending ``&fetch=1 ``
299+ to the URI when you create the :py:class: `~imas.db_entry.DBEntry `.
300+
301+ Note that this will download the entire IDS files from the remote server, this may
302+ not be desired if you only want to read a single time slice.
303+ 2. Disable the UDA cache. You can do this by appending ``&cache_mode=none `` to the URI
304+ when you create the :py:class: `~imas.db_entry.DBEntry `.
305+
306+ Note that this may make the ``get() `` (a lot) slower, since a separate request needs
307+ to be sent to the remote UDA server for every data variable. However, this may still
308+ be the best performing option if you are only interested in a subset of all the data
309+ in an IDS (and use :ref: `lazy loading `).
310+ 3. Explicitly provide the data dictionary version when you create the
311+ :py:class: `~imas.db_entry.DBEntry `, setting it to match the Data Dictionary version
312+ of the data you want to load. To obtain the version of the data on the remote server
313+ from the field `ids_properties.put_version.data_dictionary ` via a _lazy_ ``get() ``
314+ with ``autoconvert=False `` option and using the ``&cache_mode=none `` query in the URI.
315+
316+ Note that you may need to call ``imas.convert_ids `` to convert the IDS to your
317+ desired Data Dictionary version.
318+
319+ All three possible workarounds are shown in the examples below:
320+
321+ .. md-tab-set ::
322+
323+ .. md-tab-item :: Original code
324+
325+ .. code-block :: python
326+
327+ import imas
328+
329+ URI = (
330+ " imas://uda.iter.org:56565/uda?backend=hdf5"
331+ " &path=/work/imas/shared/imasdb/ITER/3/121013/50"
332+ )
333+ with imas.DBEntry(URI , " r" ) as entry:
334+ cp = entry.get(" core_profiles" )
284335
285- Since IMAS-Python needs to have access to multiple DD versions it was chosen to
286- bundle these with the code at build-time, in setup.py. If a git clone of the
287- Data Dictionary succeeds, the setup tools automatically download saxon and
288- generate ``IDSDef.xml `` for each of the tagged versions in the DD git
289- repository. These are then gathered into ``IDSDef.zip ``, which is
290- distributed inside the IMAS-Python package.
336+ .. md-tab-item :: 1. Use UDA fetch
291337
292- To update the set of data dictionaries new versions can be added to the zipfile.
293- A reinstall of the package will ensure that all available versions are included
294- in IMAS-Python. Additionally an explicit path to an XML file can be specified, which
295- is useful for development.
338+ .. code-block :: python
296339
297- Automated tests have been provided that check the loading of all of the DD
298- versions tagged in the data-dictionary git repository.
340+ import imas
299341
342+ URI = (
343+ " imas://uda.iter.org:56565/uda?backend=hdf5"
344+ " &path=/work/imas/shared/imasdb/ITER/3/121013/50&fetch=1"
345+ )
346+ with imas.DBEntry(URI , " r" ) as entry:
347+ cp = entry.get(" core_profiles" )
348+
349+ .. md-tab-item :: 2. Disable the UDA cache
350+
351+ .. code-block :: python
352+
353+ import imas
354+
355+ URI = (
356+ " imas://uda.iter.org:56565/uda?backend=hdf5"
357+ " &path=/work/imas/shared/imasdb/ITER/3/121013/50&cache_mode=none"
358+ )
359+ with imas.DBEntry(URI , " r" ) as entry:
360+ cp = entry.get(" core_profiles" )
361+
362+ .. md-tab-item :: 3. Explicitly provide the DD version
363+
364+ .. code-block :: python
365+
366+ import imas
367+
368+ URI = (
369+ " imas://uda.iter.org:56565/uda?backend=hdf5"
370+ " &path=/work/imas/shared/imasdb/ITER/3/121013/50"
371+ )
372+ with imas.DBEntry(URI , " r" , dd_version = " 3.38.1" ) as entry:
373+ cp = entry.get(" core_profiles" )
374+
375+ # Optional: convert the IDS to your desired DD version
376+ cp = imas.convert_ids(cp, " 3.42.0" )
377+
378+
379+ .. _`DD background` :
380+
381+ Background information
382+ ----------------------
300383
301384Data Dictionary definitions
302385'''''''''''''''''''''''''''
0 commit comments