A quantum circuit optimizer based on sum-over-paths representations