Skip to content
Construct PsiQDK Algorithms

arithmetic

arithmetic

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}{|r_1 - r_2|} = \frac{1}{\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2 + (z_1-z_2)^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 keyword arguments for the Qubrick.

{}

orthogonal_dot_product instance-attribute

orthogonal_dot_product: Incomplete = orthogonal_dot_product

vector_sub instance-attribute

vector_sub: Incomplete = vector_sub

rsqrt instance-attribute

rsqrt: Incomplete = rsqrt

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

OrthogonalDotProduct

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

Bases: Qubrick

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

For example, for a 3-component vector this computes \(x^2 + y^2 + z^2\).

Note

Currently, it is on the user to set the constructor argumentss 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 auxiliary qubits 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.

{}

square instance-attribute

square: Incomplete = square

add instance-attribute

add: Incomplete = add

release_ancillae instance-attribute

release_ancillae: Incomplete = release_ancillae

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

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.

required
subtract_condition (Optional, bool)

Whether to add or subtract the two vectors. Defaults to False (addition).

False
kwargs dict[str, Any]

Other keyword arguments for the Qubrick.

{}

add instance-attribute

add: Incomplete = add

subtract_condition instance-attribute

subtract_condition: Incomplete = subtract_condition

result_qregs instance-attribute

result_qregs: Incomplete

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

The lengths of both vectors must be equal. Currently, this Qubrick 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.