Skip to content

Add common quantum embeddings #2982

@Squirtle007

Description

@Squirtle007

Required prerequisites

  • Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.

Describe the feature

Add built-in APIs for common quantum embeddings.

--

(1) Amplitude encoding:
Maps and normalizes classical features (list, ndarray or cudaq.State) to a quantum state by encoding values as amplitudes: $x \mapsto \sum_i x_i |i\rangle$, including pad as an argument for vectors not sized to $2^n$ with the specified pad value, e.g., zero-padding to the nearest power of $2^n$ by setting pad = 0. The featured API looks like:

state_vector = cudaq.amplitude_encode([0.5, 0.5, 0.5], pad = 0)

Returns cudaq.State with values [0.5773, 0.5773, 0.5773, 0] (L2-norm = 1)

--

(2) Angular encoding:
Encodes classical features (list or ndarray) as qubit rotations (e.g., with specified Ry gates): $x_i \mapsto R_y(x_i)|0\rangle$:

@cudaq.kernel
def kernel(angles: list[float]):
    q = cudaq.qvector(3)
    cudaq.angular_encode(q, angles, rotation='Y')    # or cudaq.kernels.angular_encode

The corresponding kernel:

print(cudaq.draw(kernel, [0.1, 0.2, 0.3]))
     ╭─────────╮
q0 : ┤ ry(0.1) ├
     ├─────────┤
q1 : ┤ ry(0.2) ├
     ├─────────┤
q2 : ┤ ry(0.3) ├
     ╰─────────╯

--

Both embedding methods are commonly used in QML, enabling developers to design models more easily and intuitively.

Comment for Unitary Hack:
We are happy to accept PRs that implement either one encoding and preferably both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    UnitaryHackGood issue for UnitaryHackapplicationsPertaining to Notebooks or any applicationsenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions