Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : Why the _backward i not used from the SamplerQNN #895

Open
invochex opened this issue Feb 14, 2025 · 0 comments
Open

Question : Why the _backward i not used from the SamplerQNN #895

invochex opened this issue Feb 14, 2025 · 0 comments
Labels
type: discussion 🗣️ General discussions and explanations

Comments

@invochex
Copy link

invochex commented Feb 14, 2025

Hello,

I am currently exploring Deep Learning and Quantum Computing for my research, and I am using qiskit_machine_learning to implement a Variational Quantum Classifier (VQC) for binary classification. Below is my model:

from qiskit_machine_learning.algorithms import VQC
import time

# Creating a VQC instance
vqc = VQC(
    sampler=sampler,
    optimizer= classical_optimizer(),
    feature_map= feature_map(),
    ansatz= variational_circuit(),
    callback=callback_graph,
)

# Model Training
objective_func_vals = []
start = time.time()
vqc.fit(train_features, train_labels)
elapsed = time.time() - start

print(f"Training time: {round(elapsed)} seconds")

# Evaluation performance
score = vqc.score(train_features, train_labels)
print(f"Accuracy: {score}")

Here is the sampler:

from qiskit.primitives import StatevectorSampler as Sampler

sampler = Sampler()

Here is the optimizer using COBYLA:

def classical_optimizer():
    from qiskit_algorithms.optimizers import COBYLA
    
    cls_opt = COBYLA(maxiter=100, disp=True, tol=1e-6)
    return cls_opt

I need some clarification regarding the backpropagation process in Quantum Neural Networks (QNNs), particularly in Sampler_QNN.

I noticed that the measurement of my quantum circuit is performed in the _forward function of Sampler_QNN, which is used by default in VQC.

However, I expected _backward to be used at some point for gradient optimization.

I inserted a print statement in _backward, but it was never executed, whereas _forward was called 101 times.

Questions:

Why is _backward never used in Sampler_QNN?

I assumed that _backward is responsible for optimizing gradients. If not, how does optimization work in a QNN like Sampler_QNN?

Since COBYLA is a classical optimizer, does that mean optimization is performed in a classical way?

What does backpropagation correspond to in quantum neural networks?

Does the weight update happen every time _forward is called, or is there another mechanism?

I am struggling to fully grasp the underlying principle and would greatly appreciate any insights!

Thank you in advance!

@invochex invochex changed the title Why the _backward i not used from the SamplerQNN Question : Why the _backward i not used from the SamplerQNN Feb 18, 2025
@invochex invochex changed the title Question : Why the _backward i not used from the SamplerQNN Question : Why the _backward i not used from the SamplerQNN Feb 18, 2025
@edoaltamura edoaltamura added the type: discussion 🗣️ General discussions and explanations label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: discussion 🗣️ General discussions and explanations
Projects
None yet
Development

No branches or pull requests

2 participants