Renmusxd / RustQIP

Quantum computing using rust. Efficient and a borrow-checked no cloning theorem!
https://docs.rs/qip/
MIT License
223 stars 18 forks source link

Rewrite for 1.0 #39

Open Renmusxd opened 2 years ago

Renmusxd commented 2 years ago

Much of this library isn't idiomatic rust - nor is it really well written to be honest with myself. The numerics under the hood are fine and fairly well optimized, the issue is that the UnitaryBuilder trait and pipeline constructor heavily uses dynamic dispatch. Switching over to generics and traits would allow for much more flexibility from a type system perspective. This would require a large reorganization, and much of the responsibility of the classes would need to be moved around.

Renmusxd commented 2 years ago

91e98a9149975cc7f8372deee205226d28c6bb42 is the first stable large reorganization matching all the above criteria. A few modules have been dropped for now (unfortunately including the some macro support). Slowly working on reintroducing these. the program and wrap_fn/invert_fn macros really need to be rewritten as procedural macros now to properly deal with generics and the stronger type constraints introduced by no longer using the dyn keyword.

Renmusxd commented 2 years ago

After some thought it seems the program! and wrap! / invert_fn! macros need to be significantly rethought. I believe with the strong types in the rewrite (such as no use of dyn) they can't be rewritten as macro_rules! without some significant complexity.

I am slowly learning how to write procedural macros to add these back in, since they are a cornerstone of QOL for this project.

Renmusxd commented 2 years ago

1ab3a11 is the bulk of the program! rewrite, it is now a procedural macro living in a package adjacent to the core qip code. It can be enabled via the "macros" feature. Some of the previously supported modules are gated by this now since they make heavy use of program!

The syntax changed a bit (mostly just additional semicolons and now longer requiring vertical bars where we would have preferred parens or square brackets), I'll update docs soon.

Renmusxd commented 2 years ago

Docs updated in f9940ca - while making the invert macro found a bug in some code from 91e98a9 for making subcircuits. This (further) tells me that I need to work on reintroducing the unit tests before working on any new 1.0 features.