Implement a circuit as a matrix in ProjectQ

Suppose a have a circuit coded up in ProjectQ, suppose also it is that large to be hard enough to write it down as a unitary matrix by hands (e.g. order-finding, which is rather standard, but turns out to be very complex when you decompose the modular exponent into elementary 1- and 2-qubit gates, the typical Hilbert space size even for simple numbers would be $$2^8-2^{10}$$).

Can you propose or you maybe you already know an existing way how to obtain a unitary or even a product of unitaries that delivers the circuit results applied to initial state?

• For large circuits such as the one used in period finding, it is a bad idea to try to work with unitary matrices directly. The matrices are just too large. That's why ProjectQ has concepts like BasicMathGate to specify a gate in terms of a state permutation defined by a lambda. E.g. that's how MultiplyByConstantModN is implemented. – Craig Gidney Jan 9 at 18:43