.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials\licensing\operator_license.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_licensing_operator_license.py: .. _ref_tutorials_operator_license: Operator License Requirements ============================== Identify which DPF operators require a license checkout and which ones do not. Each DPF operator exposes a :attr:`specification ` property that documents its inputs, outputs, and properties. The ``properties`` dictionary of a |Specification| contains a ``license`` key when the operator requires a product-specific license checkout at evaluation time. - **Operators without a** ``license`` **property**: no additional product license is checked out when they are evaluated. They work in both **Entry** and **Premium** server contexts. - **Operators with a** ``license`` **property**: require DPF to perform a license checkout during evaluation. They are only available in the **Premium** server context. Evaluating them in **Entry** context raises an exception with a clear message. This tutorial shows how to: - Inspect the |Specification| of a single operator for licensing information. - Enumerate all operators and separate them into licensed and unlicensed groups. - Observe the licensing error raised when a licensed operator is evaluated in **Entry** context. .. GENERATED FROM PYTHON SOURCE LINES 56-60 Import Required Modules ----------------------- Import the required modules. .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import operators as ops .. GENERATED FROM PYTHON SOURCE LINES 65-72 Retrieve All Available Operator Names -------------------------------------- Use :func:`available_operator_names ` to get the full list of operators registered on the server. This function requires a server version of 3.0 or later and is only available for InProcess servers. .. GENERATED FROM PYTHON SOURCE LINES 72-78 .. code-block:: Python # Get all operator names available on the global InProcess server all_operator_names = dpf.available_operator_names() print(f"Total operators available: {len(all_operator_names)}") .. rst-class:: sphx-glr-script-out .. code-block:: none Total operators available: 2588 .. GENERATED FROM PYTHON SOURCE LINES 79-85 Inspect an Operator Specification ---------------------------------- The |Specification| of an operator documents its properties in a dictionary. The presence or absence of the ``license`` key tells you whether evaluating the operator requires a product-specific license checkout. .. GENERATED FROM PYTHON SOURCE LINES 85-97 .. code-block:: Python # Inspect the Specification of the displacement result operator (no license required) spec_displacement = ops.result.displacement().specification print("Displacement operator properties:") print(spec_displacement.properties) print() # Inspect the Specification of an operator that requires a license checkout spec_licensed = ops.logic.ascending_sort().specification print("ascending_sort operator properties:") print(spec_licensed.properties) .. rst-class:: sphx-glr-script-out .. code-block:: none Displacement operator properties: {'category': 'result', 'exposure': 'public', 'plugin': 'core', 'scripting_name': 'displacement', 'user_name': 'displacement'} ascending_sort operator properties: {'category': 'logic', 'exposure': 'public', 'license': 'any_dpf_supported_increments', 'plugin': 'core', 'scripting_name': 'ascending_sort', 'user_name': 'ascending sort'} .. GENERATED FROM PYTHON SOURCE LINES 98-106 Separate Operators into Licensed and Unlicensed Groups ------------------------------------------------------- Iterate over all operator names and check for the ``license`` key in their specification properties. Each operator's specification is accessed via a :class:`dpf.Operator ` instance. Operators that have this key require a product license checkout in **Premium** context; those without it do not. .. GENERATED FROM PYTHON SOURCE LINES 106-124 .. code-block:: Python licensed_operators = [] unlicensed_operators = [] for name in all_operator_names: try: spec = dpf.Operator(name).specification if "license" in spec.properties: licensed_operators.append(name) else: unlicensed_operators.append(name) except Exception: # Skip operators whose Specification cannot be retrieved pass print(f"Operators requiring a license checkout: {len(licensed_operators)}") print(f"Operators requiring no license checkout: {len(unlicensed_operators)}") .. rst-class:: sphx-glr-script-out .. code-block:: none Operators requiring a license checkout: 121 Operators requiring no license checkout: 2467 .. GENERATED FROM PYTHON SOURCE LINES 125-131 Examine a Sample of Unlicensed Operators ----------------------------------------- Most DPF operators do not require any product-specific license checkout. Below are a few representative examples filtered to those with ``exposure='public'`` and a human-readable ``user_name``. .. GENERATED FROM PYTHON SOURCE LINES 131-149 .. code-block:: Python # Collect public unlicensed operators that have a user_name unlicensed_public = [] for name in unlicensed_operators: try: spec = dpf.Operator(name).specification props = spec.properties if props.get("exposure") == "public" and "user_name" in props: unlicensed_public.append((name, props["user_name"])) except Exception: pass print(f"Public operators with no license requirement: {len(unlicensed_public)}") print() print("A few examples:") for op_name, user_name in unlicensed_public[:8]: print(f" {op_name:<40} {user_name}") .. rst-class:: sphx-glr-script-out .. code-block:: none Public operators with no license requirement: 685 A few examples: img_part imaginary part amplitude_fc amplitude (fields container) mesh_support_provider mesh support provider EPCR1 creep strain principal 1 B_SN beam axial stress unit_convert_fc unit convert (fields container) norm_fc norm (fields container) propertyfield::get_attribute property field get attribute .. GENERATED FROM PYTHON SOURCE LINES 150-157 Observe the Behavior in Entry Context -------------------------------------- In **Entry** context, DPF performs no license checkouts. Evaluating a licensed operator in that context raises a :class:`DPFServerException ` with a message that explicitly states the licensing context issue. .. GENERATED FROM PYTHON SOURCE LINES 157-180 .. code-block:: Python # Start a separate server in Entry context (as_global=False keeps it isolated) entry_server = dpf.start_local_server( context=dpf.AvailableServerContexts.entry, as_global=False, config=dpf.AvailableServerConfigs.InsecureGrpcServer, ) print(f"Entry server context: {entry_server.context}") print() # Instantiate a licensed operator on the Entry server — instantiation succeeds licensed_op = dpf.Operator(name="ascending_sort", server=entry_server) print("Operator instantiated successfully in Entry context.") # Evaluate it — this triggers the license checkout and raises an exception try: licensed_op.eval() except Exception as licensing_error: print(f"Evaluation error (expected): {licensing_error}") # Shut down the Entry server entry_server.shutdown() .. rst-class:: sphx-glr-script-out .. code-block:: none Entry server context: Server Context of type LicensingContextType.entry with no xml path Operator instantiated successfully in Entry context. Evaluation error (expected): DPF issue due to licensing context: execution stopped. Apply Premium context to unlock this capability. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.122 seconds) .. _sphx_glr_download_tutorials_licensing_operator_license.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: operator_license.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: operator_license.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: operator_license.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_