相位与反射算子

相位与反射算子实现条件相位翻转、全局相位和 Grover 反射等操作,广泛用于量子搜索和振幅放大算法。完整的 Grover 搜索实现见 算法库。

概述

相位算子总览

算子

操作

幺正类

ZeroConditionalPhaseFlip

指定寄存器全为零时翻转相位

SelfAdjoint

Reflection_Bool

关于 |0⟩ 态的反射(Grover 扩散)

SelfAdjoint

GlobalPhase

全局相位乘以复数因子

BaseOperator

---

ZeroConditionalPhaseFlip(零条件相位翻转)

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

Self, for method chaining.

操作: 当所有指定寄存器的值均为零时,对基态施加 \(-1\) 相位翻转。

参数: 寄存器标识列表(名称列表或 ID 列表)。

数学表示:

\[\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}\]

用途: 构造 Grover 算法中的 Oracle。当目标态为 |0...0⟩ 时,该算子即为相位 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)
# 加载后,当 addr 对应的 data 为 0 时翻转相位
ps.ZeroConditionalPhaseFlip(["data"])(state)

# 也可以用寄存器名称列表
ps.ZeroConditionalPhaseFlip(["addr", "data"])(state)

---

Reflection_Bool(反射)

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

Self, for method chaining.

操作: 关于 |0⟩ 态的反射操作,即 Grover 扩散算子中的核心组件。

参数:

  • reg — 目标寄存器(名称或 ID,或列表)

  • inverse — 是否使用逆反射(可选,默认 False)

数学表示:

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

用途: Grover 算法的扩散算子(Diffusion Operator)由 Hadamard + Reflection + Hadamard 组合而成。

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

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

# 反射操作
ps.Reflection_Bool("q")(state)

---

GlobalPhase(全局相位)

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

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

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int) to condition on.

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

返回:

Self, for method chaining.

示例

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

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.

参数:
  • cond -- Register name (str) or ID (int).

  • pos -- Value to match.

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

返回:

Self, for method chaining.

操作: 对整个量子态乘以一个复数全局相位因子。

参数: c — 复数相位因子。

Dagger: 乘以共轭复数。

注意: 全局相位在量子力学中不可观测,但在某些算法(如振幅编码、QDA)中需要精确追踪。

import numpy as np

# 全局相位旋转 e^{iπ/4}
op = ps.GlobalPhase(np.exp(1j * np.pi / 4))
op(state)

# 撤销
op.dag(state)