def test_mitigate_executor_pyquil(): """Performs the same test as test_execute_with_pec_pyquil_trivial_decomposition(), but using mitigate_executor() instead of execute_with_pec(). """ circuit = pyquil.Program(pyquil.gates.H(0)) rep = OperationRepresentation( circuit, basis_expansion={NoisyOperation(circuit): 1.0} ) unmitigated = serial_executor(circuit) mitigated_executor = mitigate_executor( serial_executor, representations=[rep], num_samples=10, random_state=1, ) mitigated = mitigated_executor(circuit) assert np.isclose(unmitigated, mitigated)
def test_doc_is_preserved(): """Tests that the doc of the original executor is preserved.""" representations = get_pauli_and_cnot_representations(0) def first_executor(circuit): """Doc of the original executor.""" return 0 mit_executor = mitigate_executor(first_executor, representations) assert mit_executor.__doc__ == first_executor.__doc__ @pec_decorator(representations) def second_executor(circuit): """Doc of the original executor.""" return 0 assert second_executor.__doc__ == first_executor.__doc__
def test_mitigate_executor_qiskit(): """Performs the same test as test_execute_with_pec_qiskit_trivial_decomposition(), but using mitigate_executor() instead of execute_with_pec(). """ qreg = qiskit.QuantumRegister(1) circuit = qiskit.QuantumCircuit(qreg) _ = circuit.x(qreg) rep = OperationRepresentation( circuit, basis_expansion={NoisyOperation(circuit): 1.0} ) unmitigated = serial_executor(circuit) mitigated_executor = mitigate_executor( serial_executor, representations=[rep], num_samples=10, random_state=1, ) mitigated = mitigated_executor(circuit) assert np.isclose(unmitigated, mitigated)