Phase and Reflection Operators

Phase and reflection operators implement conditional phase flips, global phases, Grover reflections and similar operations, and are widely used in quantum search and amplitude amplification algorithms. A complete Grover search implementation is available in the algorithm library.

Overview

Phase operators overview

Operator

Operation

Unitarity class

ZeroConditionalPhaseFlip

Flip the phase when the specified registers are all zero

SelfAdjoint

Reflection_Bool

Reflection about the |0⟩ state (Grover diffusion)

SelfAdjoint

GlobalPhase

Multiply by a complex global phase factor

BaseOperator

—

ZeroConditionalPhaseFlip (zero-conditional phase flip)

class pysparq.ZeroConditionalPhaseFlip
clear_control_all_ones(self: pysparq._core.ZeroConditionalPhaseFlip) → None

Clear all control conditions of the specified type.

clear_control_by_bit(self: pysparq._core.ZeroConditionalPhaseFlip) → None

Clear all control conditions of the specified type.

clear_control_by_value(self: pysparq._core.ZeroConditionalPhaseFlip) → None

Clear all control conditions of the specified type.

clear_control_nonzeros(self: pysparq._core.ZeroConditionalPhaseFlip) → None

Clear all control conditions of the specified type.

property condition_variable_all_ones
property condition_variable_by_bit
property condition_variable_by_value
property condition_variable_nonzeros
conditioned_by_all_ones(*args, **kwargs)

Overloaded function.

  1. conditioned_by_all_ones(self: pysparq._core.ZeroConditionalPhaseFlip, cond: str) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.ZeroConditionalPhaseFlip, conds: collections.abc.Sequence[str]) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.ZeroConditionalPhaseFlip, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.ZeroConditionalPhaseFlip, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

conditioned_by_bit(*args, **kwargs)

Overloaded function.

  1. conditioned_by_bit(self: pysparq._core.ZeroConditionalPhaseFlip, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.ZeroConditionalPhaseFlip, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.ZeroConditionalPhaseFlip, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.ZeroConditionalPhaseFlip, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

conditioned_by_nonzeros(*args, **kwargs)

Overloaded function.

  1. conditioned_by_nonzeros(self: pysparq._core.ZeroConditionalPhaseFlip, cond: str) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.ZeroConditionalPhaseFlip, conds: collections.abc.Sequence[str]) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.ZeroConditionalPhaseFlip, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.ZeroConditionalPhaseFlip, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

conditioned_by_value(*args, **kwargs)

Overloaded function.

  1. conditioned_by_value(self: pysparq._core.ZeroConditionalPhaseFlip, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.ZeroConditionalPhaseFlip, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.ZeroConditionalPhaseFlip, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.ZeroConditionalPhaseFlip, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.ZeroConditionalPhaseFlip

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

Operation: Applies a \(-1\) phase flip to the basis states when all of the specified registers have value zero.

Parameters: A list of register identifiers (list of names or list of IDs).

Mathematical representation:

\[\begin{split}|x_1, x_2, \ldots, x_n\rangle \rightarrow \begin{cases} -|x_1, x_2, \ldots, x_n\rangle & \text{if } x_1 = x_2 = \cdots = x_n = 0 \\ |x_1, x_2, \ldots, x_n\rangle & \text{otherwise} \end{cases}\end{split}\]

Purpose: Building the Oracle in Grover’s algorithm. When the target state is |0...0⟩, this operator is exactly the phase Oracle.

import pysparq as ps

ps.System.clear()
ps.System.add_register("addr", ps.UnsignedInteger, 3)
ps.System.add_register("data", ps.UnsignedInteger, 4)

state = ps.SparseState()
ps.Hadamard_Int("addr", 3)(state)
# After loading, flip the phase when the data corresponding to addr is 0
ps.ZeroConditionalPhaseFlip(["data"])(state)

# A list of register names also works
ps.ZeroConditionalPhaseFlip(["addr", "data"])(state)

—

Reflection_Bool (reflection)

class pysparq.Reflection_Bool
clear_control_all_ones(self: pysparq._core.Reflection_Bool) → None

Clear all control conditions of the specified type.

clear_control_by_bit(self: pysparq._core.Reflection_Bool) → None

Clear all control conditions of the specified type.

clear_control_by_value(self: pysparq._core.Reflection_Bool) → None

Clear all control conditions of the specified type.

clear_control_nonzeros(self: pysparq._core.Reflection_Bool) → None

Clear all control conditions of the specified type.

property condition_variable_all_ones
property condition_variable_by_bit
property condition_variable_by_value
property condition_variable_nonzeros
conditioned_by_all_ones(*args, **kwargs)

Overloaded function.

  1. conditioned_by_all_ones(self: pysparq._core.Reflection_Bool, cond: str) -> pysparq._core.Reflection_Bool

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.Reflection_Bool, conds: collections.abc.Sequence[str]) -> pysparq._core.Reflection_Bool

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.Reflection_Bool, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Reflection_Bool

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.Reflection_Bool, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Reflection_Bool

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

conditioned_by_bit(*args, **kwargs)

Overloaded function.

  1. conditioned_by_bit(self: pysparq._core.Reflection_Bool, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Reflection_Bool

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.Reflection_Bool, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Reflection_Bool

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.Reflection_Bool, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Reflection_Bool

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.Reflection_Bool, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Reflection_Bool

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

conditioned_by_nonzeros(*args, **kwargs)

Overloaded function.

  1. conditioned_by_nonzeros(self: pysparq._core.Reflection_Bool, cond: str) -> pysparq._core.Reflection_Bool

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.Reflection_Bool, conds: collections.abc.Sequence[str]) -> pysparq._core.Reflection_Bool

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.Reflection_Bool, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Reflection_Bool

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.Reflection_Bool, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Reflection_Bool

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

conditioned_by_value(*args, **kwargs)

Overloaded function.

  1. conditioned_by_value(self: pysparq._core.Reflection_Bool, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Reflection_Bool

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.Reflection_Bool, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Reflection_Bool

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.Reflection_Bool, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Reflection_Bool

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.Reflection_Bool, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Reflection_Bool

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

Operation: Reflection about the |0⟩ state, i.e. the core component of the Grover diffusion operator.

Parameters:

  • reg — target register (name or ID, or a list)

  • inverse — whether to use the inverse reflection (optional, default False)

Mathematical representation:

\[R = 2|0\rangle\langle 0| - I\]

Purpose: The diffusion operator in Grover’s algorithm is composed of Hadamard + Reflection + Hadamard.

ps.System.clear()
ps.System.add_register("q", ps.Boolean, 1)

state = ps.SparseState()
ps.Hadamard_Bool("q")(state)

# Reflection
ps.Reflection_Bool("q")(state)

—

GlobalPhase (global phase)

class pysparq.GlobalPhase
clear_control_all_ones(self: pysparq._core.GlobalPhase) → None

Clear all control conditions of the specified type.

clear_control_by_bit(self: pysparq._core.GlobalPhase) → None

Clear all control conditions of the specified type.

clear_control_by_value(self: pysparq._core.GlobalPhase) → None

Clear all control conditions of the specified type.

clear_control_nonzeros(self: pysparq._core.GlobalPhase) → None

Clear all control conditions of the specified type.

property condition_variable_all_ones
property condition_variable_by_bit
property condition_variable_by_value
property condition_variable_nonzeros
conditioned_by_all_ones(*args, **kwargs)

Overloaded function.

  1. conditioned_by_all_ones(self: pysparq._core.GlobalPhase, cond: str) -> pysparq._core.GlobalPhase

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.GlobalPhase, conds: collections.abc.Sequence[str]) -> pysparq._core.GlobalPhase

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.GlobalPhase, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.GlobalPhase

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

  1. conditioned_by_all_ones(self: pysparq._core.GlobalPhase, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.GlobalPhase

Condition this operation on registers where all bits are 1.

Calling this method replaces prior all-ones conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

conditioned_by_bit(*args, **kwargs)

Overloaded function.

  1. conditioned_by_bit(self: pysparq._core.GlobalPhase, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.GlobalPhase

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.GlobalPhase, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.GlobalPhase

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.GlobalPhase, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.GlobalPhase

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_bit(self: pysparq._core.GlobalPhase, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.GlobalPhase

Condition this operation on a specific bit position.

Calling this method replaces prior bit conditions. Pass the list-of-pairs overload to require several bits simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Bit position to check (0-indexed).

  • conds – List of (register, position) pairs.

Returns:

Self, for method chaining.

conditioned_by_nonzeros(*args, **kwargs)

Overloaded function.

  1. conditioned_by_nonzeros(self: pysparq._core.GlobalPhase, cond: str) -> pysparq._core.GlobalPhase

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.GlobalPhase, conds: collections.abc.Sequence[str]) -> pysparq._core.GlobalPhase

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.GlobalPhase, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.GlobalPhase

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

  1. conditioned_by_nonzeros(self: pysparq._core.GlobalPhase, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.GlobalPhase

Condition this operation on registers with nonzero values.

Calling this method replaces prior nonzero-register conditions. Pass the list overload to require several registers simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int) to condition on.

  • conds – List of register names or IDs for multi-condition.

Returns:

Self, for method chaining.

Example

op.conditioned_by_nonzeros(‘control_reg’)(state)

conditioned_by_value(*args, **kwargs)

Overloaded function.

  1. conditioned_by_value(self: pysparq._core.GlobalPhase, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.GlobalPhase

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.GlobalPhase, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.GlobalPhase

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.GlobalPhase, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.GlobalPhase

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

  1. conditioned_by_value(self: pysparq._core.GlobalPhase, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.GlobalPhase

Condition this operation on registers holding a specific value.

Calling this method replaces prior value conditions. Pass the list-of-pairs overload to require several values simultaneously; conditions of different kinds are combined with logical AND.

Parameters:
  • cond – Register name (str) or ID (int).

  • pos – Value to match.

  • conds – List of (register, value) pairs.

Returns:

Self, for method chaining.

Operation: Multiplies the entire quantum state by a complex global phase factor.

Parameters: c — the complex phase factor.

Dagger: Multiplies by the complex conjugate.

Note: A global phase is unobservable in quantum mechanics, but in some algorithms (such as amplitude encoding, QDA) it must be tracked exactly.

import numpy as np

# Global phase rotation e^{iπ/4}
op = ps.GlobalPhase(np.exp(1j * np.pi / 4))
op(state)

# Undo
op.dag(state)