Skip to content

Commit

Permalink
[feature] Make SimplifyInitial opt-in (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Oct 5, 2023
1 parent c8b37a0 commit b4cb5e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
------------

* Add simple automatic placement and routing for multi-zone architectures
* Don't include ``SimplifyInitial`` in default passes; instead make it an option
to ``process_circuits()``.


0.29.0rc0 (July 2023)
---------------------
Expand Down
19 changes: 12 additions & 7 deletions pytket/extensions/aqt/backends/aqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ def default_compilation_pass(self, optimisation_level: int = 2) -> BasePass:
FlattenRegisters(),
RenameQubitsPass(self._qm),
self.rebase_pass(),
SimplifyInitial(
allow_classical=False, create_all_qubits=True, xcirc=_xcirc
),
EulerAngleReduction(OpType.Ry, OpType.Rx),
]
)
Expand All @@ -230,9 +227,6 @@ def default_compilation_pass(self, optimisation_level: int = 2) -> BasePass:
FlattenRegisters(),
RenameQubitsPass(self._qm),
self.rebase_pass(),
SimplifyInitial(
allow_classical=False, create_all_qubits=True, xcirc=_xcirc
),
EulerAngleReduction(OpType.Ry, OpType.Rx),
]
)
Expand All @@ -250,7 +244,13 @@ def process_circuits(
) -> List[ResultHandle]:
"""
See :py:meth:`pytket.backends.Backend.process_circuits`.
Supported kwargs: none.
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)
n_shots_list = Backend._get_n_shots_as_list(
Expand All @@ -263,6 +263,7 @@ def process_circuits(
self._check_all_circuits(circuits)

postprocess = kwargs.get("postprocess", False)
simplify_initial = kwargs.get("postprocess", False)

handles = []
for i, (c, n_shots) in enumerate(zip(circuits, n_shots_list)):
Expand All @@ -271,6 +272,10 @@ def process_circuits(
ppcirc_rep = ppcirc.to_dict()
else:
c0, ppcirc_rep = c, None
if simplify_initial:
SimplifyInitial(
allow_classical=False, create_all_qubits=True, xcirc=_xcirc
).apply(c0)
(aqt_circ, measures) = _translate_aqt(c0)
if self._MACHINE_DEBUG:
handles.append(
Expand Down
11 changes: 0 additions & 11 deletions pytket/extensions/aqt/backends/aqt_multi_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
from pytket.passes import FullPeepholeOptimise
from pytket.passes import RenameQubitsPass
from pytket.passes import SequencePass
from pytket.passes import SimplifyInitial
from pytket.passes import SynthesiseTket
from pytket.predicates import GateSetPredicate
from pytket.predicates import MaxNQubitsPredicate
Expand Down Expand Up @@ -200,9 +199,6 @@ def default_compilation_pass(self, optimisation_level: int = 2) -> SequencePass:
FlattenRegisters(),
RenameQubitsPass(self._qm),
self.rebase_pass(),
SimplifyInitial(
allow_classical=False, create_all_qubits=True, xcirc=_xcirc
),
EulerAngleReduction(OpType.Ry, OpType.Rx),
]
)
Expand All @@ -214,9 +210,6 @@ def default_compilation_pass(self, optimisation_level: int = 2) -> SequencePass:
FlattenRegisters(),
RenameQubitsPass(self._qm),
self.rebase_pass(),
SimplifyInitial(
allow_classical=False, create_all_qubits=True, xcirc=_xcirc
),
EulerAngleReduction(OpType.Ry, OpType.Rx),
]
)
Expand Down Expand Up @@ -495,7 +488,3 @@ def swap_position(qubit_1_: int, qubit_2_: int) -> None:

def _aqt_rebase() -> BasePass:
return auto_rebase_pass({OpType.XXPhase, OpType.Rx, OpType.Ry})


_xcirc = Circuit(1).Rx(1, 0)
_xcirc.add_phase(0.5)

0 comments on commit b4cb5e5

Please sign in to comment.