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

Trivial migrations in the frontend and core #391

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions packages/catlog/src/dbl/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ where
self.category.generators()
}

/// Migrate model along an inclusion (pushforward)
pub fn trivial_migrate(
&self,
supertheory: Arc<DiscreteDblTheory<Cat>>,
) -> DiscreteDblModel<Id, Cat> {
DiscreteDblModel {
theory: supertheory,
category: self.category.clone(),
ob_types: self.ob_types.clone(),
mor_types: self.mor_types.clone(),
}

// self.category, self.ob_types, self.mor_types
}

/// Is the model freely generated?
pub fn is_free(&self) -> bool {
self.category.is_free()
Expand Down Expand Up @@ -970,4 +985,14 @@ mod tests {
model.add_mor(f, TabOb::Basic(x), TabOb::Basic(x), TabMorType::Basic(ustr("Link")));
assert_eq!(model.validate(), Err(nonempty![InvalidDblModel::CodType(f)]));
}

#[test]
fn trivially_migrate_dbl_model() {
let th = Arc::new(th_signed_category());
let th2 = Arc::new(th_nullable_signed_category());
let loop1 = positive_loop(th.clone());
let loop2 = positive_loop(th2.clone());
assert_ne!(loop1, loop2);
assert_eq!(loop1.trivial_migrate(th2), loop2);
}
}
9 changes: 7 additions & 2 deletions packages/frontend/src/model/model_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
newFormalCell,
} from "../notebook";
import { TheoryHelpButton, Toolbar } from "../page";
import { TheoryLibraryContext } from "../stdlib";
import { TheoryLibraryContext, allTheories } from "../stdlib";
import type { ModelTypeMeta } from "../theory";
import { MaybePermissionsButton } from "../user";
import { LiveModelContext } from "./context";
Expand Down Expand Up @@ -77,6 +77,7 @@ export function ModelPane(props: {
invariant(theories, "Library of theories should be provided as context");

const liveDoc = () => props.liveModel.liveDoc;
const hasformal = () => liveDoc().doc.notebook.cells.some((cell) => cell.tag === "formal");

return (
<div class="notebook-container">
Expand All @@ -100,7 +101,11 @@ export function ModelPane(props: {
});
}}
theories={theories}
disabled={liveDoc().doc.notebook.cells.some((cell) => cell.tag === "formal")}
filtered={hasformal() ? props.liveModel.theory().inclusions : allTheories}
disabled={
hasformal() ? props.liveModel.theory().inclusions === undefined : false
}
//}
/>
</div>
<ModelNotebookEditor liveModel={props.liveModel} />
Expand Down
7 changes: 6 additions & 1 deletion packages/frontend/src/model/theory_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ type TheorySelectorProps = {
theory: TheoryMeta;
setTheory: (theoryId: string) => void;
theories: TheoryLibrary;
filtered: Array<string>;
};

export function TheorySelectorDialog(
props: {
disabled?: boolean;
filtered: Array<string>;
} & TheorySelectorProps,
) {
const [theorySelectorOpen, setTheorySelectorOpen] = createSignal(false);
Expand All @@ -37,6 +39,7 @@ export function TheorySelectorDialog(
setTheorySelectorOpen(false);
}}
theories={props.theories}
filtered={props.filtered}
/>
</Dialog.Content>
</Dialog.Portal>
Expand All @@ -55,7 +58,9 @@ export function TheorySelector(props: TheorySelectorProps) {
{([group, theories]) => (
<div class="group">
<div class="group-name">{group}</div>
<For each={theories}>
<For
each={theories.filter((t: TheoryMeta) => props.filtered.includes(t.id))}
>
{(meta) => (
<div class="theory">
<input
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/stdlib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ at present this is the complete set of logics available in the application.

export * from "./types";
export * from "./context";
export { stdTheories } from "./theories";
export { stdTheories, allTheories } from "./theories";
15 changes: 15 additions & 0 deletions packages/frontend/src/stdlib/theories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ import textStyles from "./text_styles.module.css";
/** Standard library of double theories supported by the frontend. */
export const stdTheories = new TheoryLibrary();

export const allTheories = [
"empty",
"simple-olog",
"simple-schema",
"reg-net",
"causal-loop",
"causal-loop-delays",
"indeterminate-causal-loop",
"unary-dec",
"primitive-stock-flow",
];

stdTheories.add(
{
id: "empty",
Expand All @@ -25,6 +37,7 @@ stdTheories.add(
return new Theory({
...meta,
theory: thEmpty.theory(),
inclusions: allTheories,
});
},
);
Expand Down Expand Up @@ -225,6 +238,7 @@ stdTheories.add(
...meta,
theory: thSignedCategory.theory(),
onlyFreeModels: true,
inclusions: ["causal-loop", "causal-loop-delays", "indeterminate-causal-loop"],
modelTypes: [
{
tag: "ObType",
Expand Down Expand Up @@ -297,6 +311,7 @@ stdTheories.add(
...meta,
theory: thSignedCategory.theory(),
onlyFreeModels: true,
inclusions: ["reg-net", "causal-loop-delays", "indeterminate-causal-loop"],
modelTypes: [
{
tag: "ObType",
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/theory/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class Theory {
*/
readonly instanceOfName: string;

/** Privileged migrations along inclusions which need no explicit functor **/
readonly inclusions: Array<string>;

private readonly modelTypeMeta: TypeMetadata<ModelObTypeMeta, ModelMorTypeMeta>;
private readonly instanceTypeMeta: TypeMetadata<InstanceObTypeMeta, InstanceMorTypeMeta>;

Expand All @@ -62,6 +65,7 @@ export class Theory {
modelAnalyses?: ModelAnalysisMeta[];
onlyFreeModels?: boolean;
instanceOfName?: string;
inclusions?: string[];
instanceTypes?: InstanceTypeMeta[];
diagramAnalyses?: DiagramAnalysisMeta[];
}) {
Expand All @@ -76,6 +80,7 @@ export class Theory {
this.modelTypeMeta = new TypeMetadata<ModelObTypeMeta, ModelMorTypeMeta>(props.modelTypes);
this.modelAnalysisMap = uniqueIndexArray(props.modelAnalyses ?? [], (meta) => meta.id);
this.onlyFreeModels = props.onlyFreeModels ?? false;
this.inclusions = props.inclusions ?? [];

// Instances.
this.instanceOfName = props.instanceOfName ?? "Instance of";
Expand Down