paddle_quantum.ansatz.vans
The source file of the variable ansatz.
- paddle_quantum.ansatz.vans.cir_decompose(cir, trainable=False)
Decompose all layers of circuit into gates, and make all parameterized gates trainable if needed
- Parameters:
cir (Circuit) – Target quantum circuit.
trainable (bool | None) – whether the decomposed parameterized gates are trainable
- Returns:
A quantum circuit with same structure and parameters but all layers are decomposed into Gates.
- Return type:
Note
This function does not support customized gates, such as oracle and control-oracle.
- class paddle_quantum.ansatz.vans.Inserter
Bases:
object
Class for block insertion for the circuit.
- classmethod insert_identities(cir, insert_rate, epsilon)
Insert identity blocks to the current circuit, according to the insert rate.
- class paddle_quantum.ansatz.vans.Simplifier
Bases:
object
Class for circuit simplification.
- class paddle_quantum.ansatz.vans.VAns(n, loss_func, *loss_func_args, epsilon=0.1, insert_rate=2, iter=100, iter_out=10, LR=0.1, threshold=0.002, accept_wall=100, zero_init_state=True)
Bases:
object
Class of Variable Ansatz.
User can initialize this class to find variational circuit to construct QML model.
Note
The loss function passed in must have the quantum circuit as its first parameter.
- Parameters:
n (int) – Number of qubits.
loss_func (Callable[[Circuit, Any], Tensor]) – Loss function that evaluate the loss of circuit.
loss_func_args (Any) – Parameters of loss function other than circuit.
epsilon (float) – Range of random initialization of parameters. Defaults to
0.1
.insert_rate (float) – Rate of number of inserted blocks. Defaults to
2
.iter (int) – Number of iterations of optimizer. Defaults to
100
.iter_out (int) – Number of insert-simplify cycles. Defaults to
10
.LR (float) – Learning rate. Defaults to
0.1
.threshold (float) – Tolerance of incread loss after deleting one qubit gate. Defaults to
0.002
.accpet_wall – Percentage of probability of accepting the circuit in current insert-simplify cycle. Defaults to
100
.zero_init_state (bool) – Whether the initial state is \(|0\rangle\). Defaults to
True
.
- train()
Train the quantum circuit.
- Returns:
The quantum circuit with the lowest loss.
- Return type: