{ "cells": [ { "cell_type": "markdown", "id": "ef4d8194-b159-44ce-a523-be02cb1b0571", "metadata": { "tags": [] }, "source": [ "# Setting up FusionSC\n", "\n", "## Setting up component lookup (version 2.2 and above)\n", "\n", "While FusionSC can be used out of the box (`import fusionsc as fsc`), it doesn't bundle the part and coil geometries (partly due to size, partly to comply with data access policies). In order to run FusionSC with pre-defined geometries, the resolution subsystem needs to be hooked up with lookup tables / storage for these devices.\n", "\n", "The recommended way (available from version 2.2 onwards) is to use the user configuration file in \"~/.fusionsc.yaml\" (an alternative path can be specified by setting the FUSIONSC_CONFIG_PATH environment variable). The \"fusionsc-config\" command line (alternatively usable via \"python -m fusionsc.config\") can be used to manage this configuration file.\n", "\n", "### Wendelstein 7-X inside IPP network\n", "\n", "Use the \"ipp-hgw\" default profile, which will connect to a compute server and rely on the resolution database stored there.\n", "\n", "```\n", "fusionsc-config default ipp-hgw\n", "```\n", "\n", "### J-TEXT\n", "\n", "Simplified J-TEXT geometries are bundled with FusionSC. No further configuration is required to use them.\n", "\n", "### Others\n", "\n", "You will have to manually add the neccessary resolution files. Usually this entails adding them with the config tool\n", "\n", "```\n", "fusionsc-config resolve add {file or url}\n", "```\n", "\n", "## Setting up component lookup with python methods (version 2.0 and above)\n", "\n", "For version 2.1 and below, and if you don't want to rely on the user configuration, you can always use the methods `fusionsc.resolve.importOfflineData` and `fusionsc.resolve.connectWarehouse`. Keep in mind that the changes by these methods are local to the current context.\n", "\n", "### Wendelstein 7-X inside IPP network\n", "\n", "On version 2.1 and above, you can use the `fusionsc.devices.w7x.connectIppSite` method to configure the computing server and resolution database, similar to the \"ipp-hgw\" configuration default profile." ] }, { "cell_type": "code", "execution_count": 1, "id": "a26cef2f-11dd-4500-bf56-760dd5bec63a", "metadata": {}, "outputs": [], "source": [ "from fusionsc.devices import w7x\n", "w7x.connectIppSite()" ] }, { "cell_type": "markdown", "id": "d3a67adf-e557-42ed-9ddc-5e01397d3292", "metadata": {}, "source": [ "## (W7-X only) Pre-calculating fields for Biot-Savart calculation\n", "\n", "A generally expensive calculation is the Biot-Savart rule to obtain the magnetic field from the coil geometries. For W7-X\n", ", there is a high-level support to precompute the coil fields. These fields can then be saved and loaded later for\n", "usage. When using precomputed coil fields, the offline data files are not required (unless required for other reasons, such\n", "as geometry data or other field information). W7-X has special support to pre-compute all coils so that they can be re-used\n", "later.\n", "\n", "The precomputation is performed through the `devices.w7x.CoilPack` class, which can be used as a handle to override the coils\n", "used in the generation of W7-X configurations." ] }, { "cell_type": "code", "execution_count": 1, "id": "47c0a1ad-12b7-4c26-85fa-db0d7d3cb793", "metadata": {}, "outputs": [], "source": [ "from fusionsc.devices import w7x\n", "\n", "# Obtain default coils\n", "coils = w7x.cadCoils()\n", "\n", "# Compute\n", "coils = coils.computeFields(w7x.defaultGrid())\n", "\n", "# Use in configuration\n", "config1 = w7x.standard(coils = coils)\n", "config2 = w7x.highIota(coils = coils)" ] }, { "cell_type": "markdown", "id": "f2cd2a39-9771-4a45-95ee-e6e74b6be93d", "metadata": {}, "source": [ "The precalculated fields can be saved and loaded like other field or geometry classes." ] }, { "cell_type": "code", "execution_count": null, "id": "b12d163b-a012-4020-8dad-185f6db8b2c7", "metadata": {}, "outputs": [], "source": [ "# Save\n", "coils.save(\"coils.fsc\")\n", "\n", "# Restore\n", "coils = w7x.CoilPack.load(\"coils.fsc\")" ] }, { "cell_type": "markdown", "id": "564fb827-1426-47e4-87ff-c1a582feada2", "metadata": {}, "source": [ "## (Re-)Configuring the local backend\n", "\n", "While fusionsc is capable of connecting to remote servers for execution and data management, by default it uses a local backend started at import time. The backend is started with a default configuration (all services enabled, CPU execution, auto-detected no. of computation threads). Sometimes it is desirable to override this default behavior. You can use the `backends.reconfigureLocalBackend` function for this purpose.\n", "\n", "*Note*: This function creates a **new** backend to be used by all future calls. The old backend will be closed once all references to it coming from previous pending calls are dropped. If the local backend has been exposed (e.g. as a network service or by storing the result of backends.activeBackend) it will not shut down until these external references are dropped as well." ] }, { "cell_type": "code", "execution_count": 2, "id": "3ff03968-d9b2-4df9-b461-1f29033cd8fe", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " --- Default configuration --- \n", "\n", "preferredDeviceType: cpu\n", "enableCompute: true\n", "enableStorage: true\n", "jobScheduler: system\n", "flt:\n", " eventBuffer:\n", " minSize: 100\n", " maxSize: 2500\n", " targetTotalMb: 500\n", "cpuBackend:\n", " numThreads: autoDetect\n", "\n", " --- Adjusted configuration --- \n", "\n", "preferredDeviceType: cpu\n", "enableCompute: true\n", "enableStorage: true\n", "jobScheduler: system\n", "flt:\n", " eventBuffer:\n", " minSize: 100\n", " maxSize: 2500\n", " targetTotalMb: 500\n", "cpuBackend:\n", " numThreads:\n", " fixed: 2\n", "\n" ] } ], "source": [ "# Get default configuration\n", "config = fsc.service.LocalConfig.newMessage()\n", "print(' --- Default configuration --- ')\n", "print()\n", "print(config)\n", "print()\n", "\n", "# Adjust configuration\n", "config.cpuBackend.numThreads.fixed = 2\n", "\n", "print(' --- Adjusted configuration --- ')\n", "print()\n", "print(config)\n", "print()\n", "\n", "# Apply adjusted configuration\n", "fsc.backends.reconfigureLocalBackend(config)" ] }, { "cell_type": "markdown", "id": "fd5e54c2-7655-4942-b35e-872b5de26d94", "metadata": {}, "source": [ "## Using verbose logging\n", "\n", "Sometimes it is desirable to enable the internal log output to see progress on the calculation. This can be achieved by setting the `FUSIONSC_VERBOSE` environment variable to any other value than `0`. This has to be done **before** importing the package." ] }, { "cell_type": "code", "execution_count": 1, "id": "eff8e98a-91c6-4df8-b957-1bc159491222", "metadata": {}, "outputs": [], "source": [ "import os\n", "os.environ['FUSIONSC_VERBOSE'] = '1'\n", "\n", "import fusionsc as fsc" ] }, { "cell_type": "markdown", "id": "bc3e54cd-ad08-4c69-b1ce-187d9b8bf9cb", "metadata": {}, "source": [ "When using the standalone server, verbose logging can be activated through the `--verbose` command-line switch." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 5 }