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

fix directed ECR gate #318

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Unreleased
----------

* Add `IBMQBackend.default_compilation_pass_static` for offline compilation given config and props objects.
* Add `DirectednessPredicate` to IBMQBackend
* Default compilationpass of IBMQBackend will keep ECR gates in the direction required by the backend.
cqc-melf marked this conversation as resolved.
Show resolved Hide resolved

0.51.1rc0 (April 2024)
----------------------
Expand Down
10 changes: 8 additions & 2 deletions pytket/extensions/qiskit/backends/ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@
NoFastFeedforwardPredicate,
MaxNQubitsPredicate,
Predicate,
DirectednessPredicate,
)
from qiskit.providers.models import BackendProperties, QasmBackendConfiguration # type: ignore

from ..qiskit_convert import tk_to_qiskit, _tk_gate_set
from pytket.architecture import FullyConnected
from pytket.architecture import FullyConnected, Architecture
from pytket.placement import NoiseAwarePlacement
from pytket.utils import prepare_circuit
from pytket.utils.outcomearray import OutcomeArray
Expand Down Expand Up @@ -346,6 +347,11 @@ def required_predicates(self) -> List[Predicate]:
)
),
]
if type(self.backend_info.architecture) == Architecture:
cqc-melf marked this conversation as resolved.
Show resolved Hide resolved
predicates = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not append it to the end (saves constructing a new list).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 0dac35a

I have updated that for the lines below as well.

DirectednessPredicate(self.backend_info.architecture),
] + predicates

mid_measure = self._backend_info.supports_midcircuit_measurement
fast_feedforward = self._backend_info.supports_fast_feedforward
if not mid_measure:
Expand Down Expand Up @@ -451,7 +457,7 @@ def default_compilation_pass_offline(
CXMappingPass(
arch,
noise_aware_placement,
directed_cx=False,
directed_cx=True,
delay_measures=(not mid_measure),
)
)
Expand Down
22 changes: 20 additions & 2 deletions tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ def test_machine_debug(brisbane_backend: IBMQBackend) -> None:
c = Circuit(2, 2).H(0).CX(0, 1).measure_all()
with pytest.raises(CircuitNotValidError) as errorinfo:
handles = backend.process_circuits([c, c.copy()], n_shots=2)
assert "in submitted does not satisfy GateSetPredicate" in str(errorinfo.value)
assert "in submitted does not satisfy DirectednessPredicate" in str(
errorinfo.value
)
c = backend.get_compiled_circuit(c)
handles = backend.process_circuits([c, c.copy()], n_shots=4)
from pytket.extensions.qiskit.backends.ibm import _DEBUG_HANDLE_PREFIX
Expand Down Expand Up @@ -476,7 +478,8 @@ def test_nshots(
circuit = Circuit(1).X(0)
circuit.measure_all()
n_shots = [1, 2, 3]
results = b.get_results(b.process_circuits([circuit] * 3, n_shots=n_shots))
circ_comp = b.get_compiled_circuit(circuit)
results = b.get_results(b.process_circuits([circ_comp] * 3, n_shots=n_shots))
assert [sum(r.get_counts().values()) for r in results] == n_shots


Expand Down Expand Up @@ -1330,6 +1333,21 @@ def test_crosstalk_noise_model() -> None:
res.get_counts()


@pytest.mark.skipif(skip_remote_tests, reason=REASON)
def test_ecr(ibm_brisbane_backend: IBMQBackend) -> None:
ghz5 = Circuit(5)
ghz5.H(0).CX(0, 1).CX(0, 2).CX(0, 3).CX(0, 4)
ghz5.measure_all()
ibm_ghz5 = ibm_brisbane_backend.get_compiled_circuit(ghz5)

compiled_ghz5 = ibm_brisbane_backend.get_compiled_circuit(ibm_ghz5)

ibm_brisbane_backend.valid_circuit(compiled_ghz5)

handle = ibm_brisbane_backend.process_circuit(compiled_ghz5, n_shots=1000)
ibm_brisbane_backend.cancel(handle)


# helper function for testing
def _get_qiskit_statevector(qc: QuantumCircuit) -> np.ndarray:
"""Given a QuantumCircuit, use aer_simulator_statevector to compute its
Expand Down