tensorcircuit.applications.optimization#

modules for QUBO problems in QAOA

tensorcircuit.applications.optimization.Ising_loss(c: Any, pauli_terms: Any, weights: List[float]) Any[源代码]#

computes the loss function for the Ising model based on a given quantum circuit, a list of Pauli terms, and corresponding weights. The offset is ignored.

参数
  • c -- A quantum circuit object generating the state.

  • pauli_terms -- A list of Pauli terms, where each term is represented as a list of 0/1 series.

  • weights -- A list of weights corresponding to each Pauli term.

Return loss

A real number representing the computed loss value.

tensorcircuit.applications.optimization.QAOA_loss(nlayers: int, pauli_terms: Any, weights: List[float], params: List[float], full_coupling: bool = False, mixer: str = 'X') Any[源代码]#

computes the loss function for the Quantum Approximate Optimization Algorithm (QAOA) applied to the Ising model.

参数
  • nlayers -- The number of layers in the QAOA ansatz.

  • pauli_terms -- A list of Pauli terms, where each term is represented as a list of 0/1 series.

  • weights -- A list of weights corresponding to each Pauli term.

  • params -- A list of parameter values used in the QAOA ansatz.

  • (optional) (full_coupling) -- A flag indicating whether to use all-to-all coupling in mixers. Default is False.

Paran mixer (optional)

The mixer operator to use. Default is "X". The other options are "XY" and "ZZ".

返回

The computed loss value.

tensorcircuit.applications.optimization.QUBO_QAOA(Q: Any, nlayers: int, iterations: int, vvag: bool = False, ncircuits: int = 10, init_params: Optional[List[float]] = None, mixer: str = 'X', learning_rate: float = 0.01, callback: Optional[Callable[[List[float], float], None]] = None, full_coupling: bool = False) Any[源代码]#

Performs the QAOA on a given QUBO problem. Adam optimizer from TensorFlow is used.

参数
  • Q -- The n-by-n square and symmetric Q-matrix representing the QUBO problem.

  • nlayers -- The number of layers (depth) in the QAOA ansatz.

  • iterations -- The number of iterations to run the optimization.

  • (optional) (full_coupling) -- A flag indicating whether to use vectorized variational adjoint gradient. Default is False.

  • (optional) -- The number of circuits when using vectorized variational adjoint gradient. Default is 10.

  • (optional) -- The initial parameters for the ansatz circuit. Default is None, which initializes the parameters randomly.

  • (optional) -- The learning rate for the Adam optimizer. Default is 1e-2.

  • (optional) -- A callback function that is executed during each iteration. Default is None.

  • (optional) -- A flag indicating whether to use all-to-all coupling in mixers. Default is False.

Paran mixer (optional)

The mixer operator to use. Default is "X". The other options are "XY" and "ZZ".

Return params

The optimized parameters for the ansatz circuit.

tensorcircuit.applications.optimization.QUBO_QAOA_cvar(Q: Any, nlayers: int, alpha: float, nsamples: int = 1000, callback: Optional[Callable[[List[float], float], None]] = None, expectation_based: bool = False, maxiter: int = 1000, init_params: Optional[Tuple[float]] = None) Any[源代码]#

Perform the QUBO QAOA optimization with CVaR as the loss function.

参数
  • Q -- The n-by-n square and symmetric Q-matrix representing the QUBO problem.

  • ansatz -- The ansatz function to be used for QAOA.

  • nlayers -- The number of layers (depth) in the QAOA ansatz.

  • alpha -- The cut-off percentage for CVaR.

  • nsamples -- The number of samples for measurements in the CVaR calculation. Default is 1000.

  • callback -- A callback function to be called after each iteration. Default is None.

  • expectation_based -- A flag indicating the type of CVaR ansatz (measurement-based or expectation-based). Default is False.

  • maxiter -- The maximum number of iterations for the optimization. Default is 1000.

返回

The optimized parameters for the ansatz circuit.

tensorcircuit.applications.optimization.cvar_from_circuit(circuit: Any, nsamples: int, Q: Any, alpha: float) Any[源代码]#

Directly calculate the Conditional Value at Risk (CVaR) from a circuit. The CVaR depends on a bunch of measurements.

参数
  • circuit -- The quantum circuit used to prepare the state.

  • nsamples -- The number of samples to take for measurements.

  • Q -- The Q-matrix representing the Quadratic Unconstrained Binary Optimization (QUBO) problem.

  • alpha -- The cut-off percentage for CVaR.

返回

The calculated CVaR value.

tensorcircuit.applications.optimization.cvar_from_expectation(circuit: Any, Q: Any, alpha: float) Any[源代码]#

Calculate the Conditional Value at Risk (CVaR) from the expectation values of a quantum circuit.

参数
  • circuit -- The quantum circuit.

  • Q -- The Q-matrix representing the Quadratic Unconstrained Binary Optimization (QUBO) problem.

  • alpha -- The cut-off percentage for CVaR.

返回

The calculated CVaR value.

tensorcircuit.applications.optimization.cvar_loss(nlayers: int, Q: Any, nsamples: int, alpha: float, expectation_based: bool, params: List[float]) Any[源代码]#

Calculate the CVaR loss for a given QUBO problem using the QAOA ansatz.

参数
  • nlayers -- The number of layers (depth) in the QAOA ansatz.

  • Q -- The Q-matrix representing the Quadratic Unconstrained Binary Optimization (QUBO) problem.

  • nsamples -- The number of samples to take for measurements in the CVaR calculation.

  • alpha -- The cut-off percentage for CVaR.

  • expectation_based -- A flag indicating the type of CVaR ansatz (measurement-based or expectation-based).

  • params -- The parameters for the QAOA ansatz circuit.

返回

The calculated CVaR loss.

tensorcircuit.applications.optimization.cvar_value(r: List[float], p: List[float], percent: float) Any[源代码]#

Compute the Conditional Value at Risk (CVaR) based on the measurement results.

参数
  • r -- The observed outcomes after measurements.

  • p -- Probabilities associated with each observed outcome.

  • percent -- The cut-off percentage for CVaR computation.

返回

The calculated CVaR value.