jcmgray / quimb

A python library for quantum information and many-body calculations including tensor networks.
http://quimb.readthedocs.io
Other
455 stars 107 forks source link

Circuit norm should be preseved as 1.0 while gate_apply #239

Closed Watayo closed 2 weeks ago

Watayo commented 2 weeks ago

What is your issue?

While experimenting with applying a two-qubit gate to quimb.tensor.CircuitMPS(), I noticed that it could not preserve the norm of states as 1.0 when entanglement possessed by the circuit surpasses the ability of TN states, which represents the circuit. When calculating the unitary dynamics with MPS states, it may be expected to renormalize the sum of the squares of the remaining singular values as 1.0 after truncating the small singular values. Accumulation of errors may cause further numerical troubles due to the operation of restoring the norm at the end of evolution. I naively modified it as follows:

  def _apply_gate(self, gate, tags=None, **gate_opts):
      tags = tags_to_oset(tags)
      if self.tag_gate_numbers:
          tags.add(self.gate_tag(self.num_gates))
      if self.tag_gate_rounds and (gate.round is not None):
          tags.add(self.round_tag(gate.round))
      if self.tag_gate_labels and (gate.tag is not None):
          tags.add(gate.tag)

      # overide any default gate opts
      opts = {**self.gate_opts, **gate_opts}
      opts["renorm"] = True # I added it

However, I have not investigated the effect of this change on other parts of the code. I would appreciate it if you could consider this fix.

jcmgray commented 2 weeks ago

Hi @Watayo, you should be able to simply supply:

circ = qtn.CircuitMPS(..., gate_opts=dict(renorm=True))

to set renormalization to default on. Let me know if that doesn't work!

Whether you renormalize on the go or at the end has no effect on compounding errors etc - its just a floating scalar. It defaulting to off is intentional - I prefer not renormalizating as 1) the norm contains useful information 2) you can always re-normalize at the end but its not so easy to 'un-normalize'. 3) It's not so clear that one should normalize the attained state by simply boosting the remaining part, as opposed to mixing it with the maximally mixed state.

Watayo commented 2 weeks ago

Thank you for early reply, @jcmgray ! I appreciated it to let me know why you set the defaulting to off intentionally.

Watayo commented 2 weeks ago

I had considered again and I guess that it is preferable to mention about it on the documentation. This is because after the norm reaches 0.0 in such as long time dynamics simulation, we cannot handle the calculation at all. Furthermore, I would like to recommend implementing a function that returns the exact norm while renormalizing at each application of a gate. Adding this setting could enhance convenience, and I hope you will consider it.