Skip to content

Commit

Permalink
Fix: Include cz in OpenQASM basis gates (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanty committed May 26, 2022
1 parent 11d13da commit dd19585
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion qiskit_rigetti/_qcs_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 25 additions & 3 deletions tests/test_qcs_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dd19585

Please sign in to comment.