Trailing zeros and precision
Support has been added for precision information on point and range attributes. This allows both the export of trailing zero information from Granta MI databases and the import of values with specified significant figures.Export of trailing zero information
Trailing zero information can be exported from point and range attributes via the following properties:AttributePointSingle.trailing_zero_informationAttributePointMulti.trailing_zero_informationAttributeRange.low_value_trailing_zero_informationandAttributeRange.high_value_trailing_zero_information
TrailingZeroInformation objects, which describe
how many digits in the float value are significant.
Import of values with significant figures
Attribute values with significant figures can be imported to point and range attributes via the following properties: These properties now acceptValueWithPrecision instances as alternative inputs to float values. The
number of significant figures ValueWithPrecision.significant_figures, evaluated from the provided
ValueWithPrecision.value and ValueWithPrecision.number_of_digits, is added to the attribute value
during import.
See Data with Precision for examples of the new functionality.
Installation and imports
The MI Scripting Toolkit streamlined API is now provided byansys-grantami-core. This package has a dependency on the
Foundation API, which is provided by ansys-grantami-backend-soap. Both packages are delivered together. See
Getting started for how to install the packages, and Package overview for more detail
on how MI Scripting Toolkit is structured.
The GRANTA_MIScriptingToolkit package (referred to as the compatibility package) is provided for backwards
compatibility purposes and may be installed if required. It will be installed by default if upgrading an existing
installation.
Streamlined API
The streamlined API should be accessed by importingansys.grantami.core. Imports from
GRANTA_MIScriptingToolkit.granta are allowed if the compatibility package is installed, but are deprecated.
Imports from GRANTA_MIScriptingToolkit.granta subpackages are not allowed:
from GRANTA_MIScriptingToolkit import granta as mpyis permitted, but emits anAPIDeprecationWarning.from GRANTA_MIScriptingToolkit.granta import Recordis permitted, but emits anAPIDeprecationWarning.from GRANTA_MIScriptingToolkit.granta.mi_record_classes import Recordis no longer allowed and raises anImportError.
Foundation API
The foundation API should be accessed by importingansys.grantami.backend.soap. Imports from
GRANTA_MIScriptingToolkit are allowed if the compatibility package is installed, but are deprecated. Imports from
GRANTA_MIScriptingToolkit subpackages are not allowed:
import GRANTA_MIScriptingToolkit as gdlis permitted, but emits anAPIDeprecationWarning.from GRANTA_MIScriptingToolkit import RecordReferenceis permitted, but emits anAPIDeprecationWarning.from GRANTA_MIScriptingToolkit.RecordReference import RecordReferenceis no longer allowed and raises anImportError.
Session construction
Connecting to Granta MI is now done with aSessionBuilder class. Once the connection is complete, a
Session object is returned. New OIDCSessionBuilder and SessionConfiguration classes have
also been introduced to support the SessionBuilder class.
Direct use of the Session constructor is available if importing the Streamlined API via the
compatibility package, but is deprecated.
Attribute values
Significant changes have been made toAttributeValue in this release, to better
represent the underlying Granta MI behavior. These changes bring the following benefits:
- Better client-side validation. More checks are performed when the Python objects are modified, ensuring the data is compatible with Granta MI when imported.
- More representative classes for attribute sub-types, for example multi-value vs single-value attributes and series vs grid functional data. The allowed types are now narrower and more specific, making the streamlined API easier to use.
- More predictable behavior via the use of immutable types. Attribute values now make use of tuples instead of lists, which allows for additional validation and fewer side effects.
- AttributeDate
- AttributePoint
- AttributeDiscrete
- AttributeRange
- AttributeHyperlink
- Float functional attributes
- AttributeTabular
AttributeLogical.valuenow defaults toNone.AttributePicture.value,AttributePicture.mime_file_type, andAttributePicture.urlnow default toNone.AttributeFile.value,AttributeFile.mime_file_type, andAttributeFile.urlnow default toNone.AttributeFile.file_namenow defaults to the attribute name instead of an empty string.AttributeBinary,AttributeDate,AttributeDiscrete,AttributeHyperlink,AttributeInteger,AttributeLogical,AttributeTabular,AttributeShortText,AttributeLongText, andAttributeUnsupportedno longer haveunitproperties.
AttributeDate
AttributeDate.value now only supports date objects:
- Values exported from Granta MI are represented as
dateobjects instead ofdatetimeobjects set to midnight on the appropriate date. - Values to be imported to Granta MI must be specified as
dateobjects.datetimeandstrobjects are no longer supported.
AttributeDate:
- The
AttributeDate.value_as_stringproperty has been removed. Instead, useisoformat()on the output ofAttributeDate.value. - Setting a date attribute to a value earlier than 1st January 1753 now raises a
ValueErrorimmediately. Previously, a non-descriptive error would be raised on import.
AttributePoint
AttributePoint has been split into AttributePointSingle and AttributePointMulti.
AttributePointSingle represents attribute values for point attributes defined as not allowing multiple
values:
AttributePointSingle.valueonly accepts scalar inputs.- Single point attributes do not include parameters.
AttributePointMulti represents attribute values for point attributes defined as allowing multiple values:
AttributePointMulti.valueonly accepts tuples ofParameterizedPointValueas input.- Parameter values are included in the
ParameterizedPointValuevalues. - The property
AttributePointMulti.parameter_definitionshas been removed.AttributePointMultidefines anAttributePointMulti.parametersproperty, which describes parameters of the attribute and their current unit.
AttributePointSingle.valueandAttributePointMulti.valueboth default toNonefor empty or not applicable attribute values.- Invalid inputs now raise a
TypeError. AttributePointSingle.default_unitandAttributePointMulti.default_unitreturn the default unit for the point attribute as defined in the attribute definition, but converted to the active unit system.- The methods
AttributePointMulti.set_value()andAttributePointSingle.set_value()have been added to support setting the attribute value from a broader set of types. - The
unitproperty now returnsNonefor dimensionless attributes, instead of an empty string. - Point attribute values now support precision information. See Trailing zeros and precision for more details.
AttributeDiscrete
AttributeDiscrete has been split into AttributeDiscreteSingle and AttributeDiscreteMulti.
AttributeDiscreteSingle represents attribute values for discrete attributes defined as not allowing multiple
values:
AttributeDiscreteSingle.valueonly accepts string inputs. A list of strings is not permitted.AttributeDiscreteSingle.orderis now a single integer value.
AttributeDiscreteMulti represents attribute values for discrete attributes defined as allowing multiple
values:
AttributeDiscreteMulti.valuenow returns a tuple of strings, and only accepts a tuple of strings as input. A single string is not permitted.AttributeDiscreteMulti.orderis a tuple of integers.
AttributeDiscreteSingle.valueandAttributeDiscreteMulti.orderboth default toNonefor empty or not applicable attribute values.- Properties
AttributeDiscreteSingle.orderandAttributeDiscreteMulti.orderare now updated whenAttributeDiscreteSingle.valueorAttributeDiscreteMulti.valueare modified.
AttributeRange
The interface for range attribute values has changed significantly since the previous release.
WARNING
Any code that uses the v4.2AttributeRange class will need to be modified when upgrading to v5.0.
AttributeRange.value can now only be set to an instance of Range:
Rangeis a frozen dataclass.- The alternative constructor
Range.from_data()supports previously accepted range values (seeRange_Value_Type). Range.as_dict()returns a dictionary of low and high values, identical to the value previously returned byAttributeRange.valuefor exported attribute values.AttributeRange.valuereturnsNonefor empty or not applicable attribute values, and aRangeobject otherwise.
AttributeRange:
- Added properties
AttributeRange.lowandAttributeRange.highto access the low and high values of a range attribute. These properties always returnfloat,ValueWithPrecision, orNone(for open-ended ranges), notint. AttributeRange.default_unitreturns the default unit for the attribute as defined in the attribute definition, but converted to the active unit system.AttributeRange.unitnow returnsNonefor dimensionless attributes, instead of an empty string.- Range attribute values now support precision information. See Trailing zeros and precision for more details.
AttributeHyperlink
- The property
.objecthas been removed fromAttributeHyperlink. Use the propertiesAttributeHyperlink.value,AttributeHyperlink.hyperlink_display, andAttributeHyperlink.hyperlink_descriptioninstead. - Properties
AttributeHyperlink.hyperlink_description,AttributeFile.description,AttributeFile.url, andAttributePicture.urlnow returnNoneif properties are not set, instead of an empty string.
Float functional attributes
The interface for float functional attribute values has changed significantly since the previous release.WARNING
Any code that uses the v4.2AttributeFunctional class will need to be modified when upgrading to v5.0.
These changes were required for the following reasons:
- To support series functional data where multiple series share the same set of parameter values. In previous versions, it was not possible to determine which data points belonged to which series.
- To support enhanced validation. In previous versions, it was possible to create invalid functional data objects that would only fail when import was attempted.
- To support greater control over datum-level parameter settings. In previous versions, it was not possible to fully specify datum-level parameter settings, or to determine if a parameter setting was inherited or set directly.
Attribute value changes
FunctionalSerieshas been split into two new classes to represent point and range series data. These changes allow the representation of series data where multiple series share the same set of parameter values. The list below contains the new classes, and the specific types accepted by the.valueproperty:AttributeFunctionalSeriesPoint.valueaccepts atupleofSeriesPointobjects.AttributeFunctionalSeriesRange.valueaccepts atupleofSeriesRangeobjects.
FunctionalGridhas been split into two separate classes to represent point and range grid data. The.valueproperty for each of these classes accepts specific objects as described below:AttributeFunctionalGridPoint.valueaccepts aGridPointobject.AttributeFunctionalGridRange.valueaccepts aGridRangeobject.
FunctionalSeries.hide_graphhas been renamed toshow_as_table. This is available onAttributeFunctionalSeriesPointandAttributeFunctionalSeriesRangeclasses.- By default, the methods
generate_grid_version()orgenerate_series_version()onAttributeFunctionalSeriesPoint,AttributeFunctionalSeriesRange,AttributeFunctionalGridPoint, andAttributeFunctionalGridRangeclasses copy the data, unit, datum parameter settings, and applicableness to the new attribute value. The optional parametercreate_emptycan be set toTrueto create empty versions of the attribute values instead. - Removed
AttributeFunctionalSeries.series_linestylesandAttributeFunctionalGrid.linestyle. Use thedecorationproperty available forSeriesPoint,SeriesRange,GridPointandGridRangeclasses instead. - Removed
AttributeFunctional.clear(). Set the.valuetoNone. - The functional data representation from previous versions is available as the read-only property
table_viewforAttributeFunctionalSeriesPoint,AttributeFunctionalSeriesRange,AttributeFunctionalGridPoint, andAttributeFunctionalGridRangeclasses. - The methods
AttributeFunctionalSeriesPoint.set_value()andAttributeFunctionalSeriesRange.set_value()have been added to support setting the attribute value from any sequence of series objects. - The
unitproperty on functional attribute classes now returnsNonefor dimensionless attributes, instead of an empty string.
X-axis changes
AttributeFunctional.xaxis_parameterhas been removed. To access x-axis parameter information, use thex_axisproperty to obtain the x-axis parameter name, and provide the result to theparametersmapping. Thex_axisproperty is available forAttributeFunctionalSeriesPoint,AttributeFunctionalSeriesRange,AttributeFunctionalGridPoint, andAttributeFunctionalGridRangeclasses.- The mapping
AttributeFunctional.xaxishas been removed. Usewith_new_x_axis(), to create an attribute value with a different x-axis. This method is available forAttributeFunctionalSeriesPoint,AttributeFunctionalSeriesRange,AttributeFunctionalGridPoint, andAttributeFunctionalGridRangeclasses.
Parameter changes
- The
parametersproperty, available forAttributeFunctionalSeriesPoint,AttributeFunctionalSeriesRange,AttributeFunctionalGridPoint, andAttributeFunctionalGridRange, now returns a mapping of parameter names toFunctionalValueParameterobjects. FunctionalValueParameterobjects hold information about datum level parameter settings. If these properties are set, they represent a datum-specific setting for that parameter which may override an attribute-level setting. If they are set toNone, this specifies that the particular setting is inherited from the attribute parameter definition. In this case, the inherited value is available in the corresponding ‘effective’ property. See the API reference for more details.
AttributeTabular
The interface for tabular attribute values has changed significantly since the previous release.
WARNING
Any code that uses the v4.2AttributeTabular class will need to be modified when upgrading to v5.0.
These changes were required to allow a more granular and efficient way to edit and import data. In previous versions of
MI Scripting Toolkit, tabular data was imported as a whole object, even when updating a single cell. This could cause a large
overhead when interacting with tabular attributes with many rows, and with binary columns.
As a result of these changes, the interface now provides more information about rows and cells, and improves performance
in scenarios where only a subset of the table data is modified.
New classes have been added to represent tabular rows and cells. These ensure that data provided is consistent with the
schema definition of the attribute.
Attribute value changes
- New class
TabularRowrepresents a row in a tabular attribute value. The row provides access to the linking value of the row, the row identifier and the cells in the row. The cells can be accessed as a tuple viaTabularRow.cells, or as a mapping from column name to cell viaTabularRow.cells_by_column. - A new property
AttributeTabular.rowsprovides access to the rows of the table as a sequence ofTabularRowobjects. - The
.valueproperty onAttributeTabularis now read-only, replicating where possible the existing interface. All updates should be performed via the new interface. - The
.add_rowmethod onAttributeTabularhas been renamed toAttributeTabular.append_row(), to better reflect its behavior. - The
.unitsproperty has been removed fromAttributeTabular. To access the units as defined on the column, use theAttributeDefinitionTabular.column_unitsproperty. To access the unit for a specific cell, use theRangeValue.unitorPointValue.unitproperty on the cell. - Direct indexing of the tabular attribute value to access rows has been removed.
- Operations which can cause data loss for users of Data Updater have been disabled by default. To enable them for a
specific attribute value, call
AttributeTabular.enable_destructive_editing().
Cell changes
- New classes
ShortTextValue,LongTextValue,LogicalValue,IntegerValue,DateValue,PictureValue, andFileValuerepresent individual linked cells in a tabular attribute value. The corresponding Local versions of these classes are used to represent local cells.
Invalid operations on staged records
The behavior when invalid operations are performed on staged records has been standardized. The following methods and properties now all raiseInvalidRecordStateError when called on staged records: