paddle_quantum.data_analysis.vqls

The VQLS model.

paddle_quantum.data_analysis.vqls.hadamard_test(phi, U, num_qubits)

Given unitary U and state \(|\phi\rangle\), it computes the expectation of U with respect to \(|\phi\rangle\), i.e. \(|\phi\rangle\).

Parameters:
  • phi (State) – State which the expectation is with respect to.

  • U (Tensor) – Unitary which we are taking expectation of.

  • num_qubits (int) – Number of qubits of phi/U.

Returns:

Return the real and imaginary part of the expectation value.

Return type:

Tuple[Tensor, Tensor]

paddle_quantum.data_analysis.vqls.hadamard_overlap_test(phi, b, An, Am, num_qubits)

Given unitary Am, An and state \(|\phi\rangle\), b, it computes the value of \(\langle{b}| An |\phi\rangle\langle\phi| Am^\dagger |b\rangle\).

Parameters:
  • phi (State) – State in the calculation.

  • b (State) – State in the calculation.

  • Am (Tensor) – Unitary matrix in the calculation.

  • An (Tensor) – Unitary matrix in the calculation.

  • num_qubits (int) – Number of qubits of the system.

Returns:

Return the real and imaginary part of the calculation.

Return type:

Tuple[Tensor, Tensor]

class paddle_quantum.data_analysis.vqls.VQLS(num_qubits, A, coefficients_real, coefficients_img, b, depth)

Bases: Layer

The class of the variational quantum linear solver (VQLS).

Parameters:
  • num_qubits (int) – The number of qubits which the quantum circuit contains.

  • A (List[Tensor]) – List of unitaries in the decomposition of the input matrix.

  • coefficients_real (List[float]) – Real part of coefficients of corresponding unitaries in the decomposition of the input matrix.

  • coefficients_img (List[float]) – Imaginary part of coefficients of corresponding unitaries in the decomposition of the input matrix.

  • b (State) – The state which the input answer is encoded into.

  • depth (int) – Depth of the ansatz circuit.

forward()

The forward function.

Returns:

Return the output of the model.

Return type:

Tensor

paddle_quantum.data_analysis.vqls.compute(A, b, depth, iterations, LR, gamma=0)

Solve the linear equation Ax=b.

Parameters:
  • A (ndarray) – Input matrix.

  • b (ndarray) – Input vector.

  • depth (int) – Depth of ansatz circuit.

  • iterations (int) – Number of iterations for optimization.

  • LR (float) – Learning rate of optimizer.

  • gamma (float | None) – Extra option to end optimization early if loss is below this value. Default to ‘0’.

Returns:

Return the vector x that solves Ax=b.

Raises:
  • ValueError – A is not a square matrix.

  • ValueError – dimension of A and b don’t match.

  • ValueError – A is a singular matrix hence there’s no unique solution.

Return type:

ndarray