{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Parameter library\n", "\n", "In this example, we show how to use the `Library` to access parameter values to use in pipelines, either as known values or initial guesses for optimization. The library is currently small, and only contains thermodynamic parameters for the MSMR model for a handful of materials. The library will be expanded in the future, and users can add new materials for use in their own pipelines." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ionworkspipeline as iwp" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "First we create a `Library` object. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib = iwp.Library()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can get a list of the materials in the library using the `materials` attribute." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib.materials" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can search for a material in the library using the `search_materials` method," ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib.search_materials(\"si\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "and access the parameters for a material using by indexing the library with the material name." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "si = lib[\"Silicon (lithiation) - Verbrugge 2017\"]" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "`si` is a `Material` object with attributes for the name, description and parameter values." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Parameters are stored in a dictionary and can be accessed using the `parameter_values` attribute." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "si.parameter_values" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can also access the name" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "si.name" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "and description." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "si.description" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can search the materials for a specific parameter using the `search_parameters` method." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "si.search_parameters(\"U\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can also search for parameters across the entire library." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib.search_parameters(\"U\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "New `Material` objects can be created by passing in a dictionary with keys \"name\", \"description\" and \"parameter_values\" to the `Material` class. The parameters can contain functions and scalar values." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def myfun(x):\n", " return x**2\n", "\n", "\n", "my_material_dict = {\n", " \"name\": \"My Material\",\n", " \"description\": \"This is a material I made\",\n", " \"parameter values\": {\"U\": 1.0, \"D\": 2.0, \"fun\": myfun},\n", "}\n", "\n", "my_material = iwp.Material(my_material_dict)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can check that the stored parameters are those we passed in," ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "my_material.parameter_values" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "and we can search as before." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "my_material.search_parameters(\"U\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "New materials can be added to the library using entry points, as described in the [documentation](../../api/library/index.rst)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "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" }, "vscode": { "interpreter": { "hash": "6b12f1f625627d6c4a17ef696ddbbbd9bd4b12881121180de40e09e7956aa05c" } } }, "nbformat": 4, "nbformat_minor": 2 }