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

Save gates to JSON #1015

Merged
merged 4 commits into from
Sep 28, 2023
Merged

Save gates to JSON #1015

merged 4 commits into from
Sep 28, 2023

Conversation

Jacfomg
Copy link
Contributor

@Jacfomg Jacfomg commented Sep 21, 2023

Naive patch to save gates in RB implemented changes in qiboteam/qibocal#412.

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.

@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

All modified lines are covered by tests ✅

Files Coverage Δ
src/qibo/gates/abstract.py 100.00% <100.00%> (ø)

📢 Thoughts on this report? Let us know!.

Copy link
Member

@alecandido alecandido left a comment

Choose a reason for hiding this comment

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

The present one is just an addition, and it is not going to destroy anything, so for me is good to go.

I still believe we should improve the serialization, but most likely it will involve reworking a bit the Gate class itself.

@Jacfomg
Copy link
Contributor Author

Jacfomg commented Sep 21, 2023

The present one is just an addition, and it is not going to destroy anything, so for me is good to go.

I still believe we should improve the serialization, but most likely it will involve reworking a bit the Gate class itself.

If you have anything that could be simple to add I can try to implement it as well.

@Jacfomg Jacfomg marked this pull request as ready for review September 21, 2023 11:36
@alecandido
Copy link
Member

If you have anything that could be simple to add I can try to implement it as well.

That's the main problem: it might not be too simple.
But it's not too clear even to myself. So, as soon as you provide a suitable test we can merge.

src/qibo/gates/abstract.py Outdated Show resolved Hide resolved
src/qibo/gates/abstract.py Outdated Show resolved Hide resolved
src/qibo/gates/abstract.py Show resolved Hide resolved
Copy link
Member

@stavros11 stavros11 left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this. It is a bit minimal and I am not sure if it works for all gates (maybe it will fail for Unitary) but definitely better than nothing.

from typing import List, Sequence, Tuple

import sympy

from qibo.backends import GlobalBackend
from qibo.config import raise_error

REQUIRED_FIELDS = ["name", "init_kwargs", "_target_qubits", "_control_qubits"]
REQUIRED_FIELDS_INIT_KWARGS = ["theta", "phi", "lam"]
Copy link
Member

Choose a reason for hiding this comment

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

You could include the trainable here, right? Might be relevant for some applications, but I am not sure if those would use the serialization anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I don't know either, for what I needed it wasn't necessary. This can extended as the application that requires it appears. I would try to save the least for now.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, let's stick to something simple.

I want to rework the gates anyhow, and (if possible) write a simpler and more robust serialization. Maybe we will need to improve this in any case, but maybe not.

@Jacfomg
Copy link
Contributor Author

Jacfomg commented Sep 27, 2023

Thanks for implementing this. It is a bit minimal and I am not sure if it works for all gates (maybe it will fail for Unitary) but definitely better than nothing.

It does save the unitaries. In fact, most of the gates the RB saves are unitaries.

@alecandido alecandido merged commit b852689 into master Sep 28, 2023
26 checks passed
@alecandido alecandido deleted the save_gates branch September 28, 2023 05:44
@scarrazza scarrazza mentioned this pull request Oct 5, 2023
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