def test_executor_observable_compatibility_check(execute, obs): q = cirq.LineQubit(0) circuits = [cirq.Circuit(cirq.X(q)), cirq.Circuit(cirq.H(q), cirq.Z(q))] executor = Executor(execute) with pytest.raises(ValueError, match="are not compatible"): executor.evaluate(circuits, obs)
def test_executor_evaluate_float(execute): q = cirq.LineQubit(0) circuits = [cirq.Circuit(cirq.X(q)), cirq.Circuit(cirq.H(q), cirq.Z(q))] executor = Executor(execute) results = executor.evaluate(circuits) assert np.allclose(results, [1, 2]) if execute is executor_serial_unique: assert executor.calls_to_executor == 2 else: assert executor.calls_to_executor == 1 assert executor.executed_circuits == circuits assert executor.quantum_results == [1, 2]
def test_executor_evaluate_density_matrix(execute): obs = Observable(PauliString("Z")) q = cirq.LineQubit(0) circuits = [cirq.Circuit(cirq.I.on(q)), cirq.Circuit(cirq.X.on(q))] executor = Executor(execute) results = executor.evaluate(circuits, obs) assert np.allclose(results, [1, -1]) if execute is executor_density_matrix: assert executor.calls_to_executor == 2 else: assert executor.calls_to_executor == 1 assert executor.executed_circuits == circuits assert np.allclose(executor.quantum_results[0], executor_density_matrix(circuits[0])) assert np.allclose(executor.quantum_results[1], executor_density_matrix(circuits[1])) assert len(executor.quantum_results) == len(circuits)
def test_executor_evaluate_measurements(execute): obs = Observable(PauliString("Z")) q = cirq.LineQubit(0) circuits = [cirq.Circuit(cirq.I.on(q)), cirq.Circuit(cirq.X.on(q))] executor = Executor(execute) results = executor.evaluate(circuits, obs) assert np.allclose(results, [1, -1]) if execute is executor_measurements: assert executor.calls_to_executor == 2 else: assert executor.calls_to_executor == 1 assert executor.executed_circuits[0] == circuits[0] + cirq.measure(q) assert executor.executed_circuits[1] == circuits[1] + cirq.measure(q) assert executor.quantum_results[0] == executor_measurements( circuits[0] + cirq.measure(q)) assert executor.quantum_results[1] == executor_measurements( circuits[1] + cirq.measure(q)) assert len(executor.quantum_results) == len(circuits)