mindquantum.algorithm.library.qjpeg
- mindquantum.algorithm.library.qjpeg(n_qubits: int, m_qubits: int)[source]
Construct the circuit for compressing quantum figure with the QJPEG algorithm.
- Parameters
Note
The input arguments, n_qubits and m_qubits, should both be even, and the n_qubits must be not less than the m_qubits. Please refer to arXiv:2306.09323v2 for more information.
- Returns
Circuit, The QJPEG circuit for quantum image compression
List[int], List of indices for remainder qubits that carry the compressed quantum image information
List[int], List of indices for discarded qubits
Examples
>>> from mindquantum import Simulator, normalize >>> import numpy as np >>> n_qubits = 4 >>> m_qubits = 2 >>> circ, remainder_qubits, discard_qubits = qjpeg(n_qubits, m_qubits) >>> print(remainder_qubits, discard_qubits) [0, 2] [1, 3] >>> data = np.array([[1,0,0,0], [1,1,0,0], [1,1,1,0], [1,1,1,1]]) >>> state = normalize(data.reshape(-1)) >>> sim = Simulator('mqmatrix', n_qubits) >>> sim.set_qs(state) >>> sim.apply_circuit(circ) >>> rho = sim.get_partial_trace(discard_qubits) >>> sub_probs = rho.diagonal().real >>> new_data = sub_probs.reshape((2**(m_qubits//2), -1)) >>> print(new_data) [[0.3, 0.], [0.4, 0.3]]