Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/funky-deserts-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hashintel/petrinaut": patch
---

Add support for inhibitor arcs
12 changes: 8 additions & 4 deletions libs/@hashintel/petrinaut/src/clipboard/paste.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ describe("paste — arc remapping", () => {
{
id: "transition__old-t1",
name: "T1",
inputArcs: [{ placeId: "place__old-p1", weight: 3 }],
inputArcs: [
{ placeId: "place__old-p1", weight: 3, type: "standard" },
],
outputArcs: [{ placeId: "place__old-p1", weight: 1 }],
lambdaType: "predicate",
lambdaCode: "",
Expand Down Expand Up @@ -449,7 +451,9 @@ describe("paste — arc remapping", () => {
{
id: "transition__old",
name: "T1",
inputArcs: [{ placeId: "place__missing", weight: 1 }],
inputArcs: [
{ placeId: "place__missing", weight: 1, type: "standard" },
],
outputArcs: [{ placeId: "place__missing", weight: 1 }],
lambdaType: "predicate",
lambdaCode: "",
Expand Down Expand Up @@ -485,8 +489,8 @@ describe("paste — arc remapping", () => {
id: "transition__t1",
name: "T1",
inputArcs: [
{ placeId: "place__included", weight: 1 },
{ placeId: "place__excluded", weight: 2 },
{ placeId: "place__included", weight: 1, type: "standard" },
{ placeId: "place__excluded", weight: 2, type: "standard" },
],
outputArcs: [{ placeId: "place__excluded", weight: 1 }],
lambdaType: "predicate",
Expand Down
4 changes: 2 additions & 2 deletions libs/@hashintel/petrinaut/src/clipboard/serialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const fullNet: SDCPN = {
{
id: "t1",
name: "Transition1",
inputArcs: [{ placeId: "p1", weight: 1 }],
inputArcs: [{ placeId: "p1", weight: 1, type: "standard" }],
outputArcs: [{ placeId: "p2", weight: 2 }],
lambdaType: "predicate",
lambdaCode: "return true;",
Expand Down Expand Up @@ -466,7 +466,7 @@ describe("parseClipboardPayload", () => {
{
id: "t1",
name: "T",
inputArcs: [{ placeId: "p1", weight: "heavy" }],
inputArcs: [{ placeId: "p1", weight: "heavy", type: "standard" }],
outputArcs: [],
lambdaType: "predicate",
lambdaCode: "",
Expand Down
12 changes: 9 additions & 3 deletions libs/@hashintel/petrinaut/src/clipboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { z } from "zod";

export const CLIPBOARD_FORMAT_VERSION = 1;

const arcSchema = z.object({
const inputArcSchema = z.object({
placeId: z.string(),
weight: z.number(),
type: z.enum(["standard", "inhibitor"]).optional().default("standard"),
});

const outputArcSchema = z.object({
placeId: z.string(),
weight: z.number(),
});
Expand All @@ -21,8 +27,8 @@ const placeSchema = z.object({
const transitionSchema = z.object({
id: z.string(),
name: z.string(),
inputArcs: z.array(arcSchema),
outputArcs: z.array(arcSchema),
inputArcs: z.array(inputArcSchema),
outputArcs: z.array(outputArcSchema),
lambdaType: z.enum(["predicate", "stochastic"]),
lambdaCode: z.string(),
transitionKernelCode: z.string(),
Expand Down
15 changes: 13 additions & 2 deletions libs/@hashintel/petrinaut/src/core/types/sdcpn.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
export type ID = string;

export type InputArc = {
placeId: string;
weight: number;
type: "standard" | "inhibitor";
Comment thread
alex-e-leon marked this conversation as resolved.
};

export type OutputArc = {
placeId: string;
weight: number;
};

export type Transition = {
id: ID;
name: string;
inputArcs: { placeId: string; weight: number }[];
outputArcs: { placeId: string; weight: number }[];
inputArcs: InputArc[];
outputArcs: OutputArc[];
lambdaType: "predicate" | "stochastic";
lambdaCode: string;
transitionKernelCode: string;
Expand Down
9 changes: 9 additions & 0 deletions libs/@hashintel/petrinaut/src/examples/broken-machines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const productionMachines: { title: string; petriNetDefinition: SDCPN } =
{
placeId: "place__81e551b4-11dc-4781-9cd7-dd882fd7e947",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand Down Expand Up @@ -132,6 +133,7 @@ export const productionMachines: { title: string; petriNetDefinition: SDCPN } =
{
placeId: "place__81e551b4-11dc-4781-9cd7-dd882fd7e947",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand Down Expand Up @@ -159,10 +161,12 @@ export const productionMachines: { title: string; petriNetDefinition: SDCPN } =
{
placeId: "place__d662407f-c56d-4a96-bcbb-ead785a9c594",
weight: 1,
type: "standard",
},
{
placeId: "place__2bdd959f-a5bc-404a-bd03-34fafcef66b8",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand All @@ -185,6 +189,7 @@ export const productionMachines: { title: string; petriNetDefinition: SDCPN } =
{
placeId: "place__17c65d6e-0c3e-48e6-a677-2914e28131ac",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand All @@ -208,6 +213,7 @@ export const productionMachines: { title: string; petriNetDefinition: SDCPN } =
{
placeId: "place__e5af0410-d80a-4c8b-b3bf-692918b98e6c",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand All @@ -234,6 +240,7 @@ export const productionMachines: { title: string; petriNetDefinition: SDCPN } =
{
placeId: "place__4b72cf19-907b-4fc0-ac0a-555453e95d4b",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand All @@ -257,10 +264,12 @@ export const productionMachines: { title: string; petriNetDefinition: SDCPN } =
{
placeId: "place__eaca89b8-1db1-45fa-8c3a-6eb6f0419ffa",
weight: 1,
type: "standard",
},
{
placeId: "place__9cb073fb-f1d7-4613-8b10-8d1b08796f24",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand Down
178 changes: 178 additions & 0 deletions libs/@hashintel/petrinaut/src/examples/deployment-pipeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import { SNAP_GRID_SIZE } from "../constants/ui";
import type { SDCPN } from "../core/types/sdcpn";

export const deploymentPipelineSDCPN: {
title: string;
petriNetDefinition: SDCPN;
} = {
title: "Deployment Pipeline",
petriNetDefinition: {
places: [
{
id: "place__deployment-ready",
name: "DeploymentReady",
colorId: null,
dynamicsEnabled: false,
differentialEquationId: null,
x: -8 * SNAP_GRID_SIZE,
y: -10 * SNAP_GRID_SIZE,
},
{
id: "place__incident-being-investigated",
name: "IncidentBeingInvestigated",
colorId: null,
dynamicsEnabled: false,
differentialEquationId: null,
x: -8 * SNAP_GRID_SIZE,
y: 10 * SNAP_GRID_SIZE,
},
{
id: "place__deployment-in-progress",
name: "DeploymentInProgress",
colorId: null,
dynamicsEnabled: false,
differentialEquationId: null,
x: 25 * SNAP_GRID_SIZE,
y: -10 * SNAP_GRID_SIZE,
},
{
id: "place__completed-deployments",
name: "CompletedDeployments",
colorId: null,
dynamicsEnabled: false,
differentialEquationId: null,
x: 55 * SNAP_GRID_SIZE,
y: -10 * SNAP_GRID_SIZE,
},
{
id: "place__resolved-incidents",
name: "ResolvedIncidents",
colorId: null,
dynamicsEnabled: false,
differentialEquationId: null,
x: 25 * SNAP_GRID_SIZE,
y: 20 * SNAP_GRID_SIZE,
},
],
transitions: [
{
id: "transition__create-deployment",
name: "Create Deployment",
inputArcs: [],
outputArcs: [{ placeId: "place__deployment-ready", weight: 1 }],
lambdaType: "stochastic",
lambdaCode:
"export default Lambda((tokens, parameters) => parameters.deployment_creation_rate)",
transitionKernelCode:
"export default TransitionKernel(() => {\n return {\n DeploymentReady: [{}],\n };\n});",
x: -30 * SNAP_GRID_SIZE,
y: -10 * SNAP_GRID_SIZE,
},
{
id: "transition__incident-raised",
name: "Incident Raised",
inputArcs: [],
outputArcs: [
{ placeId: "place__incident-being-investigated", weight: 1 },
],
lambdaType: "stochastic",
lambdaCode:
"export default Lambda((tokens, parameters) => parameters.incident_rate)",
transitionKernelCode:
"export default TransitionKernel(() => {\n return {\n IncidentBeingInvestigated: [{}],\n };\n});",
x: -30 * SNAP_GRID_SIZE,
y: 10 * SNAP_GRID_SIZE,
},
{
id: "transition__start-deployment",
name: "Start Deployment",
inputArcs: [
{
placeId: "place__deployment-ready",
weight: 1,
type: "standard",
},
{
placeId: "place__incident-being-investigated",
weight: 1,
type: "inhibitor",
},
{
placeId: "place__deployment-in-progress",
weight: 1,
type: "inhibitor",
},
],
outputArcs: [{ placeId: "place__deployment-in-progress", weight: 1 }],
lambdaType: "predicate",
lambdaCode: "export default Lambda(() => true)",
transitionKernelCode:
"export default TransitionKernel(() => {\n return {\n DeploymentInProgress: [{}],\n };\n});",
x: 8 * SNAP_GRID_SIZE,
y: -10 * SNAP_GRID_SIZE,
},
{
id: "transition__finish-deployment",
name: "Finish Deployment",
inputArcs: [
{
placeId: "place__deployment-in-progress",
weight: 1,
type: "standard",
},
],
outputArcs: [{ placeId: "place__completed-deployments", weight: 1 }],
lambdaType: "predicate",
lambdaCode: "export default Lambda(() => true)",
transitionKernelCode:
"export default TransitionKernel(() => {\n return {\n CompletedDeployments: [{}],\n };\n});",
x: 40 * SNAP_GRID_SIZE,
y: -10 * SNAP_GRID_SIZE,
},
{
id: "transition__close-incident",
name: "Close Incident",
inputArcs: [
{
placeId: "place__incident-being-investigated",
weight: 1,
type: "standard",
},
],
outputArcs: [{ placeId: "place__resolved-incidents", weight: 1 }],
lambdaType: "stochastic",
lambdaCode:
"export default Lambda((tokens, parameters) => parameters.incident_resolution_rate)",
transitionKernelCode:
"export default TransitionKernel(() => {\n return {\n ResolvedIncidents: [{}],\n };\n});",
x: 8 * SNAP_GRID_SIZE,
y: 10 * SNAP_GRID_SIZE,
},
],
types: [],
differentialEquations: [],
parameters: [
{
id: "param__deployment_creation_rate",
name: "Deployment Creation Rate",
variableName: "deployment_creation_rate",
type: "real",
defaultValue: "0.5",
},
{
id: "param__incident_rate",
name: "Incident Rate",
variableName: "incident_rate",
type: "real",
defaultValue: "0.1",
},
{
id: "param__incident_resolution_rate",
name: "Incident Resolution Rate",
variableName: "incident_resolution_rate",
type: "real",
defaultValue: "0.3",
},
],
},
};
2 changes: 2 additions & 0 deletions libs/@hashintel/petrinaut/src/examples/satellites-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const probabilisticSatellitesSDCPN: {
{
placeId: "3cbc7944-34cb-4eeb-b779-4e392a171fe1",
weight: 2,
type: "standard",
},
],
outputArcs: [
Expand Down Expand Up @@ -172,6 +173,7 @@ export default TransitionKernel((tokens) => {
{
placeId: "3cbc7944-34cb-4eeb-b779-4e392a171fe1",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand Down
2 changes: 2 additions & 0 deletions libs/@hashintel/petrinaut/src/examples/satellites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const satellitesSDCPN: { title: string; petriNetDefinition: SDCPN } = {
{
placeId: "3cbc7944-34cb-4eeb-b779-4e392a171fe1",
weight: 2,
type: "standard",
},
],
outputArcs: [
Expand Down Expand Up @@ -169,6 +170,7 @@ export default TransitionKernel((tokens) => {
{
placeId: "3cbc7944-34cb-4eeb-b779-4e392a171fe1",
weight: 1,
type: "standard",
},
],
outputArcs: [
Expand Down
Loading
Loading