Skip to content

workbench_algorithms.subroutines.vector_arithmetic

Qubricks to do some vector arithmetic circuits.

VectorAddition

VectorAddition(
    add, subtract_condition: bool = False, **kwargs
)

Bases: Qubrick

Qubrick for adding (or subtracting) the components of two vectors of Qubits.

Parameters:

Name Type Description Default
add Qubrick

Adder Qubrick for adding Qubit registers.

required
subtract_condition (Optional, bool)

Whether to add or subtract the two vectors. Defaults to False (meaning, defaults to adding).

False

Parameters:

Name Type Description Default
add Qubrick

Adder Qubrick for adding Qubit registers.

required
subtract_condition (Optional, bool)

Whether to add or subtract the two vectors. Defaults to False (meaning, defaults to adding).

False
kwargs dict[str, Any]

Other key word arguments for the Qubrick.

{}

compute

compute(q_vec1: list[Qubits], q_vec2: list[Qubits])

Compute circuit for computing the sum (or difference) of two vectors.

Parameters:

Name Type Description Default
q_vec1 list

List of registers encoding vector components for one vector.

required
q_vec2 list

List of registers encoding vector components for the other vector.

required
Note

Two things: (i) The lengths of both vectors must be equal. (ii) Currently, WB cannot handle adding registers of different sizes correctly.

Currently, this method casts the results of addition to QInt objects in order to handle negative signs. This will be generalized.

OrthogonalDotProduct

OrthogonalDotProduct(
    release_ancillae, square, add, **kwargs
)

Bases: Qubrick

Qubrick for squaring an n-component vector, then adding the squared results.

Ex. for a 3-component vector computes \(x^2 + y^2 + z^3\).

Note

Currently, it is on the user to set the constructor args for sub-Qubricks. A consequence of this is that if you want to allow squaring negative values, this must be decided when you instantiate the square sub-Qubrick rather than in this Qubrick's constructor. Discussions on where this decision should be made are ongoing.

Parameters:

Name Type Description Default
release_ancillae bool

Whether to release ancillae in the squaring components.

required
square Qubrick

Qubrick that computes the square of a qubit register.

required
add Qubrick

Adder Qubrick.

required
**kwargs dict[str, Any]

Other arguments to pass to the init.

{}

compute

compute(q_vec: list[Qubits] | Qubits)

Compute circuit for squaring an n-component vector.

Parameters:

Name Type Description Default
q_vec Qubits or list[Qubits]

List of Qubits each storing a component of the vector or one big Qubits object with each component (ex. x | y | z).

required

AbsoluteDisplacement

AbsoluteDisplacement(
    orthogonal_dot_product, vector_sub, rsqrt, **kwargs
)

Bases: Qubrick

Qubrick for computing the reciprocal of the absolute value of the difference of two vectors.

Specifically, it computes \(\frac{1}{|r1 - r2|} = \frac{1}{\sqrt{(x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2}}\).

Note

Currently, it is on the user to set the constructor args for sub-Qubricks. A consequence of this is that if you want to allow negative values, this must be decided when you instantiate the square sub-Qubrick inside of orthogonal_dot_product rather than in this Qubrick's constructor. Discussions on where this decision should be made are ongoing.

Parameters:

Name Type Description Default
orthogonal_dot_product Qubrick

Qubrick for computing the square of a vector.

required
vector_sub Qubrick

Adder Qubrick for subtracting Qubit registers.

required
rsqrt Qubrick

Qubrick for performing the reciprocal square root operation.

required
kwargs dict[str, Any]

Other key word arguments for the Qubrick.

{}

compute

compute(
    q_vec1, q_vec2, high_precision: bool = False
) -> None

Compute circuit for taking the absolute value of the difference between two vectors.

Parameters:

Name Type Description Default
q_vec1 list

List of registers encoding vector components for one vector.

required
q_vec2 list

List of registers encoding vector components for the other vector.

required
high_precision (Optional, bool)

If True, returns high precision output from inverse square-root. Defaults to False.

False