diff --git a/docs/changelog.rst b/docs/changelog.rst index d725cb25..70b7ee80 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,11 +2,12 @@ Changelog ~~~~~~~~~ -0.44.0 (Unreleased) -------------------- +Unreleased +---------- * Implement crosstalk noise model for AerBackend. - +* Don't include ``SimplifyInitial`` in default passes; instead make it an option + to ``process_circuits()``. 0.44.0 (September 2023) ----------------------- diff --git a/docs/intro.txt b/docs/intro.txt index b256d0f5..64d50456 100644 --- a/docs/intro.txt +++ b/docs/intro.txt @@ -170,22 +170,17 @@ Every :py:class:`Backend` in pytket has its own ``default_compilation_pass`` met - self.rebase_pass [2] - `SynthesiseTket `_ * - - - `SimplifyInitial `_ [4] - self.rebase_pass [2] * - - - `RemoveRedundancies `_ - * - - - - - `SimplifyInitial `_ [4] * [1] If no value is specified then ``optimisation_level`` defaults to a value of 2. * [2] self.rebase_pass is a rebase to the gateset supported by the backend, For IBM quantum devices that is {X, SX, Rz, CX}. * [3] Here :py:class:`CXMappingPass` maps program qubits to the architecture using a `NoiseAwarePlacement `_ -* [4] :py:class:`SimplifyInitial` has arguments ``allow_classical=False`` and ``create_all_qubits=True``. -**Note:** The ``default_compilation_pass`` for :py:class:`AerBackend` is the same as above except it doesn't use :py:class:`SimplifyInitial`. +**Note:** The ``default_compilation_pass`` for :py:class:`AerBackend` is the same as above. Backend Predicates diff --git a/pytket/extensions/qiskit/backends/ibm.py b/pytket/extensions/qiskit/backends/ibm.py index 5db91cd0..f2090074 100644 --- a/pytket/extensions/qiskit/backends/ibm.py +++ b/pytket/extensions/qiskit/backends/ibm.py @@ -428,10 +428,6 @@ def default_compilation_pass( if self._supports_rz: passlist.extend([self.rebase_pass(), RemoveRedundancies()]) - if optimisation_level > 0: - passlist.append( - SimplifyInitial(allow_classical=False, create_all_qubits=True) - ) return SequencePass(passlist) @property @@ -451,7 +447,13 @@ def process_circuits( ) -> List[ResultHandle]: """ See :py:meth:`pytket.backends.Backend.process_circuits`. - Supported kwargs: `postprocess`. + + Supported `kwargs`: + - `postprocess`: apply end-of-circuit simplifications and classical + postprocessing to improve fidelity of results (bool, default False) + - `simplify_initial`: apply the pytket ``SimplifyInitial`` pass to improve + fidelity of results assuming all qubits initialized to zero (bool, default + False) """ circuits = list(circuits) @@ -464,6 +466,9 @@ def process_circuits( handle_list: List[Optional[ResultHandle]] = [None] * len(circuits) circuit_batches, batch_order = _batch_circuits(circuits, n_shots_list) + postprocess = kwargs.get("postprocess", False) + simplify_initial = kwargs.get("simplify_initial", False) + batch_id = 0 # identify batches for debug purposes only for (n_shots, batch), indices in zip(circuit_batches, batch_order): for chunk in itertools.zip_longest( @@ -475,8 +480,6 @@ def process_circuits( if valid_check: self._check_all_circuits(batch_chunk) - postprocess = kwargs.get("postprocess", False) - qcs, ppcirc_strs = [], [] for tkc in batch_chunk: if postprocess: @@ -484,6 +487,10 @@ def process_circuits( ppcirc_rep = ppcirc.to_dict() else: c0, ppcirc_rep = tkc, None + if simplify_initial: + SimplifyInitial( + allow_classical=False, create_all_qubits=True + ).apply(c0) qcs.append(tk_to_qiskit(c0)) ppcirc_strs.append(json.dumps(ppcirc_rep)) if self._MACHINE_DEBUG: diff --git a/tests/backend_test.py b/tests/backend_test.py index f9dc3f29..1d10da3c 100644 --- a/tests/backend_test.py +++ b/tests/backend_test.py @@ -1035,10 +1035,6 @@ def test_compilation_correctness(perth_backend: IBMQBackend) -> None: m_ini = lift_perm(ini) m_inv_fin = lift_perm(inv_fin) - # Note that we do not expect unitary equivalence, because the pass includes - # SimplifyInitial which may remove initial gates that do not affect the final - # result. However the first columns of the unitaries (i.e. the final - # statevectors arising from an initial all-zero state) should match. assert compare_statevectors(u[:, 0], (m_inv_fin @ compiled_u @ m_ini)[:, 0])