Unicode Error when launching PSI4 driver (using Windows)
See original GitHub issueWhen using psi4 as driver for my vqe calculations, I get the following error:
Traceback (most recent call last):
File "C:\Users\poc\Anaconda3\envs\qiskit-0-27-psi4-jupyter\Scripts\psi4-script.py", line 336, in <module>
exec(content)
File "<string>", line 31
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Printing out the relevant lines from the Psithon --> Python processed input file:
!----------------------------------------------------------------------------------!
! !
! (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: !
! truncated \UXXXXXXXX escape !
! !
!----------------------------------------------------------------------------------!
Traceback (most recent call last):
File "c:\Users\poc\Documents\qiskit_scripts\groundstatesolver.py", line 336, in <module>
compare_mappers()
File "c:\Users\poc\Documents\qiskit_scripts\groundstatesolver.py", line 206, in compare_mappers
second_q_op = es_problem.second_q_ops()
File "C:\Users\poc\Anaconda3\envs\qiskit-0-27-psi4-jupyter\lib\site-packages\qiskit_nature\problems\second_quantization\electronic\electronic_structure_problem.py", line 64, in second_q_ops
self._molecule_data = cast(QMolecule, self.driver.run())
File "C:\Users\poc\Anaconda3\envs\qiskit-0-27-psi4-jupyter\lib\site-packages\qiskit_nature\drivers\psi4d\psi4driver.py", line 160, in run
PSI4Driver._run_psi4(input_file, output_file)
File "C:\Users\poc\Anaconda3\envs\qiskit-0-27-psi4-jupyter\lib\site-packages\qiskit_nature\drivers\psi4d\psi4driver.py", line 215, in _run_psi4
raise QiskitNatureError('{} process return code {}\n{}'.format(
qiskit_nature.exceptions.QiskitNatureError: 'psi4 process return code 1\nTraceback (most recent call last):\n File "C:\\Users\\poc\\Anaconda3\\envs\\qiskit-0-27-psi4-jupyter\\Scripts\\psi4-script.py", line 336, in <module>\n exec(content)\n\n File "<string>", line 31\nSyntaxError: (unicode error) \'unicodeescape\' codec can\'t decode bytes in position 2-3: truncated \\UXXXXXXXX escape\n\nPrinting out the relevant lines from the Psithon --> Python processed input file:\n\n\n!----------------------------------------------------------------------------------!\n! !\n! (unicode error) \'unicodeescape\' codec can\'t decode bytes in position 2-3: !\n! truncated \\UXXXXXXXX escape !\n! !\n!----------------------------------------------------------------------------------!\n\n'
With the kind help of some psi4 developers I could track down it to these lines: https://github.com/Qiskit/qiskit-nature/blob/c7fa055cfba2dc08daef0111e569ae5eb9bce10b/qiskit_nature/drivers/psi4d/psi4driver.py#L123-L133
I was able to get rid of the problem via changing above lines to this:
qiskit_nature_directory = os.path.abspath(os.path.join(psi4d_directory, "../.."))
molecule = QMolecule()
input_text = cfg + "\n"
input_text += "import sys\n"
syspath = "['" + qiskit_nature_directory.replace("\\", "\\\\") + "','" + "','".join(p.replace("\\", "\\\\") for p in sys.path) + "']"
input_text += "sys.path = " + syspath + " + sys.path\n"
input_text += "from qiskit_nature.drivers.qmolecule import QMolecule\n"
input_text += "_q_molecule = QMolecule('" + molecule.filename.replace("\\", "\\\\") + "')\n"
Unfortunately this fix is not cross-platform compatible but quite windows-specific. So, any help finding a nice fix for this bug or even a simplified/less error-prone way to call psi4 would be appreciated.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
(unicode error) 'unicodeescape' codec can't decode bytes in ...
This error occurs, because you are using a normal string as a path. ... Qiskit/qiskit-natureUnicode Error when launching PSI4 driver (using Windows)#260.
Read more >(unicode error) 'unicodeescape' codec can't decode bytes in ...
This error message... options.add_argument("user-data-dir=C:\Users\Username\AppData\Local\Google\Chrome\User\Data") ^ SyntaxError: (unicode ...
Read more >Unicode Error when trying to use Command Prompt with USB ...
I have problems when trying to use unicode characters like Russian characters (Cyrillic) on the Command Prompt (CMD).
Read more >Strange crash on Psi4
Hi; I installed Psi4 using conda, and run it on AMd64. WHen I try to run it I get the following problem: Traceback...
Read more >Understanding Unicode errors when opening Windows files
Have you ever tried to open a file on a Windows machine, only to get a weird Unicode error ? This video will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We should leave this open until the PR that fixes this #262 is merged. I edited it so once it merges it will auto-close this.
If the problem of this issue is related to paths I suggest looking into pathlib to replace the
os.path
usage. It has built-in platform support/detection and should simplify these things a lot.