Hadamard Operations

The Hadamard operators create quantum superpositions on registers and are fundamental operations in quantum algorithms. They are the standard way to prepare uniform superpositions, e.g. before QRAM queries; for the memory behaviour of full-register Hadamards on wide registers, see the performance notes in QFT.

Overview

Hadamard operators overview

Operator

Operation

Type constraint

Unitarity class

Hadamard_Int

Hadamard on an integer register

Integer type

SelfAdjoint

Hadamard_Int_Full

Full Hadamard (all output states)

Integer type

SelfAdjoint

Hadamard_Bool

Single-qubit Hadamard

Boolean (size=1)

SelfAdjoint

Hadamard_Partial

Partial-qubit Hadamard

Integer type

SelfAdjoint

—

Hadamard_Int

class pysparq.Hadamard_Int

Apply Hadamard transform to an integer register.

Creates an equal superposition over all integer values from 0 to 2^n - 1 for the specified number of digits.

Parameters:
  • reg_in – Name/ID of the input register.

  • n_digits – Number of digits (qubits) to apply Hadamard to.

Example

Hadamard_Int(“q”, 4)(state) # Superpose q over 0..15

clear_control_all_ones(self: pysparq._core.Hadamard_Int) → None

Clear all control conditions of the specified type.

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

Clear all control conditions of the specified type.

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

Clear all control conditions of the specified type.

clear_control_nonzeros(self: pysparq._core.Hadamard_Int) → 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.Hadamard_Int, cond: str) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, conds: collections.abc.Sequence[str]) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, cond: str) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, conds: collections.abc.Sequence[str]) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int

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.Hadamard_Int, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Int

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 Hadamard to the specified qubits of an integer register

Mathematical definition:

\[H|x\rangle = \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) \quad \text{for each qubit}\]

Type constraints: UnsignedInteger or SignedInteger

import pysparq as ps

ps.System.clear()

# 4-bit register
ps.System.add_register("q", ps.UnsignedInteger, 4)

state = ps.SparseState()
print("Initial state:")
ps.pprint(state)
# [1 basis state]
# |q=0⟩ : (1+0j)

# Apply Hadamard to the first 2 bits
ps.Hadamard_Int("q", 2)(state)

print("\nAfter Hadamard:")
ps.pprint(state)
# [2 basis states]
# |q=0⟩ : (0.707+0j)
# |q=2⟩ : (0.707+0j)

—

Hadamard_Int_Full

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

Clear all control conditions of the specified type.

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

Clear all control conditions of the specified type.

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

Clear all control conditions of the specified type.

clear_control_nonzeros(self: pysparq._core.Hadamard_Int_Full) → 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.Hadamard_Int_Full, cond: str) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, conds: collections.abc.Sequence[str]) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, cond: str) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, conds: collections.abc.Sequence[str]) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Int_Full

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.Hadamard_Int_Full, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Int_Full

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 full Hadamard to the entire register, creating a uniform superposition of all \(2^n\) states

Mathematical definition:

\[H^n|x\rangle = \frac{1}{\sqrt{2^n}}\sum_{y=0}^{2^n-1}|y\rangle\]

Type constraints: Integer type

Note: This creates \(2^n\) basis states; for large n this may cause memory problems.

ps.System.clear()

# 2-bit register
ps.System.add_register("q", ps.UnsignedInteger, 2)

state = ps.SparseState()

# Full Hadamard: creates 2^2 = 4 states
ps.Hadamard_Int_Full("q")(state)

ps.pprint(state)
# [4 basis states]
# |q=0⟩ : (0.5+0j)
# |q=1⟩ : (0.5+0j)
# |q=2⟩ : (0.5+0j)
# |q=3⟩ : (0.5+0j)

# Applying it again undoes it (self-adjoint)
ps.Hadamard_Int_Full("q")(state)
# Back to a single basis state

—

Hadamard_Bool

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

Clear all control conditions of the specified type.

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

Clear all control conditions of the specified type.

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

Clear all control conditions of the specified type.

clear_control_nonzeros(self: pysparq._core.Hadamard_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.Hadamard_Bool, cond: str) -> pysparq._core.Hadamard_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.Hadamard_Bool, conds: collections.abc.Sequence[str]) -> pysparq._core.Hadamard_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.Hadamard_Bool, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_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.Hadamard_Bool, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Hadamard_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.Hadamard_Bool, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_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.Hadamard_Bool, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_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.Hadamard_Bool, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_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.Hadamard_Bool, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_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.Hadamard_Bool, cond: str) -> pysparq._core.Hadamard_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.Hadamard_Bool, conds: collections.abc.Sequence[str]) -> pysparq._core.Hadamard_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.Hadamard_Bool, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_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.Hadamard_Bool, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Hadamard_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.Hadamard_Bool, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_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.Hadamard_Bool, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_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.Hadamard_Bool, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_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.Hadamard_Bool, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_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: Single-qubit Hadamard

Matrix:

\[\begin{split}H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\end{split}\]

Type constraints: Boolean (the register size must be 1)

Bit constraints: None (operates on bit 0 by default)

ps.System.clear()

# Single-qubit register
ps.System.add_register("qubit", ps.Boolean, 1)  # Must be 1 bit!

state = ps.SparseState()

ps.Hadamard_Bool("qubit")(state)

ps.pprint(state)
# [2 basis states]
# |qubit=0⟩ : (0.707+0j)
# |qubit=1⟩ : (0.707+0j)

—

Hadamard_Partial

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

Clear all control conditions of the specified type.

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

Clear all control conditions of the specified type.

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

Clear all control conditions of the specified type.

clear_control_nonzeros(self: pysparq._core.Hadamard_Partial) → 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.Hadamard_Partial, cond: str) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, conds: collections.abc.Sequence[str]) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, cond: str) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, conds: collections.abc.Sequence[str]) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, cond: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, conds: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, cond: str, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, conds: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, cond: typing.SupportsInt | typing.SupportsIndex, pos: typing.SupportsInt | typing.SupportsIndex) -> pysparq._core.Hadamard_Partial

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.Hadamard_Partial, conds: collections.abc.Sequence[tuple[typing.SupportsInt | typing.SupportsIndex, typing.SupportsInt | typing.SupportsIndex]]) -> pysparq._core.Hadamard_Partial

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 Hadamard to the specified qubits of a register

Type constraints: Integer type

Bit constraints: The specified positions must be within the register range

ps.System.clear()

# 4-bit register
ps.System.add_register("q", ps.UnsignedInteger, 4)

state = ps.SparseState()

# Apply Hadamard only to bits 1 and 3
positions = {1, 3}
ps.Hadamard_Partial("q", positions)(state)

# Creates 2^2 = 4 superposition states (only positions 1 and 3 flip)

—

Use Cases

Uniform superposition

Used in quantum search, quantum sampling and similar algorithms:

# Create a uniform superposition of the address register
ps.System.add_register("addr", ps.UnsignedInteger, n)
state = ps.SparseState()
ps.Hadamard_Int_Full("addr")(state)

# addr is now uniformly distributed over all possible values

Single-qubit initialization

Used to initialize a control bit:

ps.System.add_register("ctrl", ps.Boolean, 1)
ps.Hadamard_Bool("ctrl")(state)

# ctrl is in the |+⟩ = (|0⟩ + |1⟩)/√2 state

Partial superposition

For selective superposition:

# Superpose only the low 2 bits
ps.Hadamard_Int("reg", 2)(state)

# Or superpose specific positions
ps.Hadamard_Partial("reg", {0, 2})(state)