跳转至

QuantumStatePreparation

QuICT.qcda.synthesis.quantum_state_preparation.QuantumStatePreparation

QuantumStatePreparation(method: str = 'unitary_decomposition', keep_phase: bool = False, ancilla: int = 0, opt: bool = True)

Bases: object

For a given quantum state \(|\psi\rangle\), create a CompositeGate \(C\) that \(|\psi\rangle = C |0\rangle\)

Choose the method between the references, designing circuit of quantum state preparation with uniformly gates, unitary decomposition and diagnal gates respectively

Reference

[1] Transformation of quantum states using uniformly controlled rotations https://arxiv.org/abs/quant-ph/0407010

[2] Quantum-state preparation with universal gate decompositions https://arxiv.org/abs/1003.5760

Examples:

>>> from QuICT.qcda.synthesis import QuantumStatePreparation
>>> QSP = QuantumStatePreparation('uniformly_gates')
>>> gates = QSP.execute(state_vector)
>>> from QuICT.qcda.synthesis import QuantumStatePreparation
>>> QSP = QuantumStatePreparation('unitary_decomposition')
>>> gates = QSP.execute(state_vector)

Parameters:

  • method (str, default: 'unitary_decomposition' ) –

    chosen method in ['uniformly_gates', 'unitary_decomposition'], Please note that if you select method 'unary_transformation', then please pass in the state_vector with all real number coefficient when using execute(), otherwise the method will be invalid and automatically transferred to method 'unary_diagonal_joint'.

  • keep_phase (bool, default: False ) –

    whether to keep the global phase as a GPhase gate in the output

  • ancilla (int, default: 0 ) –

    the number of ancillary qubits m

  • opt (bool, default: True ) –

    optimizer switch for 'diagonal_gates', enabled by default

Source code in QuICT/qcda/synthesis/quantum_state_preparation/quantum_state_preparation.py
def __init__(
    self,
    method: str = 'unitary_decomposition',
    keep_phase: bool = False,
    ancilla: int = 0,
    opt: bool = True,
):
    """
    Args:
        method (str, optional): chosen method in
            ['uniformly_gates', 'unitary_decomposition'],
            Please note that if you select method 'unary_transformation',
            then please pass in the state_vector with all real number coefficient when using execute(),
            otherwise the method will be invalid and automatically transferred to method 'unary_diagonal_joint'.
        keep_phase (bool, optional): whether to keep the global phase as a GPhase gate in the output
        ancilla (int, optional): the number of ancillary qubits m
        opt (bool, optional): optimizer switch for 'diagonal_gates', enabled by default
    """
    assert method in [
        'uniformly_gates',
        'unitary_decomposition',
    ], ValueError('Invalid quantum state preparation method')
    self.method = method
    self.keep_phase = keep_phase
    self.ancilla = ancilla
    if self.method not in ['diagonal_gates'] and self.ancilla != 0:
        self._logger.warn(
            "Now only 'diagonal_gates' methods can make use of ancilla qubits."
        )
    self.opt = opt

execute

execute(state_vector: ndarray) -> CompositeGate

Quantum state preparation with the chosen method

Parameters:

  • state_vector (ndarray) –

    the statevector to be prepared

Returns:

  • CompositeGate ( CompositeGate ) –

    the preparation CompositeGate

Source code in QuICT/qcda/synthesis/quantum_state_preparation/quantum_state_preparation.py
def execute(self, state_vector: np.ndarray) -> CompositeGate:
    """
    Quantum state preparation with the chosen method

    Args:
        state_vector (np.ndarray): the statevector to be prepared

    Returns:
        CompositeGate: the preparation CompositeGate
    """
    # Ref: [1] <https://arxiv.org/abs/quant-ph/0407010>
    if self.method == 'uniformly_gates':
        return self._with_uniformly_gates(state_vector)

    # Ref: [2] <https://arxiv.org/abs/1003.5760>
    if self.method == 'unitary_decomposition':
        return self._with_unitary_decomposition(state_vector)