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

Add kwargs to arguments for Backend.get_compiled_circuit #962

Closed
wants to merge 6 commits into from

Conversation

sjdilkes
Copy link
Contributor

@sjdilkes sjdilkes commented Aug 9, 2023

No description provided.

@sjdilkes sjdilkes requested a review from cqc-alec August 9, 2023 16:17
Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

Should probably add to changelog, as this is an API change.

@@ -144,7 +143,9 @@ def rebase_pass(self) -> BasePass:
...

@abstractmethod
def default_compilation_pass(self, optimisation_level: int = 2) -> BasePass:
def default_compilation_pass(
self, optimisation_level: int = 2, **kwarfs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self, optimisation_level: int = 2, **kwarfs
self, optimisation_level: int = 2, **kwargs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that's an embarrassing one, fixed!

"""
return_circuit = circuit.copy()
self.default_compilation_pass(optimisation_level).apply(return_circuit)
self.default_compilation_pass(optimisation_level, kwargs).apply(return_circuit)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.default_compilation_pass(optimisation_level, kwargs).apply(return_circuit)
self.default_compilation_pass(optimisation_level, **kwargs).apply(return_circuit)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -213,7 +217,9 @@ def get_compiled_circuits(
:return: Compiled circuits.
:rtype: List[Circuit]
"""
return [self.get_compiled_circuit(c, optimisation_level) for c in circuits]
return [
self.get_compiled_circuit(c, optimisation_level, kwargs) for c in circuits
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.get_compiled_circuit(c, optimisation_level, kwargs) for c in circuits
self.get_compiled_circuit(c, optimisation_level, **kwargs) for c in circuits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

Ah! Is this going to break all the backends?

@sjdilkes
Copy link
Contributor Author

Ah! Is this going to break all the backends?

Yeah, they're all going need to have **kwargs added to their corresponding default_compilation_pass methods. I think it's worth it to allow users to pass backend specific optimisation choices through the usual interface, and at least any existing user code will work fine.

@cqc-alec
Copy link
Collaborator

Ah! Is this going to break all the backends?

Yeah, they're all going need to have **kwargs added to their corresponding default_compilation_pass methods. I think it's worth it to allow users to pass backend specific optimisation choices through the usual interface, and at least any existing user code will work fine.

But it does mean that if someone updates pytket their code will stop working, which breaks the 1.x API promise.

We could make new Backend methods get_default_compilation_pass_v2, get_compiled_circuit_v2 and get_compiled_circuits_v2 which take the kwargs and call the existing methods by default, and override them in pytket-quantinuum (making the old methods call the new ones)?

@sjdilkes
Copy link
Contributor Author

Ah! Is this going to break all the backends?

Yeah, they're all going need to have **kwargs added to their corresponding default_compilation_pass methods. I think it's worth it to allow users to pass backend specific optimisation choices through the usual interface, and at least any existing user code will work fine.

But it does mean that if someone updates pytket their code will stop working, which breaks the 1.x API promise.

We could make new Backend methods get_default_compilation_pass_v2, get_compiled_circuit_v2 and get_compiled_circuits_v2 which take the kwargs and call the existing methods by default, and override them in pytket-quantinuum (making the old methods call the new ones)?

Good point, I didn't think about people updating pytket but not the corresponding extension package.

That's a good idea - I'll do that now.

@sjdilkes
Copy link
Contributor Author

Ah! Is this going to break all the backends?

Yeah, they're all going need to have **kwargs added to their corresponding default_compilation_pass methods. I think it's worth it to allow users to pass backend specific optimisation choices through the usual interface, and at least any existing user code will work fine.

But it does mean that if someone updates pytket their code will stop working, which breaks the 1.x API promise.
We could make new Backend methods get_default_compilation_pass_v2, get_compiled_circuit_v2 and get_compiled_circuits_v2 which take the kwargs and call the existing methods by default, and override them in pytket-quantinuum (making the old methods call the new ones)?

Good point, I didn't think about people updating pytket but not the corresponding extension package.

That's a good idea - I'll do that now.

Do you think I should also include optimisation_level in the kwargs?

@cqc-alec
Copy link
Collaborator

Rethinking this whole thing...

@sjdilkes sjdilkes closed this Aug 10, 2023
@sjdilkes sjdilkes deleted the add-kwargs-to-get_compiled_circuit branch August 10, 2023 12:18
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.

2 participants