Complex Algebra

qucumber.utils.cplx.absolute_value(x)[source]

Computes the complex absolute value elementwise.

Parameters

x (torch.Tensor) – A complex tensor.

Returns

A real tensor.

Return type

torch.Tensor

qucumber.utils.cplx.conjugate(x)[source]

A function that takes the conjugate transpose of the argument.

Parameters

x (torch.Tensor) – A complex vector or matrix.

Returns

The conjugate of x.

Return type

torch.Tensor

qucumber.utils.cplx.elementwise_division(x, y)[source]

Elementwise division of x by y.

Parameters
Return type

torch.Tensor

qucumber.utils.cplx.elementwise_mult(x, y)[source]

Alias for scalar_mult().

qucumber.utils.cplx.imag(x)[source]

Returns the imaginary part of a complex tensor.

Parameters

x (torch.Tensor) – The complex tensor

Returns

The imaginary part of x; will have one less dimension than x.

Return type

torch.Tensor

qucumber.utils.cplx.inner_prod(x, y)[source]

A function that returns the inner product of two complex vectors, x and y (<x|y>).

Parameters
Raises

ValueError – If x and y are not complex vectors with their first dimensions being 2, then the function will not execute.

Returns

The inner product, \langle x\vert y\rangle.

Return type

torch.Tensor

qucumber.utils.cplx.kronecker_prod(x, y)[source]

A function that returns the tensor / kronecker product of 2 complex tensors, x and y.

Parameters
Raises

ValueError – If x and y do not have 3 dimensions or their first dimension is not 2, the function cannot execute.

Returns

The tensorproduct of x and y, x \otimes y.

Return type

torch.Tensor

qucumber.utils.cplx.make_complex(x, y=None)[source]

A function that combines the real (x) and imaginary (y) parts of a vector or a matrix.

Note

x and y must have the same shape. Also, this will not work for rank zero tensors.

Parameters
  • x (torch.Tensor) – The real part

  • y (torch.Tensor) – The imaginary part. Can be None, in which case, the resulting complex tensor will have imaginary part equal to zero.

Returns

The tensor [x,y] = x + yi.

Return type

torch.Tensor

qucumber.utils.cplx.matmul(x, y)[source]

A function that computes complex matrix-matrix and matrix-vector products.

Note

If one wishes to do matrix-vector products, the vector must be the second argument (y).

Parameters
Returns

The product between x and y.

Return type

torch.Tensor

qucumber.utils.cplx.norm(x)[source]

A function that returns the norm of the argument.

Parameters

x (torch.Tensor) – A complex scalar.

Returns

|x|.

Return type

torch.Tensor

qucumber.utils.cplx.norm_sqr(x)[source]

A function that returns the squared norm of the argument.

Parameters

x (torch.Tensor) – A complex scalar.

Returns

|x|^2.

Return type

torch.Tensor

qucumber.utils.cplx.outer_prod(x, y)[source]

A function that returns the outer product of two complex vectors, x and y.

Parameters
Raises

ValueError – If x and y are not complex vectors with their first dimensions being 2, then the function will not execute.

Returns

The outer product between x and y, \vert x \rangle\langle y\vert.

Return type

torch.Tensor

qucumber.utils.cplx.real(x)[source]

Returns the real part of a complex tensor.

Parameters

x (torch.Tensor) – The complex tensor

Returns

The real part of x; will have one less dimension than x.

Return type

torch.Tensor

qucumber.utils.cplx.scalar_divide(x, y)[source]

A function that computes the division of x by y.

Parameters
  • x (torch.Tensor) – The numerator (a complex scalar, vector or matrix).

  • y (torch.Tensor) – The denominator (a complex scalar).

Returns

x / y

Return type

torch.Tensor

qucumber.utils.cplx.scalar_mult(x, y, out=None)[source]

A function that computes the product between complex matrices and scalars, complex vectors and scalars or two complex scalars.

Parameters
  • x (torch.Tensor) – A complex scalar, vector or matrix.

  • y (torch.Tensor) – A complex scalar, vector or matrix.

  • z (torch.Tensor) – The complex tensor to write the output to.

  • z – A complex scalar, vector or matrix. Can be None, in which case, a new tensor is created and returned. Otherwise, the method overwrites z.

Returns

The product between x and y. Either overwrites z, or returns a new tensor.

Return type

torch.Tensor