pascalkuthe / OpenVAF

An innovative Verilog-A compiler
https://openvaf.semimod.de/
GNU General Public License v3.0
129 stars 22 forks source link

Fix missing derivatives in mextram #10

Closed pascalkuthe closed 1 year ago

pascalkuthe commented 1 year ago

When OpenVAF compresses derivatives shared in a common subgraph it may in some cases find nested subgraphs. For example if a voltage is calculated with Vab = Vay + Vyx + Vxb to save an unknown OpenVAF will perform two subgraph optimizations (one for each addition).

Previously OpenVAF would only emit the derivatives for the last subgraph in this case as the chain rule was applied in the incorrect order. This would cause catastrophic convergence failures for some models like MEXTRAM.

This commit reverses the order in which chain rules are applied. However, this meant that higher order derivative chain rules were not emitted properly as the lower order derivative needs to be emitted first (which was pushed to the chain rule list first). Therefore, the order in which derivatives where pushed to the chain rule list was also reversed.

A unit case that covers this case (and the subgraph optimization in general) was added to ensure this doesn't regress in the future.

pascalkuthe commented 1 year ago

bors merge

bors[bot] commented 1 year ago

Build succeeded: