BUG: Handling of single-element array extent
Closed this issue · 4 comments
Consider the following property instance:
results.edn
[{
"property-id" "tag:staff@noreply.openkim.org,2014-05-21:property/surface-energy-broken-bond-fit-cubic-bravais-crystal-npt"
"instance-id" 1
"short-name" {
"source-value" ["fcc"]
}
"species" {
"source-value" [ "Cu" ]
}
"a" {
"source-value" 3.615000084042549
"source-unit" "angstrom"
}
"space-group" {
"source-value" "Fm-3m"
}
"temperature" {
"source-value" 0
"source-unit" "K"
}
"cauchy-stress" {
"source-value" [ 0 0 0 0 0 0 ]
"source-unit" "GPa"
}
"fit-c" {
"source-value" 0.0027978760473830297
"source-unit" "eV/angstrom^2"
}
"fit-p1" {
"source-value" 0.005279181971724211
"source-unit" "eV/angstrom^2"
}
"fit-p2" {
"source-value" 0.0006165355304842123
"source-unit" "eV/angstrom^2"
}
"fit-p3" {
"source-value" -0.0005145747612410938
"source-unit" "eV/angstrom^2"
}
"fit-error-max" {
"source-value" 4.712160205228084e-16
}
"fit-error-range" {
"source-value" 1.5506207981968703e-16
}
}]
and the corresponding property definition:
surface-energy-broken-bond-fit-cubic-bravais-crystal-npt
{
"property-id" "tag:staff@noreply.openkim.org,2014-05-21:property/surface-energy-broken-bond-fit-cubic-bravais-crystal-npt"
"property-title" "Surface energy broken bond fit model"
"property-description" "Surface energy fit obtained by calculating the number of broken bonds created by cleaving a crystal at a given hydrostatic stress and temperature. These are the prefactors associated with each term in the model."
"short-name" {
"type" "string"
"has-unit" false
"extent" [1]
"required" false
"description" "Short name defining the cubic crystal type."
}
"species" {
"type" "string"
"has-unit" false
"extent" [1]
"required" true
"description" "The element symbols of the basis atoms. The order in which the species are specified must correspond to the order of the atoms listed in 'basis-atom-coordinates'."
}
"a" {
"type" "float"
"has-unit" true
"extent" []
"required" true
"description" "Average equilibrium conventional lattice constant of the cubic crystal."
}
"space-group" {
"type" "string"
"has-unit" false
"extent" []
"required" false
"description" "Hermann-Mauguin designation for the space group associated with the symmetry of the crystal (e.g. Immm, Fm-3m, P6_3/mmc)."
}
"wyckoff-species" {
"type" "string"
"has-unit" false
"extent" [":"]
"required" false
"description" "The element symbol of the atomic species of the unique Wyckoff sites used in the fully symmetry-reduced description of the crystal. The order of the entries must correspond to the order of the entries in 'wyckoff-multiplicity-and-letter' and 'wyckoff-coordinates'."
}
"wyckoff-multiplicity-and-letter" {
"type" "string"
"has-unit" false
"extent" [":"]
"required" false
"description" "Multiplicity and standard letter of the unique Wyckoff sites used in the fully symmetry-reduced description of the crystal (e.g. 4a, 2b). Note that the sum of the Wyckoff multiplicities should equal the total number of elements in 'basis-atom-coordinates'. The order of elements in this array must correspond to the order of the entries listed in 'wyckoff-species' and 'wyckoff-coordinates'."
}
"wyckoff-coordinates" {
"type" "float"
"has-unit" false
"extent" [":",3]
"required" false
"description" "Coordinates of the unique Wyckoff sites used in the fully symmetry-reduced description of the crystal, given as fractions of the lattice vectors. The order of elements in this array must correspond to the order of the entries listed in 'wyckoff-species' and 'wyckoff-multiplicity-and-letter'."
}
"temperature" {
"type" "float"
"has-unit" true
"extent" []
"required" true
"description" "Temperature of the crystal."
}
"cauchy-stress" {
"type" "float"
"has-unit" true
"extent" [6]
"required" true
"description" "The [xx,yy,zz,yz,xz,xy] (i.e. [11,22,33,23,13,12]) components of the Cauchy stress acting on the periodic cell. The orthonormal basis used to express the stress should be aligned with the cubic 4-fold axes of the crystal and the expected form of the stress tensor should be [d d d 0 0 0], where d > 0 indicates tensile stress."
}
"fit-c" {
"type" "float"
"has-unit" true
"extent" []
"required" true
"description" "Constant offset term."
}
"fit-p1" {
"type" "float"
"has-unit" true
"extent" []
"required" true
"description" "Fit parameter 1, the prefactor for the first term."
}
"fit-p2" {
"type" "float"
"has-unit" true
"extent" []
"required" true
"description" "Fit parameter 2, the prefactor for the second term."
}
"fit-p3" {
"type" "float"
"has-unit" true
"extent" []
"required" true
"description" "Fit parameter 3, the prefactor for the third term."
}
"fit-error-max" {
"type" "float"
"has-unit" false
"extent" []
"required" true
"description" "Maximum relative error of the fit given calculated values, given by max{ abs( (E_{fit} - E_{measured)/E_measured ) }."
}
"fit-error-range" {
"type" "float"
"has-unit" false
"extent" []
"required" true
"description" "Total average relative range of the error for the fit, \\sum{ |E_error / (E_max - E_min)| }/N, error given by E_{fit} - E_{measured}"
}
}
The key short-name
in the property definition is specified as having extent [1]
. This is supposed to mean that the value of short-name
must be an array containing a single element. However, as of version 2.5.2 of kim-property, it's trying to interpret this as meaning that the value must be a scalar, which is a bug:
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import kim_property
>>> kim_property.check_property_instances(fi="results.edn", fp_path="/home/openkim/kimproperty-testing/properties")
Traceback (most recent call last):
File "/home/openkim/.local/lib/python3.8/site-packages/kim_property/instance.py", line 323, in check_instance_optional_key_map
check_instance_optional_key_standard_pairs_format(
File "/home/openkim/.local/lib/python3.8/site-packages/kim_property/instance.py", line 271, in check_instance_optional_key_standard_pairs_format
raise KIMPropertyError(msg)
kim_property.err.KIMPropertyError:
ERROR(@check_instance_optional_key_standard_pairs_format): "extent" specifies single item, but "source-value" in the property instance is an array of values.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/openkim/.local/lib/python3.8/site-packages/kim_property/instance.py", line 565, in check_property_instances
check_instance_optional_key_map(
File "/home/openkim/.local/lib/python3.8/site-packages/kim_property/instance.py", line 328, in check_instance_optional_key_map
raise KIMPropertyError(msg)
kim_property.err.KIMPropertyError:
ERROR(@check_instance_optional_key_map): in property instance key = "short-name"
<class 'kim_property.err.KIMPropertyError'>
@dskarls I considered extent []
and extent [1]
scalar and treated them accordingly. But here, it seems that I have to consider the case of extent [1]
for both scalar and an array containing a single element. Is this correct? If this is the expected behavior, I can extend the functionality.
As per the docs, extent []
is used for scalars, and extent [1]
would mean an array containing a single element.
I updated the interface as per kim doc. Now it treats extent [1]
as an array containing a single element. I do the release later.
Latest master branch confirmed working. Ok to close. Thanks, Yaser!