unitaryfund / pyqrack

Pure Python bindings for the pure C++11/OpenCL Qrack quantum computer simulator library
MIT License
16 stars 8 forks source link

Unit tests: mirror circuits #13

Closed WrathfulSpatula closed 1 year ago

WrathfulSpatula commented 2 years ago

We rely on Qrack library unit tests, but a random mirror circuit integration test should be adapted from the underlying Qrack test suite. It can give excellent coverage in a fast test, though it's not modular. At least, it's a tractable atomic step toward PyQrack unit tests and tooling.

WrathfulSpatula commented 2 years ago

More generally, we need a PyQrack-specific unit test suite. This is worth a unitaryhack.dev bounty.

golanor commented 1 year ago

I've started to look into this, one thing I'm missing is how to create circuits in PyQrack without using Qiskit. Is there a way to do this without supplying gates/loading from file? OR should I install qiskit alongside PyQrack and add it as a test dependency?

WrathfulSpatula commented 1 year ago

Historically, Qrack always worked in terms of "immediate" gates on simulator instances, not circuit definitions. To "save a circuit," you would simply write (and save) a Qrack program in terms of immediate gates on a simulator.

However, we've recently added QrackCircuit. (https://pyqrack.readthedocs.io/en/latest/autoapi/pyqrack/qrack_circuit/index.html)

The point of saving to and loading from file is that you can store the optimized circuit compilation result at all: otherwise, you're still writing a Qrack program, loaded at run time, which is no different from how Qiskit does it, as far as I know.

I would suggest simply writing a program in terms of "immediate" Qrack gates, particularly as QrackCircuit might optimize away parts of logical tests you want to check.

WrathfulSpatula commented 1 year ago

It's also worth pointing out that here's an example of a mirror circuit integration test, for PyQrack:

https://github.com/unitaryfund/research/blob/main/qrack-report/plots/Qrack_mirror_circuit_validation.ipynb

This test mirrors the definition of a "forward" circuit in QrackCircuit, with an "uncomputation" by immediate gates. This way, both QrackCircuit and QrackSimulator are reasonably well-covered.