@tscircuit/core 0.0.1442 → 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 +160 -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
|
@@ -21628,7 +21628,36 @@ var insertNetLabelsForPortsMissingTrace = ({
|
|
|
21628
21628
|
}
|
|
21629
21629
|
const implicitPortLabelText = connectedSourcePortIdsForKey.map((sourcePortId) => getSourcePortNetLabelText(db, sourcePortId)).filter((label) => Boolean(label)).join("/");
|
|
21630
21630
|
const directCrossSubcircuitConnectionLabelText = getDirectCrossSubcircuitConnectionLabelText(db, srcPortId);
|
|
21631
|
+
const isConnectivityKeyFallback = !sourceNet?.name && !sourceNet?.source_net_id && !assignedPortNetLabelText && !directCrossSubcircuitConnectionLabelText && !implicitPortLabelText;
|
|
21631
21632
|
const text = sourceNet?.name || sourceNet?.source_net_id || assignedPortNetLabelText || directCrossSubcircuitConnectionLabelText || implicitPortLabelText || connKey;
|
|
21633
|
+
if (isConnectivityKeyFallback) {
|
|
21634
|
+
const sourcePortComponent = connectedPortsForKey.find(
|
|
21635
|
+
(port) => port.source_port_id === srcPortId
|
|
21636
|
+
);
|
|
21637
|
+
const collapsedGroup = sourcePortComponent?.parent;
|
|
21638
|
+
if (sourcePortComponent?.isGroupPort() && collapsedGroup?._parsedProps?.showAsSchematicBox) {
|
|
21639
|
+
const sourceTracesConnectedToPort = db.source_trace.list().filter(
|
|
21640
|
+
(trace) => trace.connected_source_port_ids?.includes(srcPortId)
|
|
21641
|
+
);
|
|
21642
|
+
const isPortInsideCollapsedGroup = (port) => {
|
|
21643
|
+
let parent = port.parent;
|
|
21644
|
+
while (parent) {
|
|
21645
|
+
if (parent === collapsedGroup) return true;
|
|
21646
|
+
parent = parent.parent;
|
|
21647
|
+
}
|
|
21648
|
+
return false;
|
|
21649
|
+
};
|
|
21650
|
+
const allConnectionsAreInternal = sourceTracesConnectedToPort.length > 0 && sourceTracesConnectedToPort.every(
|
|
21651
|
+
(trace) => (trace.connected_source_net_ids?.length ?? 0) === 0 && trace.connected_source_port_ids.filter((sourcePortId) => sourcePortId !== srcPortId).every((sourcePortId) => {
|
|
21652
|
+
const connectedPort = connectedPortsForKey.find(
|
|
21653
|
+
(port) => port.source_port_id === sourcePortId
|
|
21654
|
+
);
|
|
21655
|
+
return connectedPort ? isPortInsideCollapsedGroup(connectedPort) : false;
|
|
21656
|
+
})
|
|
21657
|
+
);
|
|
21658
|
+
if (allConnectionsAreInternal) continue;
|
|
21659
|
+
}
|
|
21660
|
+
}
|
|
21632
21661
|
const connectedPortCountForKey = Array.from(
|
|
21633
21662
|
allSourceAndSchematicPortIdsInScope
|
|
21634
21663
|
).filter((portId) => {
|
|
@@ -22115,82 +22144,149 @@ var isVoltageGraph = (element) => element.type === "simulation_transient_voltage
|
|
|
22115
22144
|
|
|
22116
22145
|
// lib/components/primitive-components/Group/Group_doInitialSimulationSpiceEngineRender.ts
|
|
22117
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
|
+
};
|
|
22118
22183
|
function Group_doInitialSimulationSpiceEngineRender(group) {
|
|
22119
22184
|
if (!group.isSubcircuit) return;
|
|
22120
22185
|
const { root } = group;
|
|
22121
22186
|
if (!root) return;
|
|
22122
22187
|
const analogSims = group.selectAll("analogsimulation");
|
|
22123
22188
|
if (analogSims.length === 0) return;
|
|
22124
|
-
const voltageProbes = group.selectAll("voltageprobe");
|
|
22125
|
-
const ammeters = group.selectAll("ammeter");
|
|
22126
22189
|
resetSimulationColorState();
|
|
22127
22190
|
const spiceEngineMap = { ...root.platform?.spiceEngineMap };
|
|
22128
22191
|
if (!spiceEngineMap.spicey) {
|
|
22129
22192
|
spiceEngineMap.spicey = getSpiceyEngine();
|
|
22130
22193
|
}
|
|
22131
|
-
const
|
|
22132
|
-
|
|
22133
|
-
|
|
22134
|
-
|
|
22135
|
-
|
|
22136
|
-
spiceString = spiceNetlist.toSpiceString();
|
|
22137
|
-
debug11(`Generated SPICE string:
|
|
22138
|
-
${spiceString}`);
|
|
22139
|
-
} catch (error) {
|
|
22140
|
-
debug11(`Failed to convert circuit JSON to SPICE: ${error}`);
|
|
22141
|
-
return;
|
|
22142
|
-
}
|
|
22143
|
-
const graphNameToProbe = /* @__PURE__ */ new Map();
|
|
22144
|
-
for (const probe of voltageProbes) {
|
|
22145
|
-
if (probe.finalProbeName) {
|
|
22146
|
-
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;
|
|
22147
22199
|
}
|
|
22148
|
-
|
|
22149
|
-
|
|
22150
|
-
|
|
22151
|
-
|
|
22152
|
-
|
|
22153
|
-
|
|
22154
|
-
graphDisplayOverridesByProbeId.set(
|
|
22155
|
-
probe.simulation_voltage_probe_id,
|
|
22156
|
-
getVoltageProbeGraphDisplayOverrides(probe)
|
|
22157
|
-
);
|
|
22200
|
+
const simulationExperiment = root.db.simulation_experiment.get(
|
|
22201
|
+
simulationExperimentId
|
|
22202
|
+
);
|
|
22203
|
+
if (!simulationExperiment) {
|
|
22204
|
+
debug11("No simulation experiment found, skipping simulation");
|
|
22205
|
+
continue;
|
|
22158
22206
|
}
|
|
22159
|
-
|
|
22160
|
-
|
|
22161
|
-
|
|
22162
|
-
|
|
22163
|
-
|
|
22164
|
-
|
|
22165
|
-
|
|
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;
|
|
22166
22231
|
}
|
|
22167
|
-
|
|
22168
|
-
|
|
22169
|
-
|
|
22170
|
-
|
|
22171
|
-
|
|
22172
|
-
|
|
22173
|
-
|
|
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
|
+
}
|
|
22174
22246
|
}
|
|
22175
|
-
|
|
22176
|
-
|
|
22177
|
-
|
|
22178
|
-
|
|
22179
|
-
|
|
22180
|
-
|
|
22181
|
-
simulationProbe.simulation_voltage_probe_id
|
|
22182
|
-
);
|
|
22183
|
-
const graphName = graphNamesFromNetlist[index];
|
|
22184
|
-
if (probe && graphName) {
|
|
22185
|
-
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
|
+
);
|
|
22186
22253
|
}
|
|
22187
22254
|
}
|
|
22188
|
-
|
|
22189
|
-
|
|
22190
|
-
`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))
|
|
22191
22257
|
);
|
|
22192
|
-
|
|
22193
|
-
|
|
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
|
+
}
|
|
22194
22290
|
const engineName = analogSim._parsedProps.spiceEngine ?? "spicey";
|
|
22195
22291
|
const spiceEngine = spiceEngineMap[engineName];
|
|
22196
22292
|
if (!spiceEngine) {
|
|
@@ -22200,7 +22296,7 @@ ${spiceString}`);
|
|
|
22200
22296
|
)}`
|
|
22201
22297
|
);
|
|
22202
22298
|
}
|
|
22203
|
-
const effectId = `spice-simulation-${engineName}-${
|
|
22299
|
+
const effectId = `spice-simulation-${engineName}-${simulationExperimentId}`;
|
|
22204
22300
|
debug11(
|
|
22205
22301
|
`Queueing simulation for spice engine: ${engineName} (id: ${effectId})`
|
|
22206
22302
|
);
|
|
@@ -22211,11 +22307,6 @@ ${spiceString}`);
|
|
|
22211
22307
|
debug11(
|
|
22212
22308
|
`Simulation completed, received ${result.simulationResultCircuitJson.length} elements`
|
|
22213
22309
|
);
|
|
22214
|
-
const simulationExperiment = root.db.simulation_experiment.list()[0];
|
|
22215
|
-
if (!simulationExperiment) {
|
|
22216
|
-
debug11("No simulation experiment found, skipping result insertion");
|
|
22217
|
-
return;
|
|
22218
|
-
}
|
|
22219
22310
|
const insertedVoltageGraphs = [];
|
|
22220
22311
|
const insertedCurrentGraphs = [];
|
|
22221
22312
|
for (const rawElement of result.simulationResultCircuitJson) {
|
|
@@ -22265,9 +22356,8 @@ ${spiceString}`);
|
|
|
22265
22356
|
group._markDirty("SimulationSpiceEngineRender");
|
|
22266
22357
|
} catch (error) {
|
|
22267
22358
|
debug11(`Simulation failed for engine ${engineName}: ${error}`);
|
|
22268
|
-
const simulationExperiment = root.db.simulation_experiment.list()[0];
|
|
22269
22359
|
root.db.simulation_unknown_experiment_error.insert({
|
|
22270
|
-
simulation_experiment_id:
|
|
22360
|
+
simulation_experiment_id: simulationExperimentId,
|
|
22271
22361
|
error_type: "simulation_unknown_experiment_error",
|
|
22272
22362
|
message: error instanceof Error ? error.message : String(error)
|
|
22273
22363
|
});
|
|
@@ -22564,7 +22654,7 @@ function Group_getRoutingPhasePlans(group) {
|
|
|
22564
22654
|
var package_default = {
|
|
22565
22655
|
name: "@tscircuit/core",
|
|
22566
22656
|
type: "module",
|
|
22567
|
-
version: "0.0.
|
|
22657
|
+
version: "0.0.1443",
|
|
22568
22658
|
types: "dist/index.d.ts",
|
|
22569
22659
|
main: "dist/index.js",
|
|
22570
22660
|
module: "dist/index.js",
|
|
@@ -32840,6 +32930,7 @@ var SchematicCell = class extends PrimitiveComponent2 {
|
|
|
32840
32930
|
// lib/components/primitive-components/AnalogSimulation.ts
|
|
32841
32931
|
import { analogSimulationProps } from "@tscircuit/props";
|
|
32842
32932
|
var AnalogSimulation = class extends PrimitiveComponent2 {
|
|
32933
|
+
simulation_experiment_id = null;
|
|
32843
32934
|
get config() {
|
|
32844
32935
|
return {
|
|
32845
32936
|
componentName: "AnalogSimulation",
|
|
@@ -32851,7 +32942,7 @@ var AnalogSimulation = class extends PrimitiveComponent2 {
|
|
|
32851
32942
|
const { duration, name, startTime, timePerStep, spiceOptions } = this._parsedProps;
|
|
32852
32943
|
const durationMs = duration || 10;
|
|
32853
32944
|
const timePerStepMs = timePerStep || 0.01;
|
|
32854
|
-
db.simulation_experiment.insert({
|
|
32945
|
+
const simulationExperiment = db.simulation_experiment.insert({
|
|
32855
32946
|
name: name ?? "spice_transient_analysis",
|
|
32856
32947
|
experiment_type: "spice_transient_analysis",
|
|
32857
32948
|
end_time_ms: durationMs,
|
|
@@ -32859,6 +32950,7 @@ var AnalogSimulation = class extends PrimitiveComponent2 {
|
|
|
32859
32950
|
time_per_step: timePerStepMs,
|
|
32860
32951
|
spice_options: spiceOptions
|
|
32861
32952
|
});
|
|
32953
|
+
this.simulation_experiment_id = simulationExperiment.simulation_experiment_id;
|
|
32862
32954
|
}
|
|
32863
32955
|
};
|
|
32864
32956
|
|