@tscircuit/core 0.0.1443 → 0.0.1444
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +131 -68
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -153063,6 +153063,7 @@ declare class SymbolComponent extends PrimitiveComponent<typeof symbolProps> imp
|
|
|
153063
153063
|
}
|
|
153064
153064
|
|
|
153065
153065
|
declare class AnalogSimulation extends PrimitiveComponent<typeof analogSimulationProps> {
|
|
153066
|
+
simulation_experiment_id: string | null;
|
|
153066
153067
|
get config(): {
|
|
153067
153068
|
componentName: string;
|
|
153068
153069
|
zodProps: zod.ZodObject<{
|
package/dist/index.js
CHANGED
|
@@ -22144,82 +22144,149 @@ var isVoltageGraph = (element) => element.type === "simulation_transient_voltage
|
|
|
22144
22144
|
|
|
22145
22145
|
// lib/components/primitive-components/Group/Group_doInitialSimulationSpiceEngineRender.ts
|
|
22146
22146
|
var debug11 = Debug13("tscircuit:core:Group_doInitialSimulationSpiceEngineRender");
|
|
22147
|
+
var getCircuitJsonForAnalogSimulation = ({
|
|
22148
|
+
circuitJson,
|
|
22149
|
+
simulationExperimentId,
|
|
22150
|
+
voltageProbes,
|
|
22151
|
+
ammeters
|
|
22152
|
+
}) => {
|
|
22153
|
+
const voltageProbeIds = new Set(
|
|
22154
|
+
voltageProbes.map((probe) => probe.simulation_voltage_probe_id).filter((id) => Boolean(id))
|
|
22155
|
+
);
|
|
22156
|
+
const currentProbeIds = new Set(
|
|
22157
|
+
ammeters.map((ammeter) => ammeter.simulation_current_probe_id).filter((id) => Boolean(id))
|
|
22158
|
+
);
|
|
22159
|
+
return circuitJson.filter((element) => {
|
|
22160
|
+
if (element.type === "simulation_experiment") {
|
|
22161
|
+
return element.simulation_experiment_id === simulationExperimentId;
|
|
22162
|
+
}
|
|
22163
|
+
if (element.type === "simulation_voltage_probe") {
|
|
22164
|
+
return voltageProbeIds.has(element.simulation_voltage_probe_id);
|
|
22165
|
+
}
|
|
22166
|
+
if (element.type === "simulation_current_probe") {
|
|
22167
|
+
return currentProbeIds.has(element.simulation_current_probe_id);
|
|
22168
|
+
}
|
|
22169
|
+
if (element.type === "simulation_oscilloscope_trace") {
|
|
22170
|
+
if (element.simulation_voltage_probe_id) {
|
|
22171
|
+
return voltageProbeIds.has(element.simulation_voltage_probe_id);
|
|
22172
|
+
}
|
|
22173
|
+
if (element.simulation_current_probe_id) {
|
|
22174
|
+
return currentProbeIds.has(element.simulation_current_probe_id);
|
|
22175
|
+
}
|
|
22176
|
+
}
|
|
22177
|
+
if (element.type === "simulation_transient_voltage_graph" || element.type === "simulation_transient_current_graph" || element.type === "simulation_unknown_experiment_error") {
|
|
22178
|
+
return false;
|
|
22179
|
+
}
|
|
22180
|
+
return true;
|
|
22181
|
+
});
|
|
22182
|
+
};
|
|
22147
22183
|
function Group_doInitialSimulationSpiceEngineRender(group) {
|
|
22148
22184
|
if (!group.isSubcircuit) return;
|
|
22149
22185
|
const { root } = group;
|
|
22150
22186
|
if (!root) return;
|
|
22151
22187
|
const analogSims = group.selectAll("analogsimulation");
|
|
22152
22188
|
if (analogSims.length === 0) return;
|
|
22153
|
-
const voltageProbes = group.selectAll("voltageprobe");
|
|
22154
|
-
const ammeters = group.selectAll("ammeter");
|
|
22155
22189
|
resetSimulationColorState();
|
|
22156
22190
|
const spiceEngineMap = { ...root.platform?.spiceEngineMap };
|
|
22157
22191
|
if (!spiceEngineMap.spicey) {
|
|
22158
22192
|
spiceEngineMap.spicey = getSpiceyEngine();
|
|
22159
22193
|
}
|
|
22160
|
-
const
|
|
22161
|
-
|
|
22162
|
-
|
|
22163
|
-
|
|
22164
|
-
|
|
22165
|
-
spiceString = spiceNetlist.toSpiceString();
|
|
22166
|
-
debug11(`Generated SPICE string:
|
|
22167
|
-
${spiceString}`);
|
|
22168
|
-
} catch (error) {
|
|
22169
|
-
debug11(`Failed to convert circuit JSON to SPICE: ${error}`);
|
|
22170
|
-
return;
|
|
22171
|
-
}
|
|
22172
|
-
const graphNameToProbe = /* @__PURE__ */ new Map();
|
|
22173
|
-
for (const probe of voltageProbes) {
|
|
22174
|
-
if (probe.finalProbeName) {
|
|
22175
|
-
graphNameToProbe.set(probe.finalProbeName, probe);
|
|
22194
|
+
for (const analogSim of analogSims) {
|
|
22195
|
+
const simulationExperimentId = analogSim.simulation_experiment_id;
|
|
22196
|
+
if (!simulationExperimentId) {
|
|
22197
|
+
debug11("No simulation experiment id found, skipping simulation");
|
|
22198
|
+
continue;
|
|
22176
22199
|
}
|
|
22177
|
-
|
|
22178
|
-
|
|
22179
|
-
|
|
22180
|
-
|
|
22181
|
-
|
|
22182
|
-
|
|
22183
|
-
graphDisplayOverridesByProbeId.set(
|
|
22184
|
-
probe.simulation_voltage_probe_id,
|
|
22185
|
-
getVoltageProbeGraphDisplayOverrides(probe)
|
|
22186
|
-
);
|
|
22200
|
+
const simulationExperiment = root.db.simulation_experiment.get(
|
|
22201
|
+
simulationExperimentId
|
|
22202
|
+
);
|
|
22203
|
+
if (!simulationExperiment) {
|
|
22204
|
+
debug11("No simulation experiment found, skipping simulation");
|
|
22205
|
+
continue;
|
|
22187
22206
|
}
|
|
22188
|
-
|
|
22189
|
-
|
|
22190
|
-
|
|
22191
|
-
|
|
22192
|
-
|
|
22193
|
-
|
|
22194
|
-
|
|
22207
|
+
const simulationScope = analogSim.getGroup() ?? group;
|
|
22208
|
+
const voltageProbes = simulationScope.selectAll("voltageprobe");
|
|
22209
|
+
const ammeters = simulationScope.selectAll("ammeter");
|
|
22210
|
+
const circuitJson = getCircuitJsonForAnalogSimulation({
|
|
22211
|
+
circuitJson: root.db.toArray(),
|
|
22212
|
+
simulationExperimentId,
|
|
22213
|
+
voltageProbes,
|
|
22214
|
+
ammeters
|
|
22215
|
+
});
|
|
22216
|
+
let spiceString;
|
|
22217
|
+
let spiceNetlist;
|
|
22218
|
+
try {
|
|
22219
|
+
spiceNetlist = circuitJsonToSpice(circuitJson);
|
|
22220
|
+
spiceString = spiceNetlist.toSpiceString();
|
|
22221
|
+
debug11(`Generated SPICE string:
|
|
22222
|
+
${spiceString}`);
|
|
22223
|
+
} catch (error) {
|
|
22224
|
+
debug11(`Failed to convert circuit JSON to SPICE: ${error}`);
|
|
22225
|
+
root.db.simulation_unknown_experiment_error.insert({
|
|
22226
|
+
simulation_experiment_id: simulationExperimentId,
|
|
22227
|
+
error_type: "simulation_unknown_experiment_error",
|
|
22228
|
+
message: error instanceof Error ? error.message : String(error)
|
|
22229
|
+
});
|
|
22230
|
+
continue;
|
|
22195
22231
|
}
|
|
22196
|
-
|
|
22197
|
-
|
|
22198
|
-
|
|
22199
|
-
|
|
22200
|
-
|
|
22201
|
-
|
|
22202
|
-
|
|
22232
|
+
const graphNameToProbe = /* @__PURE__ */ new Map();
|
|
22233
|
+
const voltageProbesById = /* @__PURE__ */ new Map();
|
|
22234
|
+
const graphDisplayOverridesByProbeId = /* @__PURE__ */ new Map();
|
|
22235
|
+
for (const probe of voltageProbes) {
|
|
22236
|
+
if (probe.finalProbeName) {
|
|
22237
|
+
graphNameToProbe.set(probe.finalProbeName, probe);
|
|
22238
|
+
}
|
|
22239
|
+
if (probe.simulation_voltage_probe_id) {
|
|
22240
|
+
voltageProbesById.set(probe.simulation_voltage_probe_id, probe);
|
|
22241
|
+
graphDisplayOverridesByProbeId.set(
|
|
22242
|
+
probe.simulation_voltage_probe_id,
|
|
22243
|
+
getVoltageProbeGraphDisplayOverrides(probe)
|
|
22244
|
+
);
|
|
22245
|
+
}
|
|
22203
22246
|
}
|
|
22204
|
-
|
|
22205
|
-
|
|
22206
|
-
|
|
22207
|
-
|
|
22208
|
-
|
|
22209
|
-
|
|
22210
|
-
simulationProbe.simulation_voltage_probe_id
|
|
22211
|
-
);
|
|
22212
|
-
const graphName = graphNamesFromNetlist[index];
|
|
22213
|
-
if (probe && graphName) {
|
|
22214
|
-
graphNameToProbe.set(graphName, probe);
|
|
22247
|
+
for (const ammeter of ammeters) {
|
|
22248
|
+
if (ammeter.simulation_current_probe_id) {
|
|
22249
|
+
graphDisplayOverridesByProbeId.set(
|
|
22250
|
+
ammeter.simulation_current_probe_id,
|
|
22251
|
+
getAmmeterGraphDisplayOverrides(ammeter)
|
|
22252
|
+
);
|
|
22215
22253
|
}
|
|
22216
22254
|
}
|
|
22217
|
-
|
|
22218
|
-
|
|
22219
|
-
`Skipping probe-to-graph order mapping because counts differ: probes=${orderedSimulationProbes.length} graphNames=${graphNamesFromNetlist.length}`
|
|
22255
|
+
const scopedCurrentProbeIds = new Set(
|
|
22256
|
+
ammeters.map((ammeter) => ammeter.simulation_current_probe_id).filter((id) => Boolean(id))
|
|
22220
22257
|
);
|
|
22221
|
-
|
|
22222
|
-
|
|
22258
|
+
const currentProbesById = /* @__PURE__ */ new Map();
|
|
22259
|
+
const currentProbesByName = /* @__PURE__ */ new Map();
|
|
22260
|
+
for (const probe of root.db.simulation_current_probe.list().filter(
|
|
22261
|
+
(probe2) => scopedCurrentProbeIds.has(probe2.simulation_current_probe_id)
|
|
22262
|
+
)) {
|
|
22263
|
+
currentProbesById.set(probe.simulation_current_probe_id, probe);
|
|
22264
|
+
if (probe.name !== void 0) {
|
|
22265
|
+
currentProbesByName.set(probe.name, probe);
|
|
22266
|
+
}
|
|
22267
|
+
}
|
|
22268
|
+
const orderedSimulationProbes = root.db.simulation_voltage_probe.list().filter(
|
|
22269
|
+
(probe) => voltageProbesById.has(probe.simulation_voltage_probe_id)
|
|
22270
|
+
);
|
|
22271
|
+
const graphNamesFromNetlist = getTransientVoltageGraphNamesFromSpiceNetlist(spiceNetlist);
|
|
22272
|
+
if (graphNamesFromNetlist.length === orderedSimulationProbes.length) {
|
|
22273
|
+
for (const [
|
|
22274
|
+
index,
|
|
22275
|
+
simulationProbe
|
|
22276
|
+
] of orderedSimulationProbes.entries()) {
|
|
22277
|
+
const probe = voltageProbesById.get(
|
|
22278
|
+
simulationProbe.simulation_voltage_probe_id
|
|
22279
|
+
);
|
|
22280
|
+
const graphName = graphNamesFromNetlist[index];
|
|
22281
|
+
if (probe && graphName) {
|
|
22282
|
+
graphNameToProbe.set(graphName, probe);
|
|
22283
|
+
}
|
|
22284
|
+
}
|
|
22285
|
+
} else {
|
|
22286
|
+
debug11(
|
|
22287
|
+
`Skipping probe-to-graph order mapping because counts differ: probes=${orderedSimulationProbes.length} graphNames=${graphNamesFromNetlist.length}`
|
|
22288
|
+
);
|
|
22289
|
+
}
|
|
22223
22290
|
const engineName = analogSim._parsedProps.spiceEngine ?? "spicey";
|
|
22224
22291
|
const spiceEngine = spiceEngineMap[engineName];
|
|
22225
22292
|
if (!spiceEngine) {
|
|
@@ -22229,7 +22296,7 @@ ${spiceString}`);
|
|
|
22229
22296
|
)}`
|
|
22230
22297
|
);
|
|
22231
22298
|
}
|
|
22232
|
-
const effectId = `spice-simulation-${engineName}-${
|
|
22299
|
+
const effectId = `spice-simulation-${engineName}-${simulationExperimentId}`;
|
|
22233
22300
|
debug11(
|
|
22234
22301
|
`Queueing simulation for spice engine: ${engineName} (id: ${effectId})`
|
|
22235
22302
|
);
|
|
@@ -22240,11 +22307,6 @@ ${spiceString}`);
|
|
|
22240
22307
|
debug11(
|
|
22241
22308
|
`Simulation completed, received ${result.simulationResultCircuitJson.length} elements`
|
|
22242
22309
|
);
|
|
22243
|
-
const simulationExperiment = root.db.simulation_experiment.list()[0];
|
|
22244
|
-
if (!simulationExperiment) {
|
|
22245
|
-
debug11("No simulation experiment found, skipping result insertion");
|
|
22246
|
-
return;
|
|
22247
|
-
}
|
|
22248
22310
|
const insertedVoltageGraphs = [];
|
|
22249
22311
|
const insertedCurrentGraphs = [];
|
|
22250
22312
|
for (const rawElement of result.simulationResultCircuitJson) {
|
|
@@ -22294,9 +22356,8 @@ ${spiceString}`);
|
|
|
22294
22356
|
group._markDirty("SimulationSpiceEngineRender");
|
|
22295
22357
|
} catch (error) {
|
|
22296
22358
|
debug11(`Simulation failed for engine ${engineName}: ${error}`);
|
|
22297
|
-
const simulationExperiment = root.db.simulation_experiment.list()[0];
|
|
22298
22359
|
root.db.simulation_unknown_experiment_error.insert({
|
|
22299
|
-
simulation_experiment_id:
|
|
22360
|
+
simulation_experiment_id: simulationExperimentId,
|
|
22300
22361
|
error_type: "simulation_unknown_experiment_error",
|
|
22301
22362
|
message: error instanceof Error ? error.message : String(error)
|
|
22302
22363
|
});
|
|
@@ -22593,7 +22654,7 @@ function Group_getRoutingPhasePlans(group) {
|
|
|
22593
22654
|
var package_default = {
|
|
22594
22655
|
name: "@tscircuit/core",
|
|
22595
22656
|
type: "module",
|
|
22596
|
-
version: "0.0.
|
|
22657
|
+
version: "0.0.1443",
|
|
22597
22658
|
types: "dist/index.d.ts",
|
|
22598
22659
|
main: "dist/index.js",
|
|
22599
22660
|
module: "dist/index.js",
|
|
@@ -32869,6 +32930,7 @@ var SchematicCell = class extends PrimitiveComponent2 {
|
|
|
32869
32930
|
// lib/components/primitive-components/AnalogSimulation.ts
|
|
32870
32931
|
import { analogSimulationProps } from "@tscircuit/props";
|
|
32871
32932
|
var AnalogSimulation = class extends PrimitiveComponent2 {
|
|
32933
|
+
simulation_experiment_id = null;
|
|
32872
32934
|
get config() {
|
|
32873
32935
|
return {
|
|
32874
32936
|
componentName: "AnalogSimulation",
|
|
@@ -32880,7 +32942,7 @@ var AnalogSimulation = class extends PrimitiveComponent2 {
|
|
|
32880
32942
|
const { duration, name, startTime, timePerStep, spiceOptions } = this._parsedProps;
|
|
32881
32943
|
const durationMs = duration || 10;
|
|
32882
32944
|
const timePerStepMs = timePerStep || 0.01;
|
|
32883
|
-
db.simulation_experiment.insert({
|
|
32945
|
+
const simulationExperiment = db.simulation_experiment.insert({
|
|
32884
32946
|
name: name ?? "spice_transient_analysis",
|
|
32885
32947
|
experiment_type: "spice_transient_analysis",
|
|
32886
32948
|
end_time_ms: durationMs,
|
|
@@ -32888,6 +32950,7 @@ var AnalogSimulation = class extends PrimitiveComponent2 {
|
|
|
32888
32950
|
time_per_step: timePerStepMs,
|
|
32889
32951
|
spice_options: spiceOptions
|
|
32890
32952
|
});
|
|
32953
|
+
this.simulation_experiment_id = simulationExperiment.simulation_experiment_id;
|
|
32891
32954
|
}
|
|
32892
32955
|
};
|
|
32893
32956
|
|