microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
source/pip/tests-integration/interop_qiskit/test_qsharp.py
59lines · modecode
| 1 | # Copyright (c) Microsoft Corporation. |
| 2 | # Licensed under the MIT License. |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | from . import QISKIT_AVAILABLE, SKIP_REASON |
| 7 | |
| 8 | |
| 9 | if QISKIT_AVAILABLE: |
| 10 | from qsharp.interop.qiskit import ( |
| 11 | OutputSemantics, |
| 12 | ProgramType, |
| 13 | QSharpBackend, |
| 14 | ) |
| 15 | from qiskit.circuit import QuantumCircuit |
| 16 | |
| 17 | |
| 18 | @pytest.mark.skipif(not QISKIT_AVAILABLE, reason=SKIP_REASON) |
| 19 | def test_qsharp_smoke() -> None: |
| 20 | circuit = QuantumCircuit(2, 2) |
| 21 | circuit.x(0) |
| 22 | circuit.cx(0, 1) |
| 23 | circuit.measure_all(add_bits=False) |
| 24 | circuit.name = "smoke" |
| 25 | |
| 26 | backend = QSharpBackend() |
| 27 | res = backend._qsharp(circuit) |
| 28 | assert res is not None |
| 29 | assert "qasm_import" in res |
| 30 | assert "operation smoke() : Result[]" in res |
| 31 | assert "Std.Arrays.Reversed" in res |
| 32 | |
| 33 | |
| 34 | @pytest.mark.skipif(not QISKIT_AVAILABLE, reason=SKIP_REASON) |
| 35 | def test_qsharp_disable_output() -> None: |
| 36 | circuit = QuantumCircuit(2, 2) |
| 37 | circuit.x(0) |
| 38 | circuit.cx(0, 1) |
| 39 | circuit.measure_all(add_bits=False) |
| 40 | circuit.name = "circuit_with_unit_output" |
| 41 | backend = QSharpBackend() |
| 42 | output_semantics = OutputSemantics.ResourceEstimation |
| 43 | |
| 44 | res = backend._qsharp(circuit, output_semantics=output_semantics) |
| 45 | assert "operation circuit_with_unit_output() : Unit" in res |
| 46 | |
| 47 | |
| 48 | @pytest.mark.skipif(not QISKIT_AVAILABLE, reason=SKIP_REASON) |
| 49 | def test_qsharp_openqasm_output_semantics() -> None: |
| 50 | circuit = QuantumCircuit(2, 2) |
| 51 | circuit.x(0) |
| 52 | circuit.cx(0, 1) |
| 53 | circuit.measure_all(add_bits=False) |
| 54 | circuit.name = "circuit_with_unit_output" |
| 55 | backend = QSharpBackend() |
| 56 | output_semantics = OutputSemantics.OpenQasm |
| 57 | |
| 58 | res = backend._qsharp(circuit, output_semantics=output_semantics) |
| 59 | assert "Std.Arrays.Reversed" not in res |
| 60 | |