Skip to content

Reduce function building overhead in wrappedCircuit#332

Open
k-vijayaraghavan wants to merge 16 commits into
ECSHackWeek:mainfrom
k-vijayaraghavan:main
Open

Reduce function building overhead in wrappedCircuit#332
k-vijayaraghavan wants to merge 16 commits into
ECSHackWeek:mainfrom
k-vijayaraghavan:main

Conversation

@k-vijayaraghavan
Copy link
Copy Markdown

In models/circuits/fittings.py, it is rather inefficient to create/evaluate a new function for each call (i.e. currently, each call involves string conversions and exec). The proposed buildCircuit no longer substitutes parameters; rather it returns a string with variable-names that can be used to construct a lambda function. Subsequently wrapCircuit returns a lambda function that only needs to be generated once. This offers ~80% improvement. (tests/test_fitting.py::test_buildCircuit() has been correspondingly modified for compatibility)

PS: A new file tests/compare_newfitting.py was created (and subsequently deleted) to compare new buildCircuit with original buildCircuit. The file showed significant speed-up
R0-p(R1-Wo1,CPE1) : 82.97% faster
R0-p(C1,R1,R2) : 79.30% faster
R0-p(p(R1, C1)-R2, C2) : 82.17% faster
p(C1,R1)-p(C2,R2) : 81.10% faster
R1 : 85.55% faster

In models/circuits/fittings.py, buildCircuit no longer substitutes parameters; rather it returns a string that can be used to construct  a lambda function. Subsequently wrapCircuit returns a lambda function that only needs to be generated once. This offers ~80% improvement.
@k-vijayaraghavan k-vijayaraghavan marked this pull request as draft April 28, 2026 23:01
@k-vijayaraghavan k-vijayaraghavan marked this pull request as ready for review April 28, 2026 23:17
@k-vijayaraghavan k-vijayaraghavan marked this pull request as draft May 3, 2026 18:11
@k-vijayaraghavan k-vijayaraghavan marked this pull request as ready for review May 3, 2026 18:12
We can pass optimizations={"algorithm":algo,...} to circuit_fit.
Here  algo can be 'pygad' or 'scipy_minimize' or a callable. We can also pass optimizations=[optimizations1,optimizations2], where optimizations1={"algorithm":algo,...} ... to perform sequential optimization.
To improve scaling, we can pass scale=[..] with the expected relative magnitude of the different parameters.
Modified elements for robust tanh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant