Skip to content

Commit

Permalink
[feature] Make SimplifyInitial opt-in (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Oct 5, 2023
1 parent a8b6a9b commit f02027f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
7 changes: 4 additions & 3 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-----------------------
Expand Down
7 changes: 1 addition & 6 deletions docs/intro.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,17 @@ Every :py:class:`Backend` in pytket has its own ``default_compilation_pass`` met
- self.rebase_pass [2]
- `SynthesiseTket <https://cqcl.github.io/tket/pytket/api/passes.html#pytket.passes.SynthesiseTket>`_
* -
- `SimplifyInitial <https://cqcl.github.io/tket/pytket/api/passes.html#pytket.passes.SimplifyInitial>`_ [4]
- self.rebase_pass [2]
* -
-
- `RemoveRedundancies <https://cqcl.github.io/tket/pytket/api/passes.html#pytket.passes.RemoveRedundancies>`_
* -
-
- `SimplifyInitial <https://cqcl.github.io/tket/pytket/api/passes.html#pytket.passes.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 <https://cqcl.github.io/tket/pytket/api/placement.html#pytket.placement.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
Expand Down
21 changes: 14 additions & 7 deletions pytket/extensions/qiskit/backends/ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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(
Expand All @@ -475,15 +480,17 @@ 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:
c0, ppcirc = prepare_circuit(tkc, allow_classical=False)
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:
Expand Down
4 changes: 0 additions & 4 deletions tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])


Expand Down

0 comments on commit f02027f

Please sign in to comment.