-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
The UnitaryGate
class is defined in Python and that means that when we need to work with it from Rust (either for transpiler passes or circuit construction) we treat it as a PyInstruction
and that requires that we use Python for interacting with it. For the most part for reading this isn't a huge overhead because a UnitaryGate
is a gate defined around a unitary matrix as a numpy array and we typically just need to inspect that matrix which can be done by reference without any copying or conversion. However, on writing (typically creation), which we do a fair amount of in the transpiler and the circuit library, the python overhead is significant. In rust it will be easy to build a UnitaryGate
struct that implements the Operation
trait and owns an Array2<Complex64>
. We might need to think a bit about the python interface and split of responsibilities between the languages because we can generate a numpy array from a owned array but the traits in rust-numpy for doing that either consume the array or copy it.
This weakly depends on #12966 as we'll need to figure out the best way to expand PackedOperation to support this and the pattern we establish in #12966 will inform this.