-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/Support pennylane's Hamiltonian and Circuit #107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also fix pyproject.toml because the tests fail
Lines 45 to 47 in b1efe3c
qiskit = ["qiskit"] | |
quri-parts = ["quri-parts-qulacs"] | |
qutip = ["qutip"] |
Changes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left the comments.
pyproject.toml
Outdated
@@ -25,7 +25,7 @@ quri-parts-circuit = "^0.19.0" | |||
qiskit = "^1.1.1" | |||
matplotlib = "^3.9.2" | |||
qutip = "^5.0.4" | |||
|
|||
PennyLane = "^0.39.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small letter is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIxed
pyproject.toml
Outdated
@@ -45,6 +45,7 @@ matplotlib = "^3.9.2" | |||
qiskit = ["qiskit"] | |||
quri-parts = ["quri-parts-qulacs"] | |||
qutip = ["qutip"] | |||
PennyLane = ["PennyLane"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small letter is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Here is a simple usage of the Parameter gate transfer from QamomileCircuit to pennylane Qnode. from qamomile.core.circuit import QuantumCircuit as QamomileCircuit
import pennylane as qml
import numpy as np
import qamomile
from qamomile.pennylane.transpiler import PennylaneTranspiler
from qamomile.core.circuit import Parameter
qc = QamomileCircuit(3)
theta = Parameter("theta")
beta = Parameter("beta")
gamma = Parameter("gamma")
qc.rx(theta, 0)
qc.ry(beta, 1)
qc.rz(gamma, 2)
qc.crx(gamma, 0 ,1)
qc.crz(theta, 1 ,2)
qc.cry(beta, 2 ,0)
transpiler = PennylaneTranspiler()
QNode = transpiler.transpile_circuit(qc)
print("QN: ", QNode)
p= {"theta":0.1,"beta":0.2, "gamma": 0.3}
qml.drawer.use_style("black_white")
fig, ax = qml.draw_mpl(QNode)(theta=0.1,beta=0.2, gamma=0.3) |
New feture updated
Fixed @ahao27 Qamomile/qamomile/pennylane/transpiler.py Lines 233 to 250 in aa614bf
|
I have modified Qamomile/qamomile/pennylane/transpiler.py Lines 137 to 150 in 03627f1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please implement convert_result
"source": [ | ||
"### Pennylane Backend\n", | ||
"\n", | ||
"Here's how you can execute a Qamomile circuit using Qpennylane.\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qpennylane
is typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I have left the comments
qamomile/pennylane/transpiler.py
Outdated
""" | ||
Convert the result from PennyLane execution to a Qamomile-compatible result. | ||
|
||
Currently not implemented. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write the docstring?
And also, can you fix the type?
qamomile/pennylane/transpiler.py
Outdated
return None | ||
|
||
decimal_result_data = {binary_to_decimal(key): value for key, value in result.items()} | ||
num_bits = len(result.popitem()[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think popitem
modifies the result
, so we should not use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
👍 |
Description
Add a new transpiler to support Pennylane's Hamiltonian format in Qamomile.
This PR introduces a transpiler specifically designed to convert Qamomile's Hamiltonians into Pennylane's Hamiltonians, enhancing the interoperability between the two quantum frameworks.
Changes
Implements the PennylaneTranspiler class, which handles the conversion of Qamomile's Hamiltonians into Pennylane's qml.Hamiltonian objects.
transpiler.py:
Supports Pauli-X, Pauli-Y, and Pauli-Z operators, with appropriate error handling for unsupported cases.
exception.py:
Introduces custom exceptions for handling unsupported operations during the transpilation process.
init.py:
Allows for module initialization and ensures proper package integration.
Created test_pennylane_transpiler.py to validate the correctness of the transpiler.
Test cases cover:
Inline docstrings were added to describe the purpose and functionality of each method and class.