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

fixed broken concepts for datasets and models #2964

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const conceptSearchTerm = ref({
name: ''
});
const curies = ref<DKG[]>([]);

const nameOfCurieCache = ref(new Map<string, string>());

const formattedData = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@

<script setup lang="ts">
import type { DKG, Model, ModelConfiguration } from '@/types/Types';
import { cloneDeep, groupBy, isEmpty, round } from 'lodash';
import { cloneDeep, groupBy, isEmpty } from 'lodash';
import Accordion from 'primevue/accordion';
import AccordionTab from 'primevue/accordiontab';
import { computed, ref } from 'vue';
Expand All @@ -225,10 +225,10 @@ import {
} from '@/model-representation/petrinet/petrinet-service';
import { logger } from '@/utils/logger';
import {
searchCuriesEntities,
getNameOfCurieCached,
getCurieFromGroudingIdentifier,
getCurieUrl,
getNameOfCurieCached,
searchCuriesEntities,
parseCurie
} from '@/services/concept';
import DataTable from 'primevue/datatable';
Expand All @@ -253,13 +253,13 @@ interface ModelTableTypes {

const isRowEditable = ref<string | null>();
const transientTableValue = ref<ModelTableTypes | null>(null);
const nameOfCurieCache = ref(new Map<string, string>());

const curies = ref<DKG[]>([]);
const conceptSearchTerm = ref({
curie: '',
name: ''
});
const curies = ref<DKG[]>([]);
const nameOfCurieCache = ref(new Map<string, string>());

const parameters = computed(() => props.model?.semantics?.ode.parameters ?? []);
const observables = computed(() => props.model?.semantics?.ode?.observables ?? []);
Expand Down
4 changes: 2 additions & 2 deletions packages/client/hmi-client/src/services/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function getFacets(type: AssetType, curies?: ClauseValue[]): Promise<Conce
*/
async function getCuriesEntities(curies: Array<string>): Promise<Array<DKG> | null> {
try {
const response = await API.get(`/mira/${curies.toString()}`);
const response = await API.get(`/mira/currie/${curies.toString()}`);
if (response?.status !== 200) return null;
return response?.data ?? null;
} catch (error) {
Expand Down Expand Up @@ -111,7 +111,7 @@ async function getEntitySimilarity(
targets: string[]
): Promise<Array<EntitySimilarityResult> | null> {
try {
const response = await API.post('/mira/entity_similarity', { sources, targets } as Curies);
const response = await API.post('/mira/entity-similarity', { sources, targets } as Curies);
if (response?.status !== 200) return null;
return response?.data ?? null;
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/client/hmi-client/src/services/goLLM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function modelCard(documentId: string): Promise<void> {
await handleTaskById(taskId, {
ondata(data, closeConnection) {
if (data?.status === TaskStatus.Failed) {
closeConnection();
throw new FatalError('Task failed');
}
if (data.status === TaskStatus.Success) {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/hmi-client/src/services/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function getModelConfigurations(modelId: Model['id']): Promise<Mode
* @deprecated moving to mira-stratify
*/
export async function reconstructAMR(amr: any) {
const response = await API.post('/mira/reconstruct_ode_semantics', amr);
const response = await API.post('/mira/reconstruct-ode-semantics', amr);
return response?.data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@

<script setup lang="ts">
import { cloneDeep, isEmpty } from 'lodash';
import { computed, ref, watch, onUnmounted, onMounted } from 'vue';
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import Button from 'primevue/button';
import InputText from 'primevue/inputtext';
import Textarea from 'primevue/textarea';
Expand All @@ -256,7 +256,8 @@ import TeraDrilldown from '@/components/drilldown/tera-drilldown.vue';
import TeraDrilldownSection from '@/components/drilldown/tera-drilldown-section.vue';
import { getModel, getModelConfigurations, getModelType } from '@/services/model';
import { createModelConfiguration } from '@/services/model-configurations';
import type { Model, ModelConfiguration, Initial, ModelParameter } from '@/types/Types';
import type { Initial, Model, ModelConfiguration, ModelParameter } from '@/types/Types';
import { TaskStatus } from '@/types/Types';
import { AMRSchemaNames, ModelConfigTableData, ParamType } from '@/types/common';
import { getStratificationType } from '@/model-representation/petrinet/petrinet-service';
import {
Expand All @@ -281,7 +282,6 @@ import '@/ace-config';
import LoadingWateringCan from '@/assets/images/lottie-loading-wateringCan.json';
import { Vue3Lottie } from 'vue3-lottie';
import TeraModelSemanticTables from '@/components/model/petrinet/tera-model-semantic-tables.vue';
import { TaskStatus } from '@/types/Types';
import { FatalError } from '@/api/api';
import { formatTimestamp } from '@/utils/date';
import TeraOperatorAnnotation from '@/components/operator/tera-operator-annotation.vue';
Expand Down Expand Up @@ -431,6 +431,7 @@ const extractConfigurationsFromInputs = async () => {
{
ondata(data, closeConnection) {
if (data?.status === TaskStatus.Failed) {
closeConnection();
throw new FatalError('Configs from document - Task failed');
}
if (data.status === TaskStatus.Success) {
Expand All @@ -453,6 +454,7 @@ const extractConfigurationsFromInputs = async () => {
{
ondata(data, closeConnection) {
if (data?.status === TaskStatus.Failed) {
closeConnection();
throw new FatalError('Configs from datasets - Task failed');
}
if (data.status === TaskStatus.Success) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
package software.uncharted.terarium.hmiserver.controller.mira;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import feign.FeignException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -26,19 +11,33 @@
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import software.uncharted.terarium.hmiserver.annotations.IgnoreRequestLogging;
import software.uncharted.terarium.hmiserver.models.dataservice.Artifact;
import software.uncharted.terarium.hmiserver.models.dataservice.model.Model;
import software.uncharted.terarium.hmiserver.models.mira.Curies;
import software.uncharted.terarium.hmiserver.models.mira.DKG;
import software.uncharted.terarium.hmiserver.models.mira.EntitySimilarityResult;
import software.uncharted.terarium.hmiserver.models.task.TaskRequest;
import software.uncharted.terarium.hmiserver.models.task.TaskRequest.TaskType;
import software.uncharted.terarium.hmiserver.models.task.TaskResponse;
import software.uncharted.terarium.hmiserver.proxies.mira.MIRAProxy;
import software.uncharted.terarium.hmiserver.security.Roles;
import software.uncharted.terarium.hmiserver.service.data.ArtifactService;
import software.uncharted.terarium.hmiserver.service.tasks.MdlToStockflowResponseHandler;
import software.uncharted.terarium.hmiserver.service.tasks.SbmlToPetrinetResponseHandler;
import software.uncharted.terarium.hmiserver.service.tasks.StellaToStockflowResponseHandler;
import software.uncharted.terarium.hmiserver.service.tasks.TaskService;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@RequestMapping("/mira")
@RestController
@Slf4j
Expand All @@ -49,6 +48,9 @@ public class MiraController {
final private ArtifactService artifactService;
final private TaskService taskService;

@Autowired
MIRAProxy proxy;

@Data
static public class ModelConversionRequest {
public UUID artifactId;
Expand All @@ -59,7 +61,7 @@ static public class ModelConversionResponse {
public Model response;
}

private boolean endsWith(final String filename, final List<String> suffixes) {
private static boolean endsWith(final String filename, final List<String> suffixes) {
for (final String suffix : suffixes) {
if (filename.endsWith(suffix)) {
return true;
Expand Down Expand Up @@ -164,4 +166,63 @@ public ResponseEntity<Void> cancelTask(@PathVariable("task-id") final UUID taskI
public SseEmitter subscribe(@PathVariable("task-id") final UUID taskId) {
return taskService.subscribe(taskId);
}

@GetMapping("/currie/{curies}")
@Secured(Roles.USER)
public ResponseEntity<List<DKG>> searchConcept(
@PathVariable("curies") final String curies) {
try {
final ResponseEntity<List<DKG>> response = proxy.getEntities(curies);
if (response.getStatusCode().is2xxSuccessful()) {
return ResponseEntity.ok(response.getBody());
}
return ResponseEntity.internalServerError().build();
} catch (final FeignException.NotFound e) { // Handle 404 errors
log.info("Could not find resource in the DKG", e);
return ResponseEntity.notFound().build();
} catch (final Exception e) {
log.error("Unable to fetch DKG", e);
return ResponseEntity.internalServerError().build();
}
}

@GetMapping("/search")
@Secured(Roles.USER)
public ResponseEntity<List<DKG>> search(
@RequestParam("q") final String q,
@RequestParam(required = false, name = "limit", defaultValue = "10") final Integer limit,
@RequestParam(required = false, name = "offset", defaultValue = "0") final Integer offset) {
try {
final ResponseEntity<List<DKG>> response = proxy.search(q, limit, offset);
if (response.getStatusCode().is2xxSuccessful()) {
return ResponseEntity.ok(response.getBody());
}
return ResponseEntity.internalServerError().build();
} catch (final FeignException.NotFound e) { // Handle 404 errors
log.info("Could not find resource in the DKG", e);
return ResponseEntity.notFound().build();
} catch (final Exception e) {
log.error("Unable to fetch DKG", e);
return ResponseEntity.internalServerError().build();
}
}

// This rebuilds the semantics ODE via MIRA
// 1. Send AMR to MIRA => MIRANet
// 2. Send MIRANet to MIRA to convert back to AMR Petrinet
// 3. Send AMR back
@PostMapping("/reconstruct-ode-semantics")
@Secured(Roles.USER)
public ResponseEntity<JsonNode> reconstructODESemantics(
final Object amr) {
return ResponseEntity.ok(proxy.reconstructODESemantics(amr).getBody());

}

@PostMapping("/entity-similarity")
@Secured(Roles.USER)
public ResponseEntity<List<EntitySimilarityResult>> entitySimilarity(
@RequestBody final Curies obj) {
return ResponseEntity.ok(proxy.entitySimilarity(obj).getBody());
}
}

This file was deleted.

Loading