# How to avoid Cirq: State_vector is not normalized error for Feedback-loop in optimizer?

I am doing a VQE in Cirq, but sometimes I get this error while running steps of the classical optimization loop: State_vector is not normalized instead had norm 1.0000000010132789 And therefore the program interrupts.

Is there anything I can do to avoid this? Because my state should be normalized the way I constructed the circuit.

• Is there anything preventing you from calling something like state_vector = state_vector / np.linalg.norm(state_vector) in your feedback loop? Also this question is probably better suited for the cirq github or gitter site: gitter.im/cirqdev Apr 21 at 19:48
• @forky40 Speaking as a cirq dev, quantum stack exchange is an excellent place for this type of question. Apr 22 at 17:32
• What method are you calling that throws the exception? VQE normally only works with gates and samples, no state vectors, so I'm not sure if you're specifying an initial state or analyzing a returned state. In both cases, manually normalizing the state should work but I want to be sure there's not something more serious hiding. Apr 22 at 17:34
• @CraigGidney I guess. This feels like it falls in the grey area of a question about a software implementation not behaving in the expected way where the root of the problem and its resolution only involve domain knowledge of qc in a tangential way. But I haven't found any community consensus on such questions so i could be wrong. Apr 22 at 19:26
• @forky40 It's a question about how to use software for simulating quantum computations. That seems right on topic to me. Apr 22 at 19:51