Quantum Input/Output
A common problem in quantum circuits deals with how to get classical data in and out of a quantum computer. Forge provides a method to create a circuit from an array of numerical data which loads that data into a quantum circuit.
- qcware.forge.qio.loader(data: numpy.ndarray, mode: str = 'optimized', opt_shape: Optional[Tuple[int, ...]] = None, initial: bool = True, return_statevector_indices: bool = False)
Creates a circuit which loads an array of classical data into the state space of a quantum computer or simulator. This is useful in order to act on known data or to simulator quantum RAM.
Arguments:
- Parameters
data (numpy.ndarray) – A 1-d array representing the classical data to be represented in the circuit
mode (str) – Whether to used the “optimized” loader (using approximately \(~sqrt(d)\) depth and \(~sqrt(d)\) qubits) or the “parallel” loader (using approximately \(log(d)\) depth and d qubits., defaults to optimized
opt_shape (Optional[Tuple[int,...]]) – If the loader is an optimized loader, this corresponds to the new shape of the input matrix, defaults to None
initial (bool) – Whether the loader is at the beginning of the circuit (in which it performs an initial X gate on the first qubit), defaults to True
return_statevector_indices (bool) – True; return a tuple (circ, inds) of circuit and statevector indices False; return circuit circ, defaults to False
- Returns
circ: if return_statevector_indices == False (circ, inds): if return_statevector_indices == True
- circ: A Quasar circuit suitable for execution on any quasar backend supporting the required
gates which loads the classical vector into a quantum state.
inds: Indices of the resulting statevector into which the classical data was loaded. :rtype: quasar.Circuit: if return_statevector_indices == False tuple(quasar.Circuit, numpy.ndarray): if return_statevector_indices == True