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

Add AnnotatedOperation.params and fix some control issues #12752

Merged
merged 10 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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: 2 additions & 4 deletions qiskit/circuit/annotated_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def params(self, value: list[ParameterValueType]):
if hasattr(self.base_op, "params"):
self.base_op.params = value
else:
raise NotImplementedError(
raise AttributeError(
f"Cannot set attribute ``params`` on the base operation {self.base_op}."
)

Expand All @@ -239,9 +239,7 @@ def validate_parameter(self, parameter: ParameterValueType) -> ParameterValueTyp
if hasattr(self.base_op, "validate_parameter"):
return self.base_op.validate_parameter(parameter)

raise NotImplementedError(
f"Cannot set validate parameters on the base operation {self.base_op}."
)
raise AttributeError(f"Cannot validate parameters on the base operation {self.base_op}.")


def _canonicalize_modifiers(modifiers):
Expand Down
6 changes: 5 additions & 1 deletion qiskit/circuit/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ def control(
ctrl_state: the control state in decimal or as a bitstring
(e.g. ``'111'``). If ``None``, use ``2**num_ctrl_qubits-1``.
annotated: indicates whether the controlled gate is implemented
as an annotated gate. If ``None``, this is handled as ``False``.
as an annotated gate. If ``None``, this is set to ``False``,
if the controlled gate can directly be constructed, and otherwise
set to ``True``. This allows defering the construction process in case the
synthesis of the controlled gate requires more information (e.g.
values of unbound parameters).
Cryoris marked this conversation as resolved.
Show resolved Hide resolved

Returns:
Controlled version of the given operation.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/generalized_gates/unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def control(
label: Optional gate label.
ctrl_state: The control state in decimal or as a bit string (e.g. ``"1011"``).
If ``None``, use ``2**num_ctrl_qubits - 1``.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/h.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down
6 changes: 3 additions & 3 deletions qiskit/circuit/library/standard_gates/p.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down Expand Up @@ -264,7 +264,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down Expand Up @@ -405,7 +405,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down
8 changes: 4 additions & 4 deletions qiskit/circuit/library/standard_gates/rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
as an annotated gate. If ``None``, this is set to ``False``, unless the
gate contains free parameters and has more than one control qubit,
in which case it cannot yet be synthesized.
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters and more than one control qubit, in which
case it cannot yet be synthesized. Otherwise it is set to ``False``.

Returns:
ControlledGate: controlled version of this gate.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/rxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters, in which case it cannot
yet be synthesized.
Expand Down
8 changes: 4 additions & 4 deletions qiskit/circuit/library/standard_gates/ry.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
as an annotated gate. If ``None``, this is set to ``False``, unless the
gate contains free parameters and has more than one control qubit,
in which case it cannot yet be synthesized.
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters and more than one control qubit, in which
case it cannot yet be synthesized. Otherwise it is set to ``False``.

Returns:
ControlledGate: controlled version of this gate.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/ryy.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters, in which case it cannot
yet be synthesized.
Expand Down
8 changes: 4 additions & 4 deletions qiskit/circuit/library/standard_gates/rz.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
as an annotated gate. If ``None``, this is set to ``False``, unless the
gate contains free parameters and has more than one control qubit,
in which case it cannot yet be synthesized.
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters and more than one control qubit, in which
case it cannot yet be synthesized. Otherwise it is set to ``False``.

Returns:
ControlledGate: controlled version of this gate.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/rzx.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters, in which case it cannot
yet be synthesized.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/rzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters, in which case it cannot
yet be synthesized.
Expand Down
4 changes: 2 additions & 2 deletions qiskit/circuit/library/standard_gates/s.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down Expand Up @@ -213,7 +213,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/sx.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is handled as ``False``.

Returns:
Expand Down
8 changes: 4 additions & 4 deletions qiskit/circuit/library/standard_gates/u.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
as an annotated gate. If ``None``, this is set to ``False``, unless the
gate contains free parameters and has more than one control qubit,
in which case it cannot yet be synthesized.
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters and more than one control qubit, in which
case it cannot yet be synthesized. Otherwise it is set to ``False``.

Returns:
ControlledGate: controlled version of this gate.
Expand Down
6 changes: 3 additions & 3 deletions qiskit/circuit/library/standard_gates/u1.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down Expand Up @@ -278,7 +278,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down Expand Up @@ -410,7 +410,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down
8 changes: 4 additions & 4 deletions qiskit/circuit/library/standard_gates/u3.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
as an annotated gate. If ``None``, this is set to ``False``, unless the
gate contains free parameters and has more than one control qubit,
in which case it cannot yet be synthesized.
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters and more than one control qubit, in which
case it cannot yet be synthesized. Otherwise it is set to ``False``.

Returns:
ControlledGate: controlled version of this gate.
Expand Down
12 changes: 6 additions & 6 deletions qiskit/circuit/library/standard_gates/x.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down Expand Up @@ -257,7 +257,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down Expand Up @@ -453,7 +453,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down Expand Up @@ -801,7 +801,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down Expand Up @@ -1222,7 +1222,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g. ``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/xx_minus_yy.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters, in which case it cannot
yet be synthesized.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/xx_plus_yy.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate. If ``None``, this is set to ``True`` if
the gate contains free parameters, in which case it cannot
yet be synthesized.
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/y.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/standard_gates/z.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def control(
label: An optional label for the gate [Default: ``None``]
ctrl_state: control state expressed as integer,
string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ def control(
label (str): An optional label to give the controlled operation for visualization.
ctrl_state (str or int): The control state in decimal or as a bitstring
(e.g. '111'). If None, use ``2**num_ctrl_qubits - 1``.
annotated: indicates whether the controlled gate can be implemented
annotated: indicates whether the controlled gate should be implemented
as an annotated gate.

Returns:
Expand Down
Loading
Loading