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

Refactor quimb backend #13

Merged
merged 6 commits into from
Feb 16, 2023
Merged

Conversation

alecandido
Copy link
Member

@alecandido alecandido commented Feb 15, 2023

Adopt Qibo QASM parser, i.e. construct the Quimb Circuit object directly from Qibo Circuit.

The code inside qibotn is not any longer tailored for QFT. So, feel free to try with any other Qibo circuit, and report in case something is broken.

(a known limitation is that Qibo gates have both .qubits attribute and `.target_qubits', but the latter is not used at present time; then, if qubits are renamed afterwards, w.r.t. the canonical naming, this is not propagated to Quimb - but I expect to be non-trivial to hit this corner case)

QASM

Notice that the function still reads QASM, so in the tests a QASM string is still generated and passed to the function. But instead of writing a dedicated parser, the Qibo parser is used, and it generates a temporary Qibo circuit inside the quimb backend.
So, at the moment there are two circuits: one in the tests, generating the QFT, that than is dump to QASM (still in tests), and the other inside the backend, loaded from the QASM.

If at some point we don't care any longer about accepting QASM input, we can always replace the input of eval() function (still lacking a better, but simple, name, given that I'm shadowing a built-in) directly with a Qibo circuit, and delegate the QASM parsing (i.e. the call to qibo.models.Circuit.from_qasm()) to the user.

Swaps

Before there was a dedicated handling for swaps. Given that Qibo is treating them as any other gate, at the moment I suppressed them everywhere, but in the qibo.models.QFT circuit generation.
If you are aware of any explicit reason to treat them separately from the rest, please explain me and I will try to fix it accordingly.

@alecandido alecandido mentioned this pull request Feb 15, 2023
@alecandido alecandido marked this pull request as ready for review February 15, 2023 15:38
@alecandido
Copy link
Member Author

@scarrazza workflows are not running because we exceed our quota.

@alecandido
Copy link
Member Author

However, locally on my Linux machine tests are now passing, and they are the exact same of #8

@alecandido alecandido force-pushed the quimb-qasm-parser branch 2 times, most recently from d88dd7a to bac9ad1 Compare February 15, 2023 16:18
Copy link
Contributor

@nitinshivaraman nitinshivaraman left a comment

Choose a reason for hiding this comment

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

Looks good!

@alecandido
Copy link
Member Author

Looks good!

Thanks, I'll wait for another review and then we can merge :)

Copy link
Contributor

@liweintu liweintu left a comment

Choose a reason for hiding this comment

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

Looks good, thanks.

@liweintu liweintu merged commit 176db90 into qasm_with_quimb_backend Feb 16, 2023
@liweintu
Copy link
Contributor

After merging, pytest hit an error below. Seems the cause is that quimb_time is too small when , failing to fit into the range of (0.01 * qibo_time, 100 * qibo_time).

  assert 1e-2 * qibo_time < quimb_time < 1e2 * qibo_time

E assert (0.01 * 1.6729983501136303) < 0.0031228289008140564

tests/test_qasm_quimb_backend.py:59: AssertionError
----------------------------------------- Captured stderr call ------------------------------------------
[Qibo 0.1.10|INFO|2023-02-16 16:49:43]: Using qibojit (cupy) backend on /GPU:0
------------------------------------------- Captured log call -------------------------------------------
INFO qibo.config:init.py:85 Using qibojit (cupy) backend on /GPU:0

@alecandido
Copy link
Member Author

alecandido commented Feb 16, 2023

After merging, pytest hit an error below. Seems the cause is that quimb_time is too small when , failing to fit into the range of (0.01 * qibo_time, 100 * qibo_time).

This is an extra condition I added, not to leave times unused. It was a rough attempt, but I considered unlikely to fail.
@scarrazza should I simply drop it?

EDIT: I believe it might only fail on a machine with an available GPU, e.g. not mine, but that is an interesting information: why Qibo is so slow with cupy backend, if Quimb is so fast?

@alecandido alecandido deleted the quimb-qasm-parser branch February 16, 2023 11:14
@alecandido alecandido restored the quimb-qasm-parser branch February 24, 2023 16:40
@alecandido alecandido deleted the quimb-qasm-parser branch February 24, 2023 16:40
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