Skip to content

qiu_quantum_computing.phase_propagator.sample_based_manual

Statevector simulation of the sample-based phase propagation, post-selected on success.

Instead of measuring the phi register, each cycle keeps the part of the state in which it is |0...0>, i.e. the successful outcome, and renormalizes it. See sample_based for the protocol.

Functions:

phase_propagation_cycle

phase_propagation_cycle(psi: Statevector, delta: float, phi: PreparableState) -> tuple[Statevector, float]

Simulate one cycle of the protocol, post-selected on its success.

Parameters:

Returns:

  • Statevector –

    The normalized state of the psi register after a successful cycle, and the

  • float –

    probability of success.

Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/phase_propagator/sample_based_manual.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def phase_propagation_cycle(
    psi: Statevector, delta: float, phi: PreparableState
) -> tuple[Statevector, float]:
    """Simulate one cycle of the protocol, post-selected on its success.

    Args:
        psi: The state of the `psi` register.
        delta: The phase of the cycle.
        phi: The preparable state `|phi>`.

    Returns:
        The normalized state of the `psi` register after a successful cycle, and the
        probability of success.
    """
    num_qubits = phi.num_qubits
    phi_qubits = list(range(num_qubits, 2 * num_qubits))

    # the phi register holds the more significant qubits, prepared in |0...0>
    state = Statevector.from_label("0" * num_qubits).tensor(psi)
    state = state.evolve(phi.circuit, phi_qubits)
    # the partial phase circuit is diagonal, see partial_phase_diagonal; applying its
    # diagonal directly avoids simulating its multi-controlled phase gate by gates
    state = Statevector(state.data * partial_phase_diagonal(delta, num_qubits))
    state = state.evolve(phi.inverse_circuit, phi_qubits)

    # the amplitudes with the phi register in |0...0> come first
    success = state.data[: 2**num_qubits]
    probability = float(np.vdot(success, success).real)
    return Statevector(success / np.sqrt(probability)), probability

phase_propagate_state

phase_propagate_state(psi_in: Statevector, deltas: NDArray | list[float], phi: PreparableState) -> Statevector

Simulate one successful cycle per delta.

Parameters:

Returns:

  • Statevector –

    The state of the psi register after all cycles.

Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/phase_propagator/sample_based_manual.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def phase_propagate_state(
    psi_in: Statevector, deltas: npt.NDArray | list[float], phi: PreparableState
) -> Statevector:
    """Simulate one successful cycle per delta.

    Args:
        psi_in: The initial state of the `psi` register.
        deltas: The phase of each cycle.
        phi: The preparable state `|phi>`.

    Returns:
        The state of the `psi` register after all cycles.
    """
    psi = psi_in
    for delta in deltas:
        psi, _ = phase_propagation_cycle(psi, delta, phi)
    return psi

phase_propagate_state_with_constant_delta

phase_propagate_state_with_constant_delta(psi_in: Statevector, delta: float, num_cycles: int, phi: PreparableState) -> Statevector

Simulate num_cycles successful cycles with the same delta.

Parameters:

  • psi_in (Statevector) –

    The initial state of the psi register.

  • delta (float) –

    The phase of each cycle.

  • num_cycles (int) –

    The number of cycles.

  • phi (PreparableState) –

    The preparable state |phi>.

Returns:

  • Statevector –

    The state of the psi register after all cycles.

Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/phase_propagator/sample_based_manual.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def phase_propagate_state_with_constant_delta(
    psi_in: Statevector, delta: float, num_cycles: int, phi: PreparableState
) -> Statevector:
    """Simulate `num_cycles` successful cycles with the same delta.

    Args:
        psi_in: The initial state of the `psi` register.
        delta: The phase of each cycle.
        num_cycles: The number of cycles.
        phi: The preparable state `|phi>`.

    Returns:
        The state of the `psi` register after all cycles.
    """
    return phase_propagate_state(psi_in, np.full(num_cycles, delta), phi)

phase_propagate_state_with_arbitrary_signal

phase_propagate_state_with_arbitrary_signal(psi_in: Statevector, signal: SampledSignal, max_delta: float, method: SynthesisMethod = GATE) -> Statevector

Simulate the application of e^(i f(x)) for a signal f of one sign.

Parameters:

  • psi_in (Statevector) –

    The initial state of the psi register.

  • signal (SampledSignal) –

    The real signal f of one sign, on an axis of 2**n samples.

  • max_delta (float) –

    The maximum phase per cycle.

  • method (SynthesisMethod, default: GATE ) –

    How the preparation of |phi> is represented in the circuits.

Returns:

  • Statevector –

    The state of the psi register after all cycles.

Source code in packages/qiu-quantum-computing/src/qiu_quantum_computing/phase_propagator/sample_based_manual.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def phase_propagate_state_with_arbitrary_signal(
    psi_in: Statevector,
    signal: SampledSignal,
    max_delta: float,
    method: SynthesisMethod = SynthesisMethod.GATE,
) -> Statevector:
    """Simulate the application of `e^(i f(x))` for a signal `f` of one sign.

    Args:
        psi_in: The initial state of the `psi` register.
        signal: The real signal `f` of one sign, on an axis of `2**n` samples.
        max_delta: The maximum phase per cycle.
        method: How the preparation of `|phi>` is represented in the circuits.

    Returns:
        The state of the `psi` register after all cycles.
    """
    alpha, state = sample_based_decomposition(signal)
    deltas = slice_alpha_to_deltas_evenly(alpha, max_delta)
    return phase_propagate_state(psi_in, deltas, PreparableState(state, method))