-
Notifications
You must be signed in to change notification settings - Fork 4
Advance: Custom state preparation
In the below, we use qoop to define a quantum compilation process:
where
Step 1. We use the QuantumStatePreparetion class from qoop.compilation and two modules ansatz, state.
from qoop.compilation.qsp import QuantumStatePreparation
from qoop.core import ansatz, state
import qiskit
Step 2. Defining
#define a custom ansatz
def custom_ansatz(num_qubits: int) -> qiskit.QuantumCircuit:
qc = qiskit.QuantumCircuit(num_qubits)
thetas = qiskit.circuit.ParameterVector(
'theta', 2 * num_qubits)
j = 0
for i in range(num_qubits):
qc.rx(thetas[j], i)
qc.rz(thetas[j + 1], i)
j += 2
return qc
Step 3. We create a compiler object that includes
#run the compiler
num_qubits = 2
compiler = QuantumStatePreparation(
u = custom_ansatz(num_qubits),
target_state = state.w(num_qubits).inverse()
)
Step 4. Call fit() method. We provide few options in this method, the user can leave it blank to use the default hyperparameter, declare the existing options or self-defining as above.
compiler.fit(
num_steps = 100,
optimizer = 'sgd',
metrics_func = [
'loss_basic',
'compilation_trace_fidelities'
]
)
#plot figure
compiler.plot()
Copyright @ 2024 Hai et al
- Home
- Contribute guideline
- Installation guideline
- Package requirements
- Core
- GA-QAS
- Example
- Advanced