Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auxiliary qubit tracking in HighLevelSynthesis #12911

Merged
merged 7 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions qiskit/circuit/add_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def control(
gate.definition.data[0].operation.params[0],
q_control,
q_target[bit_indices[qargs[0]]],
use_basis_gates=True,
use_basis_gates=False,
)
elif gate.name == "ry":
controlled_circ.mcry(
Expand All @@ -146,14 +146,14 @@ def control(
q_target[bit_indices[qargs[0]]],
q_ancillae,
mode="noancilla",
use_basis_gates=True,
use_basis_gates=False,
)
elif gate.name == "rz":
controlled_circ.mcrz(
gate.definition.data[0].operation.params[0],
q_control,
q_target[bit_indices[qargs[0]]],
use_basis_gates=True,
use_basis_gates=False,
)
continue
elif gate.name == "p":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _mcsu2_real_diagonal(
circuit.h(target)

if use_basis_gates:
circuit = transpile(circuit, basis_gates=["p", "u", "cx"])
circuit = transpile(circuit, basis_gates=["p", "u", "cx"], qubits_initially_zero=False)

return circuit

Expand Down
3 changes: 2 additions & 1 deletion qiskit/circuit/library/standard_gates/p.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ def _define(self):
q_target = self.num_ctrl_qubits
new_target = q_target
for k in range(self.num_ctrl_qubits):
qc.mcrz(lam / (2**k), q_controls, new_target, use_basis_gates=True)
# Note: it's better *not* to run transpile recursively
qc.mcrz(lam / (2**k), q_controls, new_target, use_basis_gates=False)
new_target = q_controls.pop()
qc.p(lam / (2**self.num_ctrl_qubits), new_target)
else: # in this case type(lam) is ParameterValueType
Expand Down
3 changes: 3 additions & 0 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def transpile( # pylint: disable=too-many-return-statements
optimization_method: Optional[str] = None,
ignore_backend_supplied_default_methods: bool = False,
num_processes: Optional[int] = None,
qubits_initially_zero: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we talked about the variable naming earlier today. This works well, but if you want to try out a shorter name, I think qubits_zeroed works here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice idea, or maybe qubits_reset if we want to avoid the "zero" 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, I like that suggestion. It is clear and avoids any confusion with the term "zero" :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, personally I like the current name qubits_initially_zero a bit more than qubits_reset or qubits_zeroed since it's more clear what it means.

) -> _CircuitT:
"""Transpile one or more circuits, according to some desired transpilation targets.

Expand Down Expand Up @@ -284,6 +285,7 @@ def callback_func(**kwargs):
``num_processes`` in the user configuration file, and the ``QISKIT_NUM_PROCS``
environment variable. If set to ``None`` the system default or local user configuration
will be used.
qubits_initially_zero: Indicates whether the input circuit is zero-initialized.

Returns:
The transpiled circuit(s).
Expand Down Expand Up @@ -386,6 +388,7 @@ def callback_func(**kwargs):
init_method=init_method,
optimization_method=optimization_method,
dt=dt,
qubits_initially_zero=qubits_initially_zero,
)

out_circuits = pm.run(circuits, callback=callback, num_processes=num_processes)
Expand Down
4 changes: 3 additions & 1 deletion qiskit/synthesis/unitary/qsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ def _apply_a2(circ):
from qiskit.circuit.library.generalized_gates.unitary import UnitaryGate

decomposer = two_qubit_decompose_up_to_diagonal
ccirc = transpile(circ, basis_gates=["u", "cx", "qsd2q"], optimization_level=0)
ccirc = transpile(
circ, basis_gates=["u", "cx", "qsd2q"], optimization_level=0, qubits_initially_zero=False
)
ind2q = []
# collect 2q instrs
for i, instruction in enumerate(ccirc.data):
Expand Down
Loading
Loading