Skip to content

Commit

Permalink
Add native support for the SX gate (#158)
Browse files Browse the repository at this point in the history
* Add SX support

* changelog

* SX inverse tests
  • Loading branch information
antalszava authored Nov 15, 2021
1 parent f133e97 commit fa7bd95
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

### Improvements

* Added support for the `qml.SX` operation to the Qiskit devices.
[(#158)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/158)

### Documentation

### Bug fixes
Expand All @@ -14,6 +17,8 @@

This release contains contributions from (in alphabetical order):

Antal Száva

---

# Release 0.18.0
Expand Down
1 change: 1 addition & 0 deletions pennylane_qiskit/qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"RZ": ex.RZGate,
"S": ex.SGate,
"T": ex.TGate,
"SX": ex.SXGate,
# Adding the following for conversion compatibility
"CSWAP": ex.CSwapGate,
"CRX": ex.CRXGate,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)


single_qubit_operations = [qml.PauliX, qml.PauliY, qml.PauliZ, qml.Hadamard, qml.S, qml.T]
single_qubit_operations = [qml.PauliX, qml.PauliY, qml.PauliZ, qml.Hadamard, qml.S, qml.T, qml.SX]

single_qubit_operations_param = [qml.PhaseShift, qml.RX, qml.RY, qml.RZ]
two_qubit = [qml.CNOT, qml.SWAP, qml.CZ]
Expand Down
7 changes: 6 additions & 1 deletion tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,13 @@ def test_one_qubit_operations_supported_by_pennylane(self, recorder):
qc.h(single_wire)
qc.s(single_wire)
qc.t(single_wire)
qc.sx(single_wire)

quantum_circuit = load(qc)
with recorder:
quantum_circuit()

assert len(recorder.queue) == 6
assert len(recorder.queue) == 7

assert recorder.queue[0].name == "PauliX"
assert recorder.queue[0].parameters == []
Expand All @@ -507,6 +508,10 @@ def test_one_qubit_operations_supported_by_pennylane(self, recorder):
assert recorder.queue[5].parameters == []
assert recorder.queue[5].wires == Wires(single_wire)

assert recorder.queue[6].name == "SX"
assert recorder.queue[6].parameters == []
assert recorder.queue[6].wires == Wires(single_wire)

def test_one_qubit_parametrized_operations_supported_by_pennylane(self, recorder):
"""Tests loading a circuit with the one-qubit parametrized operations supported by PennyLane."""

Expand Down
17 changes: 17 additions & 0 deletions tests/test_inverses.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TestInverses:
("Hadamard", 0),
("S", 1),
("T", 1),
("SX", 0)
],
)
def test_supported_gate_inverse_single_wire_no_parameters(self, name, expected_output):
Expand Down Expand Up @@ -253,3 +254,19 @@ def circuit():
return qml.expval(qml.PauliX(0))

assert np.allclose(circuit(), expected_output, atol=tol, rtol=0)

@pytest.mark.parametrize("par", [np.pi / i for i in range(1, 5)])
def test_sx_gate_inverses(self, par):
"""Tests the inverse of the SX gate"""

dev = qml.device("qiskit.aer", method="statevector", wires=2, shots=None)

expected_output = math.sin(par)

@qml.qnode(dev)
def circuit():
qml.RY(par, wires=[0])
qml.SX(wires=[0]).inv()
return qml.expval(qml.PauliX(0))

assert np.allclose(circuit(), expected_output, atol=tol, rtol=0)

0 comments on commit fa7bd95

Please sign in to comment.