I have a program that needs to evaluate several Cirq circuits by using both simulators the Simulator()
and DensityMatrixSimulator()
. I want to evaluate a circuit that its composed by repeating blocks n=1,2,3,..., so the pseudocode for evaluation looks like this:
for n in some range:
n=1 -> Evaluate block and employ simulate_expectation_values()
method of the simulators
n=2 -> Evaluate block+block and employ simulate_expectation_values()
method of the simulators
n=3 -> Evaluate block+block+block and employ simulate_expectation_values()
method of the simulators
etc...
This is highly inefficient as every time I evaluate for a fixed n, the circuit is repeated from the beginning until it reaches n-blocks depth, and I get the expectation values. In real hardware, of course the circuit depth is determined by the time when measurements take place. But at the simulation level, is there a way to perform the above operations in a more efficient way? This means to perform the simulation over all "n"s values at once, and get the expectation values corresponding to each of the n circuit depths without the need to explicitly evaluate the outer loop, and thus, avoiding starting from the beginning on each iteration.