-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: to_other_language cirq without QASM2.0 #119
base: dev
Are you sure you want to change the base?
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.
Only reviewed circuit.py
controls.append(cirq_qubits[control]) | ||
cirq_instruction = instruction.to_other_language(Language.CIRQ) | ||
cirq_circuit.append(cirq_instruction.on(*controls, *targets)) | ||
else: |
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.
Here we handle all the other cases ? (Parametrized gate, Barrier, BasisMeasure, ..) right ?
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.
Cirq doesn't have a Barrier operation, so we skips it. breakpoints is also skip. While the rest is handled properly.
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.
Ok, even BasisMeasure ?
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.
The BasisMeasure is a simple measurement with a pre-measurement circuit, we juste have to concatenate it. so yes
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.
Do we concatenate this pre-measurement circuit (the one related with the basis change I suppose) somewhere? (because I checked the code, and I didn't found it).
But I ask myself if we should include that change of basis or not. I am not convinced personally, but if we do we have to warn the user. I would export the circuit without the change of basis additional unitary. What do you think ?
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.
minor questions
controls.append(cirq_qubits[control]) | ||
cirq_instruction = instruction.to_other_language(Language.CIRQ) | ||
cirq_circuit.append(cirq_instruction.on(*controls, *targets)) | ||
else: |
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.
Ok, even BasisMeasure ?
|
||
return lambda theta: CirqControlledGate(ZPowGate(exponent=theta / np.pi)) | ||
|
||
return controlled_phase |
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.
This line is useless right ?
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.
done: removed
from cirq.ops.global_phase_op import GlobalPhaseGate | ||
from cirq.ops.raw_types import Qid | ||
|
||
class CirqUGate(QasmUGate): # pyright: ignore[reportUntypedBaseClass] |
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.
The class will be redifined each time we call the property. Isn't it better if we define the class outside and only return it when needed ?
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.
No, because there are many import requirements and we only want to import them if we use this function.
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.
Ok, I think we can find another way, but can keep it like this for the moment and add a 3M-TODO to improve this. You can resolve this conversation yourself once the todo is added.
def __repr__(self) -> str: | ||
return ( | ||
f'U(' | ||
f'theta={self.theta !r}, ' |
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.
Why !r
is used for theta and hi, and not for lambda ?
Another question concerning those angles, no need to tweak them with some division by pi ? When you can ry and rz in the decompose ?
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.
because it is an end of line so does not need to be added at the end. No we don't need to tweak the angle.
def cirq_gate(cls): | ||
from cirq.ops.common_gates import ZPowGate | ||
|
||
return lambda theta: ZPowGate(exponent=theta / np.pi) |
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.
Same question as for Rk
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.
Same answer as for Rk
from cirq.ops.controlled_gate import ControlledGate as CirqControlledGate | ||
from cirq.ops.common_gates import ZPowGate | ||
|
||
return lambda theta: CirqControlledGate(ZPowGate(exponent=theta / np.pi)) |
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.
Same question as for Rk
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.
Same answer as for Rk
@@ -161,7 +161,7 @@ def closest_unitary(matrix: Matrix): | |||
|
|||
|
|||
@typechecked | |||
def cos(angle: Expr | Real) -> sp.Expr | float: | |||
def cos(angle: Expr | Real | float) -> sp.Expr | float: |
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.
In principle, no need to add float
here, as it is "contained" in Real
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.
yes, but i had typcheck issues
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.
so at the end Real from the package number worked no ? This join the same discussion as Complex from numbers
@@ -186,7 +186,7 @@ def cos(angle: Expr | Real) -> sp.Expr | float: | |||
|
|||
|
|||
@typechecked | |||
def sin(angle: Expr | Real) -> sp.Expr | float: | |||
def sin(angle: Expr | Real | float) -> sp.Expr | float: |
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.
same as above
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.
same as above
@@ -211,7 +211,7 @@ def sin(angle: Expr | Real) -> sp.Expr | float: | |||
|
|||
|
|||
@typechecked | |||
def exp(angle: Expr | Complex) -> sp.Expr | complex: | |||
def exp(angle: Expr | Complex | complex) -> sp.Expr | complex: |
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.
Same remark for complex
and Complex
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.
same as above
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.
this worked at the end right ?
controls.append(cirq_qubits[control]) | ||
cirq_instruction = instruction.to_other_language(Language.CIRQ) | ||
cirq_circuit.append(cirq_instruction.on(*controls, *targets)) | ||
else: |
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.
Do we concatenate this pre-measurement circuit (the one related with the basis change I suppose) somewhere? (because I checked the code, and I didn't found it).
But I ask myself if we should include that change of basis or not. I am not convinced personally, but if we do we have to warn the user. I would export the circuit without the change of basis additional unitary. What do you think ?
from cirq.ops.global_phase_op import GlobalPhaseGate | ||
from cirq.ops.raw_types import Qid | ||
|
||
class CirqUGate(QasmUGate): # pyright: ignore[reportUntypedBaseClass] |
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.
Ok, I think we can find another way, but can keep it like this for the moment and add a 3M-TODO to improve this. You can resolve this conversation yourself once the todo is added.
@@ -161,7 +161,7 @@ def closest_unitary(matrix: Matrix): | |||
|
|||
|
|||
@typechecked | |||
def cos(angle: Expr | Real) -> sp.Expr | float: | |||
def cos(angle: Expr | Real | float) -> sp.Expr | float: |
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.
so at the end Real from the package number worked no ? This join the same discussion as Complex from numbers
@@ -211,7 +211,7 @@ def sin(angle: Expr | Real) -> sp.Expr | float: | |||
|
|||
|
|||
@typechecked | |||
def exp(angle: Expr | Complex) -> sp.Expr | complex: | |||
def exp(angle: Expr | Complex | complex) -> sp.Expr | complex: |
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.
this worked at the end right ?
No description provided.