forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global-phase support to control-flow builders
This formalises the concept of global phase within control-flow scopes, and teaches the control-flow builders to treat modifications to the global phase as being conditional on the control-flow block being entered.
- Loading branch information
1 parent
c20356b
commit c4d4170
Showing
5 changed files
with
110 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
releasenotes/notes/fix-global-phase-control-flow-builders-38302f41302be928.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
fixes: | ||
- | | ||
The control-flow builder interface (the context-manager forms of | ||
:meth:`.QuantumCircuit.if_test`, :meth:`~.QuantumCircuit.while_loop`, | ||
:meth:`~.QuantumCircuit.for_loop` and :meth:`~.QuantumCircuit.switch`) will now correctly track | ||
a separate global-phase advancement within that block. You can add a global-phase advancement | ||
to an inner block by assigning to :attr:`.QuantumCircuit.global_phase` within a builder scope:: | ||
from math import pi | ||
from qiskit import QuantumCircuit | ||
qc = QuantumCircuit(3, 3) | ||
qc.global_phase = pi / 2 # Set the outer circuit's global phase. | ||
with qc.if_test((qc.clbits[0], False)) as else_: | ||
# The global phase advancement in a control-flow block begins at 0, | ||
# because it represents how much the phase will be advanced by an | ||
# execution of the block. The defined phase of the outer scope is not | ||
# affected by this set. | ||
qc.global_phase = pi | ||
with else_: | ||
# Similarly, the `else` block may induce a different global-phase | ||
# advancement to the `if`, so it can also be set separately. | ||
qc.global_phase = 1.5 * pi | ||
# The phase advancement caused directly by the outer scope is independent | ||
# of the phase advancement conditionally caused by each control-flow path. | ||
assert qc.global_phase == pi / 2 | ||
The meaning of :attr:`.QuantumCircuit.global_phase` is taken to be the global-phase advancement | ||
that is inherent to a single execution of the block. It is still a *global* phase advancement, | ||
in that if the block is entered, the phase of all qubits in the entire program will be advanced. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters