I am trying to use the DensityMatrixSimulator in Cirq. I want to append gates to the circuit conditional on measurements. In order to reduce computational resources, I am trying to run these conditional gates by initializing another circuit with these conditional gates using the final state of the first measurement as the initial state. However, I am not sure how I can get the simulate method to accept the initial state matrix (see code below).
I get the ValueError of
ValueError: `state_like` was convertible to a numpy array, but its shape was neither the shape of a list of computational basis values (`len(qid_shape)`) nor the shape of a list or tensor of state vector amplitudes (`qid_shape` or `(product(qid_shape),)`. qid_shape=(2, 2) np.array(state_like).shape=(2, 2, 2, 2) np.array(state_like)=[[[[ 0.+0.j 0.-0.j] [ 0.+0.j 0.-0.j]] [[-0.+0.j 0.-0.j] [-0.+0.j 0.-0.j]]] [[[ 0.+0.j 0.-0.j] [ 1.+0.j 0.-0.j]] [[-0.+0.j 0.-0.j] [-0.+0.j 0.-0.j]]]]
This is the code I am trying to run to figure out how to initialize the initial state of the second circuit.
qubits = cirq.LineQubit.range(2) circuit = cirq.Circuit() circuit.append(cirq.X(qubits)) circuit.append(cirq.Z(qubits)) s = cirq.DensityMatrixSimulator() results = s.simulate(circuit) r = cirq.DensityMatrixSimulator() circuit2 = cirq.Circuit() circuit2.append(cirq.X(qubits)) circuit2.append(cirq.Z(qubits)) results2 =r.simulate(circuit2, initial_state = results._final_simulator_state.density_matrix)
Thank you in advance!