Can create uncharged operators and states with "conserve_qns=true"

I noticed the following way to create \sigma^x does not flag any errors (I’m using v0.3.34),

s = siteinds("S=1/2",1;conserve_qns=true)
X = op("S+",s[1])+op("S-",s[1])

I found that flux(X) is equal to 2 which would suggest that only the top right entry should be non-zero (like S^+) but I mapped this to a dense array and I get the correct expression for X. I get no errors when performing multiplication or acting on other states. This also works when you increase the number of qubits.

I can also create the (unnormalized) |+\rangle eigenstate of X in a similar fashion by doing:

psi = state("Up",s[1])+state("Dn",s[1])

This also throws no error as well and flux(psi) equals 1.

Q: Why does this work?

Only some operations check for consistent fluxes, but also only if debug checks are enabled. So if you do:

ITensors.enable_debug_checks()
flux(X)

then it will error saying the flux is not well defined.

We made some judgement call on a case-by-case basis about which functions check for consistent fluxes (and sometimes only when debug checks are enabled) based on performance, for example if checking the flux could have similar cost to the operation itself.

In the case of adding two ITensors, if you are adding up tensors with very small blocks, checking the flux could cost as much as adding the two ITensors.

1 Like

Also even with debug checks disabled, you can explicitly check that the flux is consistent with ITensors.checkflux(X).