A Qubit DSL?

I do agree that it would be really nice to have |ψ⟩ et cetera lower to something, but I am certainly quite biased on that matter as my background is primarily in quantum field theory. I do think that having ⟨args...⟩ lower to, for example vev(args...) would also be useful in contexts other than quantum mechanics.

I do think that if this gets done the lowering rules should be pretty general. Bear in mind that in the general case the Hilbert space is not required to be finite dimensional or even separable, so I don’t think we should assume that kets can be represented as a Julia AbstractVector (which always have a finite, integer length).

My suggestion would be

  • |args...⟩ lower to ket(args...)
  • ⟨args...| lowers to bra(args...)
  • ⟨bra_args...|ket_args...⟩ lowers to braket(tuple(bra_args...), tuple(ket_args...))
  • ⟨bra_args...|O|ket_args...⟩ lowers to braket(tuple(bra_args...), O, tuple(ket_args...))
  • ⟨args...⟩ lowers to vev(args...)

and that, with the possible exception of vev, that none of these functions be defined in Base. That would allow package developers to assign them as needed and not have any constraints on what the underlying data structures are called. One objection I anticipate is that this might be considered encouraging type piracy, and I’m not sure I have a good defense for that.

4 Likes