Questions in the polarization part of documentation

I met errors when going through the polarization part of the documentation:
first one:
p = pcvl.Polarization(sp.pi/2, sp.pi/4)
p.project_ev_eh()

and I got error:

TypeError Traceback (most recent call last)
/var/folders/4f/b5n_b3wj16n_66605bzq06ph0000gn/T/ipykernel_5837/2414637220.py in
----> 1 p = pcvl.Polarization(np.pi/2, np.pi/4)
2 p.project_ev_eh()

TypeError: init() takes 2 positional arguments but 3 were given

second one:
st3 = pcvl.AnnotatedBasicState("|{P:(sp.pi/2,sp.pi/3)>")
print(st3)

the error like this:

ValueError Traceback (most recent call last)
/var/folders/4f/b5n_b3wj16n_66605bzq06ph0000gn/T/ipykernel_5837/1753952641.py in
----> 1 st3 = pcvl.AnnotatedBasicState("|{P:(sp.pi/2,sp.pi/3)>")
2 print(st3)

/opt/anaconda3/lib/python3.9/site-packages/perceval/utils/statevector.py in init(self, bs, photon_annotations)
132 m = re.match(r"{(.?)}(.)", v)
133 if m is None:
→ 134 raise ValueError(“non-closed annotation: %s” % bs)
135 annotation = Annotations.parse_annotation(m.group(1))
136 v = m.group(2)

ValueError: non-closed annotation: |{P:(sp.pi/2,sp.pi/3)>

So how should I deal with these? Does anybody can help?

Hi,
Having a look at the library, I would say that the authors use sp as the short for sympy. But, in this situation, scipy would do the job as well.

For the first issue I think there is a small typo in the documentation. If you have a look at the code, the class Polarization accept only a string, a single float or a tuple. Thus, in your case, the correct command should be:

p = pcvl.Polarization((sp.pi/2, sp.pi/4))

Similarly, the second mistake is mainly caused by a missing closing braket }:

st3 = pcvl.AnnotatedBasicState("|{ P:(pi/2, pi/3) }")

Note that, if you write the string in this way "|{ P:(sp.pi/2, sp.pi/3) }" you will get another error because Sympy won’t be able to parse it.

Thanks Francesco for your answer ! just a small typo: there is missing > in your command - it should be:

st3 = pcvl.AnnotatedBasicState("|{P:(pi/2,pi/3)}>")

Thanks for the help,Francesco ! !