def serial_executor(circuit: QPROGRAM, noise: float = BASE_NOISE) -> float: """A noisy executor function which executes the input circuit with `noise` depolarizing noise and returns the expectation value of the ground state projector. Simulation will be slow for "large circuits" (> a few qubits). """ circuit, _ = convert_to_mitiq(circuit) # Ground state projector. d = 2**len(circuit.all_qubits()) obs = np.zeros(shape=(d, d), dtype=np.float32) obs[0, 0] = 1.0 return noisy_simulation(circuit, noise, obs)
def executor(circuit: QPROGRAM, noise_level: float = 0.1, shots: int = 8192) -> MeasurementResult: """Returns computational basis measurements after executing the circuit with depolarizing noise. Args: circuit: Circuit to execute. noise_level: Probability of depolarizing noise after each moment. shots: Number of samples to take. Returns: Dictionary where each key is a bitstring (binary int) and each value is the number of times that bitstring was measured. """ circuit = circuit.with_noise(cirq.depolarize(p=noise_level)) circuit.append(cirq.measure(*circuit.all_qubits(), key="z")) result = cirq.DensityMatrixSimulator().run(circuit, repetitions=shots) return {bin(k): v for k, v in result.histogram(key="z").items()}