qrisp.semi_classic_matmul#

semi_classic_matmul(q_matrix, cl_matrix, output_array=None, res_bit_shape='eq')[source]#

Performs matrix multiplication between a classical numpy array and a QuantumArray

Parameters:
q_matrixQuantumArray

The QuantumArray to multiply.

cl_matrixnumpy.ndarray

The numpy array to multiply.

output_arrayQuantumArray, optional

The QuantumArray to store the result in. The default is None.

res_bit_shapestr or QuantumFloat, optional

Specification of the dimension of the output bitshape of the output QuantumArray. Possible are “eq”, which will take the bitshape equal two the first factor, “safe” which automatically determines the bitshape such that there can be no overflow, or a QuantumFloat which has the desired bitshape. The default is “eq”.

Returns:
output_arrayQuantumArray

The QuantumArray containing the result.

Raises:
Exception

Tried to apply matrix multiplication with unfitting dimensions.

Examples

We multiply a QuantumArray with a scalar multiple of the identity matrix (np.eye):

>>> import numpy as np
>>> from qrisp import QuantumFloat, QuantumArray, semi_classic_matmul
>>> qf = QuantumFloat(4,0, signed = False)
>>> q_arr_0 = QuantumArray(qf, shape = (2,2))
>>> q_arr_1 = QuantumArray(qf, shape = (2,2))
>>> q_arr_0[:] = [[1,2],[3,4]]
>>> res = semi_classic_matmul(q_arr_0, 2*np.eye(2))
>>> print(res)
{OutcomeArray([[2, 4],
               [6, 8]]): 1.0}