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

Support barriers in Aer simulators #192

Merged
merged 5 commits into from
Oct 26, 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
~~~~~~~~~

unreleased
----------

* Add support for circuits with barriers in the Aer simulators.

0.45.0 (October 2023)
---------------------

Expand Down
3 changes: 3 additions & 0 deletions pytket/extensions/qiskit/backends/aer.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def _tket_gate_set_from_qiskit_backend(
for gate_str in config.basis_gates
if gate_str in _gate_str_2_optype
}

gate_set.add(OpType.Barrier)

if "unitary" in config.basis_gates:
gate_set.add(OpType.Unitary1qBox)
gate_set.add(OpType.Unitary2qBox)
Expand Down
28 changes: 27 additions & 1 deletion tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
get_operator_expectation_value,
)
from pytket.utils.operators import QubitPauliOperator
from pytket.utils.results import compare_statevectors
from pytket.utils.results import compare_statevectors, compare_unitaries

skip_remote_tests: bool = os.getenv("PYTKET_RUN_REMOTE_TESTS") is None

Expand Down Expand Up @@ -1403,3 +1403,29 @@ def test_unitary_backend_transpiles() -> None:
# check that the lower-right 2x2 submatrix of the unitary is the matrix of
# the X gate.
assert np.isclose(u[62:64, 62:64], np.asarray(([0.0, 1.0], [1.0, 0.0]))).all()


def test_barriers_in_aer_simulators() -> None:
"""Test for barrier support in aer simulators
https://github.com/CQCL/pytket-qiskit/issues/186"""

circ = Circuit(2).H(0).CX(0, 1).add_barrier([0, 1])

state_backend = AerStateBackend()
shots_backend = AerBackend()
unitary_backend = AerUnitaryBackend()

test_state = circ.get_statevector()
test_unitary = circ.get_unitary()

backends = (state_backend, unitary_backend, shots_backend)

for backend in backends:
assert OpType.Barrier in backend.backend_info.gate_set
assert backend.valid_circuit(circ)

state_result = state_backend.run_circuit(circ).get_state()
unitary_result = unitary_backend.run_circuit(circ).get_unitary()

assert compare_statevectors(test_state, state_result)
assert compare_unitaries(test_unitary, unitary_result)