Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update gateset #37

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
~~~~~~~~~

0.31.0 (unreleased)
-------------------

* add pyquil.gates.XY to the native gateset

0.30.0 (October 2023)
---------------------

Expand Down
9 changes: 8 additions & 1 deletion pytket/extensions/pyquil/backends/forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ class ForestBackend(Backend):
_supports_counts = True
_supports_contextual_optimisation = True
_persistent_handles = True
_GATE_SET = {OpType.CZ, OpType.Rx, OpType.Rz, OpType.Measure, OpType.Barrier}
_GATE_SET = {
OpType.CZ,
OpType.Rx,
OpType.Rz,
OpType.Measure,
OpType.Barrier,
OpType.ISWAP,
}

def __init__(self, qc: QuantumComputer):
"""Backend for running circuits with the Rigetti QVM.
Expand Down
2 changes: 2 additions & 0 deletions tests/pyquil_convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
CPHASE,
SWAP,
MEASURE,
XY,
)
from pyquil.quilbase import Measurement
from sympy import pi, Symbol
Expand Down Expand Up @@ -78,6 +79,7 @@ def get_test_program(measure: bool = False) -> Program:
p += CCNOT(0, 1, 2)
p += CPHASE(PI / 4, 2, 1)
p += SWAP(0, 3)
p += XY(PI / 3, 2, 1)
if measure:
ro = p.declare("ro", "BIT", 4)
p += MEASURE(0, ro[0])
Expand Down
54 changes: 54 additions & 0 deletions tests/qvm_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,60 @@ def test_shots_bits_edgecases(qvm: None, quilc: None) -> None:
assert res.get_counts() == correct_counts


@pytest.mark.skipif(
skip_qvm_tests, reason="Can only run Rigetti QVM if docker is installed"
)
def test_gateset(qvm: None, quilc: None) -> None:
qc = get_qc("9q-square", as_qvm=True)
forest_backend = ForestBackend(qc)
a = [Qubit("node", i) for i in range(6)]

c = Circuit(0, 6)
for q in a:
c.add_qubit(q)
c.ISWAP(1, a[5], a[4])
c.ISWAP(2, a[5], a[4])
c.ISWAP(3, a[5], a[4])

c.measure_all()

h = forest_backend.process_circuit(c, 10)
res = forest_backend.get_result(h)

correct_shots = np.zeros((10, 6), dtype=int) # type: ignore
correct_counts = Counter({(0,) * 6: 10})

assert np.array_equal(res.get_shots(), correct_shots)
assert res.get_shots().shape == (10, 6)
assert res.get_counts() == correct_counts


@pytest.mark.skipif(
skip_qvm_tests, reason="Can only run Rigetti QVM if docker is installed"
)
def test_gateset_ii(qvm: None, quilc: None) -> None:
qc = get_qc("9q-square", as_qvm=True)
forest_backend = ForestBackend(qc)

a = [Qubit("node", i) for i in range(6)]
c = Circuit(0, 6)
for q in a:
c.add_qubit(q)
c.Rx(1.0, a[5])
c.ISWAP(0.5, a[5], a[4])
c.Rx(1.0, a[4])
c.ISWAP(0.5, a[5], a[4])
c.measure_all()

h = forest_backend.process_circuit(c, 10)
res = forest_backend.get_result(h)

assert res.get_shots().shape == (10, 6)
assert (
res.get_counts()[(0, 0, 0, 0, 0, 0)] + res.get_counts()[(0, 0, 0, 0, 1, 1)]
) == 10


@pytest.mark.skipif(
skip_qvm_tests, reason="Can only run Rigetti QVM if docker is installed"
)
Expand Down