-
Notifications
You must be signed in to change notification settings - Fork 114
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
Remove Tket dependencies for PennyLane model #195
base: main
Are you sure you want to change the base?
Remove Tket dependencies for PennyLane model #195
Conversation
… and other backends. Type checks.
… and other backends. Type checks.
… up in future commit.
lambeq/backend/quantum.py
Outdated
|
||
Returns | ||
------- | ||
Dict: |
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.
Let's create a dedicated re-usable public class for the circuit dictionary, with specific attributes for each part/list. We might add more functionality in the future.
With this PR (or a follow-up), we should also move tket to optional dependencies in setup.cfg, e.g. like PennyLane. @nikhilkhatri @blakewilsonquantinuum is there any reason to keep it as a required dependency? |
@blakewilsonquantinuum As discussed, the new implementation stay consistently behind the old ones in terms of times (although not much). It might be good to do some more detailed time profiling and detect any bottlenecks. |
@@ -1912,14 +1970,14 @@ class Functor: | |||
>>> n = Ty('n') | |||
>>> diag = Cap(n, n.l) @ Id(n) >> Id(n) @ Cup(n.l, n) | |||
>>> diag.draw( | |||
... figsize=(2, 2), path='./snake.png') | |||
... figsize=(2, 2), path='./docs/_static/images/snake.png') |
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.
Be sure you pull the main again, this file here looks outdated (or some problem happened with conflict resolution).
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.
Also, be sure to keep the upstream changes for these images above.
lambeq/backend/quantum.py
Outdated
offset: int, | ||
gates: list[Layer]) -> Tuple[list[Layer], list[Layer]]: | ||
|
||
# Adds a qubit to the qubit list |
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 not using """ here?
lambeq/backend/converters/tk.py
Outdated
elif not gate['type'] in OPTYPE_MAP: | ||
raise NotImplementedError(f'Gate {gate} not supported') | ||
|
||
if 'phase' in gate and gate['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.
if gate.get('phase'):
should do.
lambeq/backend/quantum.py
Outdated
checks if a diagram is a quantum 'circuital' diagram. | ||
A circuital diagram is a diagram with qubits at the top. | ||
|
||
Used to check for measurements and post-selection |
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.
Is this referring to what the case was in the previous version? Is this information useful at all here?
lambeq/backend/converters/tk.py
Outdated
@@ -362,6 +211,71 @@ def _tk_to_lmbq_param(theta): | |||
raise ValueError('Parameter must be a (possibly scaled) sympy Symbol') | |||
|
|||
|
|||
def to_tk(diagram: Diagram): |
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 return type here?
lambeq/backend/pennylane.py
Outdated
|
||
|
||
def to_pennylane(lambeq_circuit: Diagram, probabilities=False, | ||
def to_pennylane(diagram: Diagram, probabilities=False, |
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.
Return type.
lambeq/backend/quantum.py
Outdated
return True | ||
|
||
|
||
def to_circuital(diagram: Diagram): |
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.
Return type.
lambeq/backend/quantum.py
Outdated
return layerD | ||
|
||
|
||
def circuital_to_dict(diagram: Diagram): |
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.
return type.
lambeq/backend/pennylane.py
Outdated
} | ||
|
||
|
||
def tk_op_to_pennylane(tk_op): | ||
def extract_ops_from_circuital(circuit_dict: dict): |
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.
Return type.
Many return types are missing, I have marked some but probably there are more, please check everywhere. |
@blakewilsonquantinuum For the deepcopy speed issue. Can you try to do it with serialisation to see how it compares? e.g. something like: import pickle
serialized = pickle.dumps(my_object)
deep_copy = pickle.loads(serialized) |
Currently, to make a pennylane circuit, we construct a tket circuit, extract the ops, and then construct the pennylane circuit from that. This requires tket being a middle man for any circuit conversion. Instead, we can convert to a preliminary diagram compatible with all circuits before converting to the particular backend.
make_circuital function - Built. Needs more testing.
Pulls qubits to the top of the diagram.
Pulls measurements to the bottom of the diagram.
Orders qubits and measurements so they are easy to build a circuit.
Type checks each layer to ensure a valid diagram.
Type checking has been tested on all diagrams from the mc_dataset.
is_circuital - Needs built.
Checks if a diagram is a valid circuital diagram.
Verifies qubits, measurements, and gates are all placed correctly and type checks.
started to build in the draft PR.
from_circuit - Needs built.
Function to build a tket, pennylane, or other circuit using the preliminary circuit.
Refactor tket, pennylane, and torch_quantum to use the above functions for building their circuits.