Skip to content

Commit

Permalink
Make SimplifyInitial opt in (#48)
Browse files Browse the repository at this point in the history
* remove SimplifyInitial from default_compilation_pass

* update docstring for process_circuits

* add simplify_initial kwarg

* update xcirc

* update changelog

* make suggested changes
  • Loading branch information
CalMacCQ authored Dec 11, 2023
1 parent 24d50e5 commit 4b4358f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
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
----------

* Don’t include :py:class:`SimplifyInitial` in default passes; instead make it an option to ``process_circuits()``.

0.31.0 (November 2023)
----------------------

Expand Down
27 changes: 19 additions & 8 deletions pytket/extensions/pyquil/backends/forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,8 @@ def default_compilation_pass(self, optimisation_level: int = 2) -> BasePass:
passlist.append(SynthesiseTket())
passlist.append(self.rebase_pass())
if optimisation_level > 0:
passlist.extend(
[
EulerAngleReduction(OpType.Rx, OpType.Rz),
SimplifyInitial(
allow_classical=False, create_all_qubits=True, xcirc=_xcirc
),
]
passlist.append(
EulerAngleReduction(OpType.Rx, OpType.Rz),
)
return SequencePass(passlist)

Expand All @@ -193,7 +188,15 @@ def process_circuits(
) -> List[ResultHandle]:
"""
See :py:meth:`pytket.backends.Backend.process_circuits`.
Supported kwargs: `seed`.
Supported kwargs:
* `seed`
* `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 @@ -204,6 +207,7 @@ def process_circuits(
self._check_all_circuits(circuits)

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

handle_list = []
for circuit, n_shots in zip(circuits, n_shots_list):
Expand All @@ -212,6 +216,13 @@ def process_circuits(
ppcirc_rep = ppcirc.to_dict()
else:
c0, ppcirc_rep = circuit, None

if simplify_initial:
_x_circ = Circuit(1).Rx(1, 0)
SimplifyInitial(
allow_classical=False, create_all_qubits=True, xcirc=_x_circ
).apply(circuit)

p, bits = tk_to_pyquil(c0, return_used_bits=True)
p.wrap_in_numshots_loop(n_shots)
ex = self._qc.compiler.native_quil_to_executable(p)
Expand Down

0 comments on commit 4b4358f

Please sign in to comment.