I would like to generate a random MPS within a particular particle-number subspace, which I can then convert to a generic MPS so that I can apply gates which cause the state to leave the initial sub-space.
Generating the initial MPS is easy with something like:
N=4
chi=2
sites = siteinds("S=1/2",N; conserve_qns=true)
state = [isodd(n) ? "Up" : "Dn" for n=1:N]
psi0 = randomMPS(sites, state; linkdims=chi)
however it is how to convert this back to the generic MPS format that is not clear to me, so that I can apply arbitrary gates to this state.
For converting a quantum number conserving MPS to a generic, dense MPS without any quantum number or block structure, you can call the function dense on your MPS to return a new MPS with the quantum number and block structure removed.
For example, at the end of your code you can add a line psi0 = dense(psi0) and psi0 will be overwritten with a new MPS of dense ITensors that are identical to your original ones just with the quantum number structure removed.