dorahacksglobal / qc-classifier

AI-inspired Classification of Quantum Computers
GNU General Public License v2.0
2 stars 4 forks source link

Add files via upload #10

Open AbdullahKazi500 opened 1 month ago

AbdullahKazi500 commented 1 month ago

I started by defining a quantum circuit, known as the quantum volume circuit, incorporating random rotations and two-qubit gates. Additionally, noise is introduced to simulate a more realistic quantum environment.

using the quantum volume circuit, generated synthetic quantum data tailored for various backends, including both quantum simulators and actual quantum hardware. This ensures versatility and adaptability across different quantum computing platforms.

The next step involves defining quantum circuits representing the real data, as well as the generator and discriminator components of the QGAN. These circuits are implemented using PennyLane,

QGAN Cost Functions establish the cost functions governing the behavior of the generator and discriminator within the QGAN framework. These functions serve as the optimization objectives during training.

Training QGAN: With the cost functions defined, proceed to train the QGAN. initialize the weights for the generator and discriminator, then iteratively update them using stochastic gradient descent (SGD), facilitating adversarial learning.

As part of the analysis, compute and compare the Bloch vectors of the real quantum states with those generated by the QGAN. This comparison offers valuable insights into the fidelity and efficacy of the generative model.

In the context of supervised learning tasks, synthetic labels are generated for the corresponding synthetic quantum data. These labels are essential for training and evaluating the subsequent classifier.

To ensure robust evaluation, split the synthetic quantum data and corresponding labels into separate training and testing sets. This division facilitates unbiased assessment of the classifier's performance.

Leveraging the generated synthetic data and labels, train a RandomForestClassifier. This classical machine learning model learns to classify quantum data based on the features extracted from the synthetic datasets.

assess the classifier's performance by evaluating its accuracy on the test dataset. This evaluation provides valuable feedback on the effectiveness of the QGAN-generated synthetic data for downstream machine learning tasks. fixes #2

AbdullahKazi500 commented 1 month ago

Hi @ShreyK7 @bernardyeszero and @sid-chava added one more updated file with more accuracy 0.57 and also some explanation in the recent PR on the same patch PR

bernardyeszero commented 1 month ago

Hi @AbdullahKazi500, sorry for the late reply. Thanks for your PR (mainly, the file "QGANDorahacks (3).ipynb") about the classifications of general circuits. I carefully read the code and found some confusing problems.

  1. In the function quantum_volume_circuit_with_noise(), the three random numbers are generated to apply at Rx, Ry, and Rz, respectively to achieve random rotation. This is not a Harr random matrix for a Quantum Volume circuit. See this explanation from Pennylane: https://pennylane.ai/qml/demos/tutorial_haar_measure/. A similar example is generating a random point in the unit sphere uniformly. Though a point in a unit sphere could be written as $(\sin \theta \cos \phi, \sin \theta \sin \phi, \cos \theta)$, we can not generate uniform distribution using $\theta = random(0, 2\pi)$ and $\phi = random(0, \pi)$, see this website: http://datagenetics.com/blog/january32020/index.html.
  2. I'm confused with the output of QGAN, which is used to generate a state to approach an ideal state. In the output, the "Real Bloch vector" is (-0.2169, 0.4505, -0.8660), but the "Generator Bloch vector" is (-0.0687, 0.4632, -0.8836). It's different.
  3. I found the classifier has no relationship with quantum circuits. So, the result of the accuracy of 57% seems perplexing.
  4. I found the code requires to be refactored, or you could submit some slides to highlight the methodology and results.

Thanks for your contributions again, and hope you enjoy the hackathon.

AbdullahKazi500 commented 1 month ago

Hi @AbdullahKazi500, sorry for the late reply. Thanks for your PR (mainly, the file "QGANDorahacks (3).ipynb") about the classifications of general circuits. I carefully read the code and found some confusing problems.

  1. In the function quantum_volume_circuit_with_noise(), the three random numbers are generated to apply at Rx, Ry, and Rz, respectively to achieve random rotation. This is not a Harr random matrix for a Quantum Volume circuit. See this explanation from Pennylane: https://pennylane.ai/qml/demos/tutorial_haar_measure/. A similar example is generating a random point in the unit sphere uniformly. Though a point in a unit sphere could be written as (sin⁡θcos⁡ϕ,sin⁡θsin⁡ϕ,cos⁡θ), we can not generate uniform distribution using θ=random(0,2π) and ϕ=random(0,π), see this website: http://datagenetics.com/blog/january32020/index.html.
  2. I'm confused with the output of QGAN, which is used to generate a state to approach an ideal state. In the output, the "Real Bloch vector" is (-0.2169, 0.4505, -0.8660), but the "Generator Bloch vector" is (-0.0687, 0.4632, -0.8836). It's different.
  3. I found the classifier has no relationship with quantum circuits. So, the result of the accuracy of 57% seems perplexing.
  4. I found the code requires to be refactored, or you could submit some slides to highlight the methodology and results.

Thanks for your contributions again, and hope you enjoy the hackathon.

Hi @bernardyeszero thanks for the comments The current implementation of generating random rotations in the quantum_volume_circuit_with_noise function might not adhere strictly to the requirements of a Haar-random quantum volume circuit. As you correctly pointed out, generating random angles for rotations in the circuit does not guarantee a uniform distribution over the Haar measure. To ensure a more accurate representation of a Haar-random quantum circuit, I may need to explore other methods or use pre-defined quantum volume circuits available in PennyLane. With respect to all the comments and feedback what should be the next steps for me according to you ? I can submit the slides explaining the methodology used here

AbdullahKazi500 commented 1 month ago

Hi @bernardyeszero I Have updated the code with respect to your comments added the Haar Transform

def haar_transform(data):
    coeffs = pywt.dwt2(data, 'haar')
    return coeffs

# Inverse Haar Transform
def inverse_haar_transform(coeffs):
    return idwt2(coeffs, 'haar')

and got Absolute differences between corresponding components of Real and Generator Bloch vectors: [0.32047444951316284, 0.15128622661165836, 0.0800592130547021] Average absolute difference: 0.1839399630598411

AbdullahKazi500 commented 1 month ago

Hi @AbdullahKazi500, sorry for the late reply. Thanks for your PR (mainly, the file "QGANDorahacks (3).ipynb") about the classifications of general circuits. I carefully read the code and found some confusing problems.

  1. In the function quantum_volume_circuit_with_noise(), the three random numbers are generated to apply at Rx, Ry, and Rz, respectively to achieve random rotation. This is not a Harr random matrix for a Quantum Volume circuit. See this explanation from Pennylane: https://pennylane.ai/qml/demos/tutorial_haar_measure/. A similar example is generating a random point in the unit sphere uniformly. Though a point in a unit sphere could be written as (sin⁡θcos⁡ϕ,sin⁡θsin⁡ϕ,cos⁡θ), we can not generate uniform distribution using θ=random(0,2π) and ϕ=random(0,π), see this website: http://datagenetics.com/blog/january32020/index.html.
  2. I'm confused with the output of QGAN, which is used to generate a state to approach an ideal state. In the output, the "Real Bloch vector" is (-0.2169, 0.4505, -0.8660), but the "Generator Bloch vector" is (-0.0687, 0.4632, -0.8836). It's different.
  3. I found the classifier has no relationship with quantum circuits. So, the result of the accuracy of 57% seems perplexing.
  4. I found the code requires to be refactored, or you could submit some slides to highlight the methodology and results.

Thanks for your contributions again, and hope you enjoy the hackathon.

I enjoyed the hackathon thank you and would like to keep working on this even after the hackathon

AbdullahKazi500 commented 1 month ago

@bernardyeszero added the slides for your reference thank you once again and the dora ha team for this opportunity