Quantum Utilities
As more and more low-level functions migrate to the quantum space, such as dot products and distance estimation between vectors, they comprise a category we (so far) simply refer to as “utility” functions
- qcware.forge.qutils.qdot(x: Union[float, numpy.ndarray], y: Union[float, numpy.ndarray], loader_mode: str = 'parallel', circuit: quasar.circuit.Circuit = None, backend: str = 'qcware/cpu_simulator', num_measurements: int = 1000, absolute: bool = False, opt_shape: Optional[Tuple[int, ...]] = None)
- Outputs the dot product of two arrays; quantum analogue of::
numpy.dot
- Cases (following numpy.dot):
x is 1d, y is 1d; performs vector - vector multiplication. Returns float. x is 2d, y is 1d; performs matrix - vector multiplication. Returns 1d array. x is 1d, y is 2d; performs vector - matrix multiplication. Returns 1d array. x is 2d, y is 2d; performs matrix - matrix multiplication. Returns 2d array.
Arguments:
- Parameters
x (Union[float, numpy.ndarray]) – 1d or 2d array
y (Union[float, numpy.ndarray]) – 1d or 2d array
loader_mode (str) – Type of loader to use, one of parallel, diagonal, semi-diagonal, or optimized, defaults to parallel
circuit (quasar.Circuit) – Circuit to use for evaluation (None to implicitly create circuit), defaults to None
backend (str) – string describing the desired backend, defaults to qcware/cpu_simulator
num_measurements (int) – Number of measurements (necessary for all backends), defaults to 1000
absolute (bool) – Whether to return the absolute value of output, defaults to False
opt_shape (Optional[Tuple[int,...]]) – Shape of optimal loader (N1, N2), defaults to None
- Returns
float, 1d array, or 2d array: dot product
- Return type
Union[float, numpy.ndarray]
- qcware.forge.qutils.qdist(x: Union[float, numpy.ndarray], y: Union[float, numpy.ndarray], loader_mode: str = 'parallel', circuit: quasar.circuit.Circuit = None, backend: str = 'qcware/cpu_simulator', num_measurements: int = 1000, absolute: bool = False, opt_shape: Optional[Tuple[int, ...]] = None)
- Outputs the distance between input vectors; quantum analogue of::
numpy.linalg.norm(X - Y)**2
- Cases (following numpy.dot):
x is 1d, y is 1d; performs vector - vector multiplication. Returns float. x is 2d, y is 1d; performs matrix - vector multiplication. Returns 1d array. x is 1d, y is 2d; performs vector - matrix multiplication. Returns 1d array. x is 2d, y is 2d; performs matrix - matrix multiplication. Returns 2d array.
Arguments:
- Parameters
x (Union[float, numpy.ndarray]) – 1d or 2d array
y (Union[float, numpy.ndarray]) – 1d or 2d array
loader_mode (str) – Type of loader to use, one of parallel, diagonal, semi-diagonal, or optimized, defaults to parallel
circuit (quasar.Circuit) – Circuit to use for evaluation (None to implicitly create circuit), defaults to None
backend (str) – String denoting the backend to use, defaults to qcware/cpu_simulator
num_measurements (int) – Number of measurements; required, defaults to 1000
absolute (bool) – Whether to return the absolute value of the result, defaults to False
opt_shape (Optional[Tuple[int,...]]) – shape of the optimized loader’s input (N1, N2), defaults to None
- Returns
float, 1d array, or 2d array: distance estimation
- Return type
Union[float, numpy.ndarray]