Cache CircuitToEinsum metadata for repeated observable sweeps#219
Open
AbdelStark wants to merge 1 commit intoNVIDIA:mainfrom
Open
Cache CircuitToEinsum metadata for repeated observable sweeps#219AbdelStark wants to merge 1 commit intoNVIDIA:mainfrom
AbdelStark wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change caches
CircuitToEinsumforward/inverse metadata for repeated observable-oriented calls and adds focused cache tests plus a small benchmark script.Problem
CircuitToEinsumalready caches the base forward parse through_get_inputs(), but repeated calls to:expectation(...)reduced_density_matrix(...)marginal_probability(...)still rebuild the forward/inverse metadata in
_get_forward_inverse_metadata(...).For repeated observable sweeps on the same circuit, this adds avoidable Python-side overhead even when:
What changed
_forward_inverse_metadata_cacheonCircuitToEinsumlightconedecompose_gatescheck_diagonalqubits_frontiernext_frontierqubits_frontier.copy()so each call still gets an isolated mutable frontier mapwhereorderings reusing one cache entrylightcone=Trueandlightcone=Falsecreating separate entriespython/samples/tensornet/circuit_to_einsum_cache_benchmark.pyfor repeated-call timingUser impact
CircuitToEinsumuse closer to a reusable compiled artifact instead of a one-shot translatorValidation
Targeted validation was done locally against the pure-Python converter path using real Qiskit and Cirq circuits.
Semantic checks covered:
expectation(...)callswhereargumentsLocal timing on a 12-qubit / depth-20 Qiskit circuit:
expectation(lightcone=True): cached mean0.000939 s, uncached mean0.012993 s,13.84xspeedupreduced_density_matrix(lightcone=True): cached mean0.000901 s, uncached mean0.011013 s,12.23xspeedup