From 19ad53bf191514dc44a8be38c1e377794609949e Mon Sep 17 00:00:00 2001 From: Matt Rutkowski Date: Tue, 7 May 2024 14:56:35 -0500 Subject: [PATCH] Add datatypes for new v1.6 EnvironmentalConsiderations to ModelCard data (#88) Signed-off-by: Matt Rutkowski --- .vscode/settings.json | 1 + schema/bom_hash_test.go | 11 ++- schema/cyclonedx_modelcard.go | 129 ++++++++++++++++++++++++---------- 3 files changed, 96 insertions(+), 45 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 38fcaabd..0ef6ff62 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -104,6 +104,7 @@ "prettyjson", "PROPKEY", "protonmail", + "pypi", "repackager", "rvoi", "rwxr", diff --git a/schema/bom_hash_test.go b/schema/bom_hash_test.go index 02edb34e..cbb8b317 100644 --- a/schema/bom_hash_test.go +++ b/schema/bom_hash_test.go @@ -308,12 +308,11 @@ func TestHashCDXComponentsSlice(t *testing.T) { return } - if components != nil { - err = document.HashmapComponents(*components, nil, false) - if err != nil { - t.Error(err) - return - } + // Now that we believe we have actual components, hash them + err = document.HashmapComponents(*components, nil, false) + if err != nil { + t.Error(err) + return } } diff --git a/schema/cyclonedx_modelcard.go b/schema/cyclonedx_modelcard.go index 225ad396..8f0a3412 100644 --- a/schema/cyclonedx_modelcard.go +++ b/schema/cyclonedx_modelcard.go @@ -25,11 +25,11 @@ package schema // v1.5: added // NOTE: CDXRefType is a named `string` type as of v1.5 type CDXModelCard struct { - BOMRef *CDXRefType `json:"bom-ref,omitempty"` // v1.5 - ModelParameters *CDXModelParameters `json:"modelParameters,omitempty"` // v1.5 - QuantitativeAnalysis *CDXQuantitativeAnalysis `json:"quantitativeAnalysis,omitempty"` // v1.5 - Considerations *CDXConsiderations `json:"considerations,omitempty"` // v1.5 - Properties *[]CDXProperty `json:"properties,omitempty"` // v1.5 + BOMRef *CDXRefType `json:"bom-ref,omitempty" cdx:"+1.5"` // v1.5 + ModelParameters *CDXModelParameters `json:"modelParameters,omitempty" cdx:"+1.5"` // v1.5 + QuantitativeAnalysis *CDXQuantitativeAnalysis `json:"quantitativeAnalysis,omitempty" cdx:"+1.5"` // v1.5 + Considerations *CDXConsiderations `json:"considerations,omitempty" cdx:"+1.5"` // v1.5 + Properties *[]CDXProperty `json:"properties,omitempty" cdx:"+1.5"` // v1.5 } // ======================================== @@ -38,20 +38,20 @@ type CDXModelCard struct { // v1.5: added type CDXModelParameters struct { - Approach *CDXApproach `json:"approach,omitempty"` // v1.5 - Task string `json:"task,omitempty"` // v1.5 - ArchitectureFamily string `json:"architectureFamily,omitempty"` // v1.5 - ModelArchitecture string `json:"modelArchitecture,omitempty"` // v1.5 - Datasets *[]CDXDataset `json:"datasets,omitempty"` // v1.5 - Inputs *[]CDXInputOutputMLParameters `json:"inputs,omitempty"` // v1.5 - Outputs *[]CDXInputOutputMLParameters `json:"outputs,omitempty"` // v1.5 + Approach *CDXApproach `json:"approach,omitempty" cdx:"+1.5"` // v1.5 + Task string `json:"task,omitempty" cdx:"+1.5"` // v1.5 + ArchitectureFamily string `json:"architectureFamily,omitempty" cdx:"+1.5"` // v1.5 + ModelArchitecture string `json:"modelArchitecture,omitempty" cdx:"+1.5"` // v1.5 + Datasets *[]CDXDataset `json:"datasets,omitempty" cdx:"+1.5"` // v1.5 + Inputs *[]CDXInputOutputMLParameters `json:"inputs,omitempty" cdx:"+1.5"` // v1.5 + Outputs *[]CDXInputOutputMLParameters `json:"outputs,omitempty" cdx:"+1.5"` // v1.5 } // v1.5: added // "Learning types describing the learning problem or hybrid learning problem." // "enum": ["supervised","unsupervised","reinforcement-learning","semi-supervised","self-supervised"] type CDXApproach struct { - Type string `json:"type,omitempty"` // v1.5 + Type string `json:"type,omitempty" cdx:"+1.5"` // v1.5 } // v1.5: added. @@ -59,14 +59,14 @@ type CDXApproach struct { // TODO: actually, "Ref" should be its own anonymous type with "anyOf": ["#/definitions/refLinkType", "#/definitions/bomLinkElementType"] type CDXDataset struct { CDXComponentData - Ref *CDXRefLinkType `json:"ref,omitempty"` // v1.5 + Ref *CDXRefLinkType `json:"ref,omitempty" cdx:"+1.5"` // v1.5 } // v1.5: added // "The data format for input/output to the model. // Example formats include string, image, time-series", type CDXInputOutputMLParameters struct { - Format string `json:"format,omitempty"` // v1.5 + Format string `json:"format,omitempty" cdx:"+1.5"` // v1.5 } // ======================================== @@ -75,34 +75,34 @@ type CDXInputOutputMLParameters struct { // v1.5: added (anonymous type) type CDXQuantitativeAnalysis struct { - PerformanceMetrics *[]CDXPerformanceMetric `json:"performanceMetrics,omitempty"` // v1.5 - Graphics *CDXGraphicsCollection `json:"graphics,omitempty"` // v1.5 + PerformanceMetrics *[]CDXPerformanceMetric `json:"performanceMetrics,omitempty" cdx:"+1.5"` // v1.5 + Graphics *CDXGraphicsCollection `json:"graphics,omitempty" cdx:"+1.5"` // v1.5 } // v1.5: added type CDXPerformanceMetric struct { - Type string `json:"type,omitempty"` // v1.5 - Value string `json:"value,omitempty"` // v1.5 - Slice string `json:"slice,omitempty"` // v1.5 - ConfidenceInterval *CDXConfidenceInterval `json:"confidenceInterval,omitempty"` // v1.5 + Type string `json:"type,omitempty" cdx:"+1.5"` // v1.5 + Value string `json:"value,omitempty" cdx:"+1.5"` // v1.5 + Slice string `json:"slice,omitempty" cdx:"+1.5"` // v1.5 + ConfidenceInterval *CDXConfidenceInterval `json:"confidenceInterval,omitempty" cdx:"+1.5"` // v1.5 } // v1.5: added type CDXConfidenceInterval struct { - LowerBound string `json:"lowerBound,omitempty"` // v1.5 - UpperBound string `json:"upperBound,omitempty"` // v1.5 + LowerBound string `json:"lowerBound,omitempty" cdx:"+1.5"` // v1.5 + UpperBound string `json:"upperBound,omitempty" cdx:"+1.5"` // v1.5 } // v1.5: added type CDXGraphicsCollection struct { - Description string `json:"description,omitempty"` // v1.5 - Collection *[]CDXGraphic `json:"collection,omitempty"` // v1.5 + Description string `json:"description,omitempty" cdx:"+1.5"` // v1.5 + Collection *[]CDXGraphic `json:"collection,omitempty" cdx:"+1.5"` // v1.5 } // v1.5: added type CDXGraphic struct { - Name string `json:"name,omitempty"` // v1.5 - Image *CDXAttachment `json:"image,omitempty"` // v1.5 + Name string `json:"name,omitempty" cdx:"+1.5"` // v1.5 + Image *CDXAttachment `json:"image,omitempty" cdx:"+1.5"` // v1.5 } // ======================================== @@ -113,25 +113,76 @@ type CDXGraphic struct { // Considerations that should be taken into account regarding the model's construction, // training, and application type CDXConsiderations struct { - Users *[]string `json:"users,omitempty"` // v1.5 - UseCases *[]string `json:"useCases,omitempty"` // v1.5 - TechnicalLimitations *[]string `json:"technicalLimitations,omitempty"` // v1.5 - PerformanceTradeoffs *[]string `json:"performanceTradeoffs,omitempty"` // v1.5 - EthicalConsiderations *[]CDXRisk `json:"ethicalConsiderations,omitempty"` // v1.5 - FairnessAssessments *[]CDXFairnessAssessment `json:"fairnessAssessments,omitempty"` // v1.5 + Users *[]string `json:"users,omitempty" cdx:"+1.5"` // v1.5 + UseCases *[]string `json:"useCases,omitempty" cdx:"+1.5"` // v1.5 + TechnicalLimitations *[]string `json:"technicalLimitations,omitempty" cdx:"+1.5"` // v1.5 + PerformanceTradeoffs *[]string `json:"performanceTradeoffs,omitempty" cdx:"+1.5"` // v1.5 + EthicalConsiderations *[]CDXRisk `json:"ethicalConsiderations,omitempty" cdx:"+1.5"` // v1.5 + FairnessAssessments *[]CDXFairnessAssessment `json:"fairnessAssessments,omitempty" cdx:"+1.5"` // v1.5 + EnvironmentalConsiderations *CDXEnvironmentalConsiderations `json:"environmentalConsiderations,omitempty" cdx:"+1.6"` // v1.6 } // v1.5: added type CDXRisk struct { - Name string `json:"name,omitempty"` // v1.5 - MitigationStrategy string `json:"mitigationStrategy,omitempty"` // v1.5 + Name string `json:"name,omitempty" cdx:"+1.5"` // v1.5 + MitigationStrategy string `json:"mitigationStrategy,omitempty" cdx:"+1.5"` // v1.5 } // v1.5: added // Information about the benefits and harms of the model to an identified at risk group. type CDXFairnessAssessment struct { - GroupAtRisk string `json:"groupAtRisk,omitempty"` // v1.5 - Benefits string `json:"benefits,omitempty"` // v1.5 - Harms string `json:"harms,omitempty"` // v1.5 - MitigationStrategy string `json:"mitigationStrategy,omitempty"` // v1.5 + GroupAtRisk string `json:"groupAtRisk,omitempty" cdx:"+1.5"` // v1.5 + Benefits string `json:"benefits,omitempty" cdx:"+1.5"` // v1.5 + Harms string `json:"harms,omitempty" cdx:"+1.5"` // v1.5 + MitigationStrategy string `json:"mitigationStrategy,omitempty" cdx:"+1.5"` // v1.5 +} + +// v1.6: added +// Information about the benefits and harms of the model to an identified at risk group. +type CDXEnvironmentalConsiderations struct { + EnergyConsumptions *[]CDXEnergyConsumption `json:"energyConsumptions,omitempty" cdx:"+1.6"` // v1.6 + Properties *[]CDXProperty `json:"properties,omitempty" cdx:"+1.6"` // v1.6 +} + +// v1.6: added +type CDXEnergyConsumption struct { + Activity string `json:"activity,omitempty" cdx:"+1.6"` // v1.6 + EnergyProviders *[]CDXEnergyProvider `json:"energyProviders,omitempty" cdx:"+1.6"` // v1.6 + ActivityEnergyCost *CDXEnergyMeasure `json:"activityEnergyCost,omitempty" cdx:"+1.6"` // v1.6 + Co2CostEquivalent *CDXCo2Measure `json:"co2CostEquivalent,omitempty" cdx:"+1.6"` // v1.6 + Co2CostOffset *CDXCo2Measure `json:"co2CostOffset,omitempty" cdx:"+1.6"` // v1.6 + Properties *[]CDXProperty `json:"properties,omitempty" cdx:"+1.6"` // v1.6 +} + +// v1.6: added +type CDXEnergyMeasure struct { + Value float64 `json:"value,omitempty" cdx:"+1.6"` // v1.6 + Unit string `json:"unit,omitempty" cdx:"+1.6"` // v1.6 +} + +// v1.6: added +type CDXCo2Measure struct { + Value float64 `json:"value,omitempty" cdx:"+1.6"` // v1.6 + Unit string `json:"unit,omitempty" cdx:"+1.6"` // v1.6 +} + +// v1.6: added +type CDXEnergyProvider struct { + BOMRef *CDXRefType `json:"bom-ref,omitempty" cdx:"+1.6"` // v1.6 + Description string `json:"description,omitempty" cdx:"+1.6"` // v1.6 + Organization *CDXOrganizationalEntity `json:"organization,omitempty" cdx:"+1.6"` // v1.6 + EnergySource string `json:"energySource,omitempty" cdx:"+1.6"` // v1.6 + EnergyProvided *CDXEnergyMeasure `json:"energyProvided,omitempty" cdx:"+1.6"` // v1.6 + ExternalReferences *[]CDXExternalReference `json:"externalReferences,omitempty" cdx:"+1.6"` // v1.6 +} + +// v1.6: added +type CDXPostalAddress struct { + BOMRef *CDXRefType `json:"bom-ref,omitempty" cdx:"+1.6"` // v1.6 + Country string `json:"country,omitempty" cdx:"+1.6"` // v1.6 + Region string `json:"region,omitempty" cdx:"+1.6"` // v1.6 + Locality string `json:"locality,omitempty" cdx:"+1.6"` // v1.6 + PostOfficeBoxNumber string `json:"postOfficeBoxNumber,omitempty" cdx:"+1.6"` // v1.6 + PostalCode string `json:"postalCode,omitempty" cdx:"+1.6"` // v1.6 + StreetAddress string `json:"streetAddress,omitempty" cdx:"+1.6"` // v1.6 }