From 9234263c8aea78994db3d002f000ff9a123f975c Mon Sep 17 00:00:00 2001 From: Dominik Gresch Date: Fri, 2 Feb 2024 16:11:10 +0100 Subject: [PATCH 1/2] Update dev notebooks --- dev_utils/connection_test.ipynb | 28 ++++++++------------------ dev_utils/material.ipynb | 35 ++++----------------------------- dev_utils/test.ipynb | 30 ++++++++-------------------- 3 files changed, 20 insertions(+), 73 deletions(-) diff --git a/dev_utils/connection_test.ipynb b/dev_utils/connection_test.ipynb index eb38377c16..f2d6154ad2 100644 --- a/dev_utils/connection_test.ipynb +++ b/dev_utils/connection_test.ipynb @@ -72,8 +72,7 @@ "metadata": {}, "outputs": [], "source": [ - "slow_server = pyacp.launch_acp(config=slow_launch)\n", - "normal_server = pyacp.launch_acp(config=normal_launch)" + "slow_acp = pyacp.launch_acp(config=slow_launch)" ] }, { @@ -82,18 +81,7 @@ "metadata": {}, "outputs": [], "source": [ - "slow_server.wait(timeout=30)\n", - "normal_server.wait(timeout=30)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "client_slow = pyacp.Client(slow_server)\n", - "client_normal = pyacp.Client(normal_server)" + "normal_acp = pyacp.launch_acp(config=normal_launch)" ] }, { @@ -110,13 +98,13 @@ "metadata": {}, "outputs": [], "source": [ - "def run_example(client):\n", - " f = client.upload_file(local_path=\"../examples/data/class40/class40.cdb\")\n", - " m = client.import_model(path=f, format=\"ansys:cdb\")\n", + "def run_example(acp_instance):\n", + " f = acp_instance.upload_file(local_path=\"../examples/data/class40/class40.cdb\")\n", + " m = acp_instance.import_model(path=f, format=\"ansys:cdb\")\n", " mg = m.create_modeling_group()\n", " for _ in range(100):\n", " mg.create_modeling_ply()\n", - " client.clear()" + " acp_instance.clear()" ] }, { @@ -125,7 +113,7 @@ "metadata": {}, "outputs": [], "source": [ - "run_example(client_normal)" + "run_example(normal_acp)" ] }, { @@ -134,7 +122,7 @@ "metadata": {}, "outputs": [], "source": [ - "run_example(client_slow)" + "run_example(slow_acp)" ] }, { diff --git a/dev_utils/material.ipynb b/dev_utils/material.ipynb index 4092f811e7..d50803084e 100644 --- a/dev_utils/material.ipynb +++ b/dev_utils/material.ipynb @@ -53,26 +53,7 @@ "metadata": {}, "outputs": [], "source": [ - "server = pyacp.launch_acp()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "server.wait(timeout=20)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "client = pyacp.Client(server)\n", - "client.clear()" + "acp = pyacp.launch_acp()" ] }, { @@ -104,7 +85,7 @@ "metadata": {}, "outputs": [], "source": [ - "model_file_remote = client.upload_file(str(model_file))" + "model_file_remote = acp.upload_file(str(model_file))" ] }, { @@ -113,7 +94,7 @@ "metadata": {}, "outputs": [], "source": [ - "model = client.import_model(path=str(model_file_remote))" + "model = acp.import_model(path=str(model_file_remote))" ] }, { @@ -314,9 +295,8 @@ "metadata": {}, "outputs": [], "source": [ - "from ansys.acp.core._tree_objects.material import EngineeringConstantsPropertySet\n", "# re-create by assignment\n", - "mat2.engineering_constants = EngineeringConstantsPropertySet()" + "mat2.engineering_constants = pyacp.ConstantEngineeringConstants()" ] }, { @@ -377,13 +357,6 @@ "source": [ "mat3.engineering_constants.field_variables" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {}, diff --git a/dev_utils/test.ipynb b/dev_utils/test.ipynb index cf964deca5..39689e0040 100644 --- a/dev_utils/test.ipynb +++ b/dev_utils/test.ipynb @@ -55,26 +55,7 @@ "metadata": {}, "outputs": [], "source": [ - "server = pyacp.launch_acp()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "server.wait(timeout=20)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "client = pyacp.Client(server)\n", - "client.clear()" + "acp = pyacp.launch_acp()" ] }, { @@ -99,7 +80,7 @@ "metadata": {}, "outputs": [], "source": [ - "model_file_remote = client.upload_file(str(model_file))" + "model_file_remote = acp.upload_file(str(model_file))" ] }, { @@ -108,7 +89,7 @@ "metadata": {}, "outputs": [], "source": [ - "model = client.import_model(path=str(model_file_remote))" + "model = acp.import_model(path=str(model_file_remote))" ] }, { @@ -121,6 +102,11 @@ "\n", "---" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] } ], "metadata": {}, From 241a5b533bf92ba843ae4708e3bc946ad86755c8 Mon Sep 17 00:00:00 2001 From: Dominik Gresch Date: Mon, 5 Feb 2024 13:39:15 +0100 Subject: [PATCH 2/2] Remove dev notebooks other than connection test, add outdated note --- dev_utils/README.md | 5 + dev_utils/connection_test.ipynb | 13 +- dev_utils/material.ipynb | 365 -------------------------------- dev_utils/test.ipynb | 115 ---------- 4 files changed, 16 insertions(+), 482 deletions(-) create mode 100644 dev_utils/README.md delete mode 100644 dev_utils/material.ipynb delete mode 100644 dev_utils/test.ipynb diff --git a/dev_utils/README.md b/dev_utils/README.md new file mode 100644 index 0000000000..290940c0cc --- /dev/null +++ b/dev_utils/README.md @@ -0,0 +1,5 @@ +# Development notebooks + +This directory contains Jupyter notebooks meant for interactively testing the code. + +Note that these notebooks are not checked as part of the CI pipeline, and could therefore be outdated. diff --git a/dev_utils/connection_test.ipynb b/dev_utils/connection_test.ipynb index f2d6154ad2..d744c49d79 100644 --- a/dev_utils/connection_test.ipynb +++ b/dev_utils/connection_test.ipynb @@ -13,9 +13,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This notebook tests the PyACP performance when run with a slower network connection. It uses the Linux ``tc-netem`` command to emulate a slower (latency- and bandwidth-restricted) network in a Docker container.\n", + "This notebook tests the PyACP performance when run with a slower network connection. It uses the Linux ``tc-netem`` command to emulate a slower (latency- and bandwidth-restricted) network in a Docker container." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "**NOTE**\n", "\n", - "Note that not all Linux kernels support ``tc-netem``: For example, it cannot be run on WSL2." + "- not all Linux kernels support ``tc-netem``. For example, it cannot be run on WSL2.\n", + "- this notebook may become outdated as the PyACP codebase evolves. It is not regularly checked for compatibility, and may need to be updated." ] }, { diff --git a/dev_utils/material.ipynb b/dev_utils/material.ipynb deleted file mode 100644 index d50803084e..0000000000 --- a/dev_utils/material.ipynb +++ /dev/null @@ -1,365 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Material API demo" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Import dependencies" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import pathlib\n", - "\n", - "import ansys.acp.core as pyacp" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Launch server" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note: Use the ansys-launcher to configure the desired launch mode, e.g. ``ansys-launcher configure ACP direct``" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "acp = pyacp.launch_acp()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Import model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "test_model_data = pathlib.Path(os.environ[\"ACP_TEST_MODEL_DATA\"])\n", - "model_file = (\n", - " test_model_data\n", - " / \"model_data\"\n", - " / \"variable_material\"\n", - " / \"multi-dimensional_materials\"\n", - " / \"VariableSamplingPoint.acph5\"\n", - ")\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "model_file_remote = acp.upload_file(str(model_file))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "model = acp.import_model(path=str(model_file_remote))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Material API" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "list(model.materials.items())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Constant Material" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Read-only, because the material is locked." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat1 = model.materials['Epoxy_Carbon_UD_230GPa_Prepreg']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The `__str__` representation shows the gRPC attributes" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(str(mat1.density))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(str(mat1.engineering_constants))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create a new material" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2 = model.create_material()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.density.rho = 1200" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.density = None" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.engineering_constants.E1 = 1.2e7\n", - "mat2.engineering_constants.E1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(str(mat2.engineering_constants))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now, changing the ply type to isotropic is blocked:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.ply_type = \"isotropic\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.engineering_constants.E1 = 0" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.ply_type = \"isotropic\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now, the isotropic engineering constants are enabled:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(str(mat2.engineering_constants))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Delete property set by setting it to `None`, or with `del`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.engineering_constants = None" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.engineering_constants" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# re-create by assignment\n", - "mat2.engineering_constants = pyacp.ConstantEngineeringConstants()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat2.engineering_constants" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Variable material property" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat3 = model.materials['Epoxy_EGlass_UD shear_degra']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(str(mat3.engineering_constants))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All read-only" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat3.engineering_constants.nu13 = (1, 2, 3)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mat3.engineering_constants.field_variables" - ] - } - ], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/dev_utils/test.ipynb b/dev_utils/test.ipynb deleted file mode 100644 index 39689e0040..0000000000 --- a/dev_utils/test.ipynb +++ /dev/null @@ -1,115 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## PyACP testing notebook\n", - "\n", - "This notebook loads a PyACP model, and is intended for interactive testing / exploration." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Import dependencies" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import pathlib\n", - "\n", - "import ansys.acp.core as pyacp" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Launch server" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note: Use the ansys-launcher to configure the desired launch mode, e.g. ``ansys-launcher configure ACP direct``" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "acp = pyacp.launch_acp()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Import model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "model_file = pathlib.Path(os.getcwd()).parent / \"tests\" / \"data\" / \"minimal_complete_model.acph5\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "model_file_remote = acp.upload_file(str(model_file))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "model = acp.import_model(path=str(model_file_remote))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Test area\n", - "\n", - "Add your testing below. Do not commit the changes.\n", - "\n", - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - } - ], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 2 -}