def _circuit_to_choi(circuit: Circuit) -> np.ndarray: """Returns the density matrix of the Choi state associated to the input circuit. The density matrix completely characterizes the quantum channel induced by the input circuit (including the effect of noise if present). Args: circuit: The input circuit. Returns: The density matrix of the Choi state associated to the input circuit. """ simulator = DensityMatrixSimulator() num_qubits = len(circuit.all_qubits()) # Copy and remove all operations full_circ = deepcopy(circuit)[0:0] full_circ += _max_ent_state_circuit(2 * num_qubits) full_circ += circuit return simulator.simulate(full_circ).final_density_matrix # type: ignore
system.normalize() circuit = qdccirq.logsweep_protocol(system, K) simulator = DensityMatrixSimulator() print('done in', time.time() - stopwatch, 'seconds.') # cooling if not cooling_out_exists: print('\nRunning cooling simulation') stopwatch = time.time() # build maximally-mixed system state tensored with |0><0| fridge init_state = np.diag( np.tile(np.array([1 / 2**L, 0], dtype=np.complex64), 2**L)) res = simulator.simulate( circuit, initial_state=init_state, qubit_order=[*system.get_qubits(), qdccirq.FRIDGE]) final_state = res.final_density_matrix[::2, ::2] # discard fridge out_dict = dict(L=L, J=system.J, B=system.B, K=K, init_state='maximally-mixed state', energy=system.energy_expval(final_state), eigoccs=list(system.eigenstate_occupations(final_state))) with open(outfile_cooling, 'wt') as f: json.dump(out_dict, f) print('done in', time.time() - stopwatch, 'seconds.')