From dd1958550893c9f25c62427c51092654f76b9cc4 Mon Sep 17 00:00:00 2001 From: Dylan Anthony <43723790+dbanty@users.noreply.github.com> Date: Tue, 10 May 2022 13:06:30 -0600 Subject: [PATCH] Fix: Include `cz` in OpenQASM basis gates (#35) --- qiskit_rigetti/_qcs_provider.py | 2 +- tests/test_qcs_backend.py | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/qiskit_rigetti/_qcs_provider.py b/qiskit_rigetti/_qcs_provider.py index 8ae81e8..3a303bf 100644 --- a/qiskit_rigetti/_qcs_provider.py +++ b/qiskit_rigetti/_qcs_provider.py @@ -122,7 +122,7 @@ def _configuration(name: str, num_qubits: int, local: bool, simulator: bool) -> backend_name=name, backend_version="", n_qubits=num_qubits, - basis_gates=["u1", "u2", "u3", "cx", "id"], + basis_gates=["u1", "u2", "u3", "cx", "id", "cz"], gates=[], local=local, simulator=simulator, diff --git a/tests/test_qcs_backend.py b/tests/test_qcs_backend.py index 5a407b0..e0def40 100644 --- a/tests/test_qcs_backend.py +++ b/tests/test_qcs_backend.py @@ -14,11 +14,13 @@ # limitations under the License. ############################################################################## import pytest -from qiskit import execute, QuantumCircuit, QuantumRegister, ClassicalRegister +from qiskit import execute, QuantumCircuit, QuantumRegister, ClassicalRegister, transpile from qiskit.providers import JobStatus -from qiskit.circuit import Parameter +from qiskit.circuit import Parameter, Qubit +from qiskit.circuit.library import CZGate -from qiskit_rigetti import RigettiQCSProvider, RigettiQCSBackend +from qiskit_rigetti import RigettiQCSProvider, RigettiQCSBackend, QuilCircuit +from qiskit_rigetti.gates import XYGate def test_run(backend: RigettiQCSBackend): @@ -162,6 +164,26 @@ def test_run__backend_coupling_map(): assert [(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)] == sorted(backend.coupling_map.get_edges()) +def test_decomposition(backend: RigettiQCSBackend): + """Test that CZGate remains after the transpile.""" + circuit = QuilCircuit(2, 2) + circuit.cz(0, 1) + circuit.measure_all() + + circuit = transpile(circuit, backend=backend) + job = execute(circuit, backend, shots=1) + job.result() # Just make sure nothing throws an exception so the circuit is valid + + assert job.status() == JobStatus.DONE + assert len(circuit.data) == 4 # CZ, BARRIER, MEASURE, MEASURE + assert circuit.data[0] == ( + CZGate(), + [Qubit(QuantumRegister(2, "q"), 0), + Qubit(QuantumRegister(2, "q"), 1)], + [], + ) + + @pytest.fixture def backend(): return RigettiQCSProvider().get_simulator(num_qubits=3)