Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datatypes for new v1.6 EnvironmentalConsiderations to ModelCard data #88

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"prettyjson",
"PROPKEY",
"protonmail",
"pypi",
"repackager",
"rvoi",
"rwxr",
Expand Down
11 changes: 5 additions & 6 deletions schema/bom_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
129 changes: 90 additions & 39 deletions schema/cyclonedx_modelcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

// ========================================
Expand All @@ -38,35 +38,35 @@ 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.
// v1.5: Note: "ref" is a constrained "string" which can be "anyOf": ["#/definitions/refLinkType", "#/definitions/bomLinkElementType"]
// 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
}

// ========================================
Expand All @@ -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
}

// ========================================
Expand All @@ -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
}
Loading