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

feat: to_other_language cirq without QASM2.0 #119

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

JulienCalistoTD
Copy link
Collaborator

No description provided.

Copy link
Contributor

@hJaffaliColibritd hJaffaliColibritd left a 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

mpqp/core/circuit.py Show resolved Hide resolved
mpqp/core/circuit.py Show resolved Hide resolved
controls.append(cirq_qubits[control])
cirq_instruction = instruction.to_other_language(Language.CIRQ)
cirq_circuit.append(cirq_instruction.on(*controls, *targets))
else:
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, even BasisMeasure ?

Copy link
Collaborator Author

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

Copy link
Contributor

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 ?

Copy link
Contributor

@Henri-ColibrITD Henri-ColibrITD left a 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:
Copy link
Contributor

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
Copy link
Contributor

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 ?

Copy link
Collaborator Author

@JulienCalistoTD JulienCalistoTD Jan 15, 2025

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]
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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.

Copy link
Contributor

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}, '
Copy link
Contributor

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 ?

Copy link
Collaborator Author

@JulienCalistoTD JulienCalistoTD Jan 15, 2025

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.

mpqp/core/instruction/gates/native_gates.py Show resolved Hide resolved
def cirq_gate(cls):
from cirq.ops.common_gates import ZPowGate

return lambda theta: ZPowGate(exponent=theta / np.pi)
Copy link
Contributor

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

Copy link
Collaborator Author

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))
Copy link
Contributor

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

Copy link
Collaborator Author

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:
Copy link
Contributor

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

Copy link
Collaborator Author

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

Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Collaborator Author

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:
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

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:
Copy link
Contributor

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 ?

mpqp/core/instruction/gates/native_gates.py Show resolved Hide resolved
from cirq.ops.global_phase_op import GlobalPhaseGate
from cirq.ops.raw_types import Qid

class CirqUGate(QasmUGate): # pyright: ignore[reportUntypedBaseClass]
Copy link
Contributor

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.

mpqp/core/instruction/gates/native_gates.py Show resolved Hide resolved
mpqp/execution/providers/google.py Show resolved Hide resolved
@@ -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:
Copy link
Contributor

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:
Copy link
Contributor

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants