Skip to content

Commit

Permalink
fix POST /model-configuration endpoint logic (#4350)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwdchang authored Aug 2, 2024
1 parent d641945 commit 6f135e9
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ import {
SimulationRequest,
Model,
ModelConfiguration,
ParameterSemantic,
SemanticType
SemanticType,
InferredParameterSemantic
} from '@/types/Types';
import { createLLMSummary } from '@/services/summary-service';
import { createForecastChart } from '@/services/charts';
Expand Down Expand Up @@ -371,14 +371,14 @@ watch(
}
});
const inferredParameters: ParameterSemantic[] = [];
const inferredParameters: InferredParameterSemantic[] = [];
Object.keys(parameterTable).forEach((parameterId) => {
const mean = stats.mean(parameterTable[parameterId]);
const stddev = stats.stddev(parameterTable[parameterId]);
inferredParameters.push({
source: 'calibration',
type: SemanticType.Parameter,
type: SemanticType.Inferred,
referenceId: parameterId,
default: false,
distribution: {
Expand Down
9 changes: 8 additions & 1 deletion packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ export interface ModelFramework extends TerariumAssetThatSupportsAdditionalPrope
semantics: string;
}

export interface InferredParameterSemantic extends Semantic {
referenceId: string;
distribution: ModelDistribution;
default: boolean;
}

export interface InitialSemantic extends Semantic {
target: string;
expression: string;
Expand All @@ -229,7 +235,7 @@ export interface ModelConfiguration extends TerariumAsset {
observableSemanticList: ObservableSemantic[];
parameterSemanticList: ParameterSemantic[];
initialSemanticList: InitialSemantic[];
inferredParameterList?: ParameterSemantic[];
inferredParameterList?: InferredParameterSemantic[];
}

export interface ObservableSemantic extends Semantic {
Expand Down Expand Up @@ -1232,6 +1238,7 @@ export enum SemanticType {
Initial = "initial",
Parameter = "parameter",
Observable = "observable",
Inferred = "inferredParameter",
}

export enum ProvenanceRelationType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,12 @@ public ResponseEntity<ModelConfiguration> createModelConfiguration(
projectService.checkPermissionCanWrite(currentUserService.get().getId(), projectId);

try {
if (modelConfiguration.getId() == null) {
modelConfiguration.setId(UUID.randomUUID());
}

return ResponseEntity.status(HttpStatus.CREATED).body(
modelConfigurationService.createAsset(modelConfiguration.clone(), projectId, permission)
modelConfigurationService.createAsset(modelConfiguration, projectId, permission)
);
} catch (final IOException e) {
log.error("Unable to get model configuration from postgres db", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package software.uncharted.terarium.hmiserver.models.dataservice.model.configurations;

import com.fasterxml.jackson.annotation.JsonBackReference;
import io.hypersistence.utils.hibernate.type.json.JsonType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Type;
import software.uncharted.terarium.hmiserver.annotations.TSIgnore;
import software.uncharted.terarium.hmiserver.annotations.TSModel;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelDistribution;

@EqualsAndHashCode(callSuper = true)
@Data
@TSModel
@Accessors
@Entity
public class InferredParameterSemantic extends Semantic {

private String referenceId;

@Type(JsonType.class)
@Column(columnDefinition = "json")
private ModelDistribution distribution;

private boolean isDefault;

@ManyToOne
@JsonBackReference
@Schema(hidden = true)
@TSIgnore
@NotNull
private ModelConfiguration modelConfiguration;

@Override
public InferredParameterSemantic clone() {
final InferredParameterSemantic clone = new InferredParameterSemantic();
super.cloneSuperFields(clone);
clone.referenceId = this.referenceId;
clone.distribution = this.distribution.clone();
clone.isDefault = this.isDefault;
return clone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ public class ModelConfiguration extends TerariumAsset {
@TSOptional
@OneToMany(mappedBy = "modelConfiguration", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JsonManagedReference
private List<ParameterSemantic> inferredParameterList = new ArrayList<>();
private List<InferredParameterSemantic> inferredParameterList = new ArrayList<>();

@Override
public ModelConfiguration clone() {
final ModelConfiguration clone = new ModelConfiguration();
super.cloneSuperFields(clone);

clone.setModelId(this.modelId);
clone.setSimulationId(this.simulationId);

if (this.observableSemanticList != null) {
clone.setObservableSemanticList(new ArrayList<>());
Expand All @@ -83,7 +84,7 @@ public ModelConfiguration clone() {

if (this.inferredParameterList != null) {
clone.setInferredParameterList(new ArrayList<>());
for (final ParameterSemantic semantic : inferredParameterList) {
for (final InferredParameterSemantic semantic : inferredParameterList) {
clone.getInferredParameterList().add(semantic.clone());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ public enum SemanticType {
PARAMETER,

@JsonProperty("observable")
OBSERVABLE
OBSERVABLE,

@JsonProperty("inferredParameter")
INFERRED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN;

ALTER TABLE model_configuration DROP COLUMN IF EXISTS calibration_run_id;
ALTER TABLE semantic DROP CONSTRAINT semantic_type_check;
ALTER TABLE semantic ADD CONSTRAINT semantic_type_check CHECK (type >= 0 AND type <= 3);

COMMIT;

0 comments on commit 6f135e9

Please sign in to comment.