[Discussion] Adding quantum math features
See original GitHub issueSometimes, it is useful to be able to analyze circuits in ways that aren’t valid on a quantum computer, but might still be interesting for theory reasons. I came across this issue a little while ago when wanting to compute the overlap <psi_1 | psi_2> of a state and had a hard time keeping memory limits under control with larger batch and state sizes using tfq.layers.State. I ultimately ended up simulating the circuits one by one, and doing the inner products in tf manually. It worked, but it wasn’t pretty.
Would people be interested in implementing things like:
Examples that can be done right now, but are tricky to get right without blowing up memory:
tfq.math.overlap # => analytically compute state overlap between the two circuits
tfq.math.amplitudes # => analytically compute requested state amplitudes (could use qsimh ?).
tfq.math.fideltiy # => analytically compute fidelity between two circuits.
Other interesting math functions might be worth having
tfq.math.operator_matrix # => ingest a cirq.PauliSum and compute the matrix
tfq.math.operator_commutators # => compute commutators on operator matrices
Does anyone else have any suggestions for useful math function ? @dabacon @zaqqwerty @jaeyoo @we-taper
Final thought: If we do end up making this .math module , maybe we should move calculate_unitary and calculate_state inside of it.
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (3 by maintainers)

Top Related StackOverflow Question
I’d say a good approach would be this:
Since op contributions aren’t coming in very quickly and are a fairly sizable undertaking, I think anyone looking to contribute a new op should definitely take this “one at a time issue creation followed by PR chain” approach.
Looks like we had an implementation of fidelity go in here #554 from @jaeyoo so we can cross it off the list here.