Python3 error in python api 1.1rc2.dev1

Not sure whether this is the right place but
after installing psi4 from git 1.1rc2.dev1 on fedora (fc25) linux the python api mode works under python3, (not under python2 because the cmake has detected python3 ). However the old mode of calling like, e.g. psi4 sample.in does not work because in the translation from psithon input to python generates incompatible python code.

By explicitly looking at the generated python (adding print (content) to the psi4 script, which is python 3.5) I found that the statement

print “\n\tToday: “, now.strftime(”%Y-%m-%d %H:%M\n”)

is invalid because python3 wants parentheses around the argument:

print ( “\n\tToday: “, now.strftime(”%Y-%m-%d %H:%M\n”) )

In this case that is easily fixed but a larger inputfile would probably generate many more print without parentheses and possibly also other incompatibilities.

It would seem to me that this is a minor bug that easily can be fixed. Removing python3 from the system is not an option, if possible at all.

//Thijs H.

If I understand you correctly this is an issue with your own input file that it is not Python 3 compatible. You can use the following regex to update your python script from 2 to 3:

:%s/^\(\s*print\)\s\+\(.*\)/\1(\2)

We could consider parsing this for the user, but it would seem that the logic behind this could grow to be fairly complex.

Thanks for the regex. But the problem is not with my own scripts, these are easily modified. The problem is that psi4 seems to be internally inconsistent when using python3. Let me try to explain. Fedora is pyhton3. When installing the new psi4 1.1rc2 it detects this and the psi4 executable (which is a python script) that is generated consequently is pythnon3:

which psi4
/usr/local/mytmp/Psi4-git/psi-inst/bin/psi4

head -5 /usr/local/mytmp/Psi4-git/psi-inst/bin/psi4

#!/bin/python3.5

@BEGIN LICENSE

Now run psi4:

cat sample.in
molecule {
He
}
energy(‘hf/cc-pvdz’)
compare_values(-2.85518839, get_variable(‘current energy’), 5, ‘SCF E’)

psi4 sample.in
Traceback (most recent call last):
File “/usr/local/mytmp/Psi4-git/psi-inst/bin/psi4”, line 250, in
exec(content)

SyntaxError: invalid syntax (, line 17)

The error is that the above psithon input is translated to python2, in variable “content”
above which is an argument to exec() which exects python3, in this case.

I think the easiest way out is to apply some regex to “content” so that it is updated to python3 if necessary.

Anyway there are no problems when running psi4 in the new pyton API mode. Actually it was when I wanted to run some of Daniels (dgasmith) scripts that I decided to install the latest psi4. Modifying these scripts to python3 is a very minor task and works fine. But then when running psi4 in t he old wayi, e.g. “psi4 sample.in”, I ran into the above mentioned problem, which I just wanted to point out.

//Thijs H.

Ah, I see. I cannot reproduce on my laptop. Can you run the project as psi4 -v sample.in and post the entire output here?

Out of curiosity, which of my scripts are you running?

I run the electron propagator scripts

here comes the output of psi4 -v sample.in
look for the line
print “\n\tToday: “, now.strftime(”%Y-%m-%d %H:%M\n”)
there is nothing wrong with the translation, but it is not python3

cat sample.out
-----------------------------------------------------------------------
Psi4: An Open-Source Ab Initio Electronic Structure Package
Psi4 1.1rc2.dev1

                     Git: Rev {master} 3e691f9 


R. M. Parrish, L. A. Burns, D. G. A. Smith, A. C. Simmonett,
A. E. DePrince III, E. G. Hohenstein, U. Bozkaya, A. Yu. Sokolov,
R. Di Remigio, R. M. Richard, J. F. Gonthier, A. M. James,
H. R. McAlexander, A. Kumar, M. Saitow, X. Wang, B. P. Pritchard,
P. Verma, H. F. Schaefer III, K. Patkowski, R. A. King, E. F. Valeev,
F. A. Evangelista, J. M. Turney, T. D. Crawford, and C. D. Sherrill,
submitted.

-----------------------------------------------------------------------


Psi4 started on: Monday, 10 April 2017 04:44PM

Process ID:  13182
PSIDATADIR: /usr/local/mytmp/Psi4-git/psi-inst/share/psi4
Memory:     500.0 MiB
Threads:    1

==> Input File <==


molecule {
He
}
energy(‘hf/cc-pvdz’)
compare_values(-2.85518839, get_variable(‘current energy’), 5, ‘SCF E’)

Parsed Psithon:
import psi4
from psi4 import *
from psi4.core import *
from psi4.driver.diatomic import anharmonicity
from psi4.driver.gaussian_n import *
from psi4.driver.aliases import *
from psi4.driver.driver_cbs import xtpl_highest_1, scf_xtpl_helgaker_2, scf_xtpl_helgaker_3, corl_xtpl_helgaker_2
from psi4.driver.wrapper_database import database, db, DB_RGT, DB_RXN
from psi4.driver.wrapper_autofrag import auto_fragments
from psi4.driver.constants.physconst import *
psi4_io = core.IOManager.shared_object()
import os

import datetime
now = datetime.datetime.now()
print “\n\tToday: “, now.strftime(”%Y-%m-%d %H:%M\n”)

Set the default path for all PSI4 data files. Be sure to include the trailing ‘/’ .

Uncomment the final line(s) of one of the options below or construct your own set_default_path

[1]

Sends scratch files for all jobs to one place. Usually safe since pid labeled.

Useful when psi4 is run on box from which it’s called (not queued cluster system)

psi4_io.set_default_path(’/scratch/parrish/’)

os.system(‘if [[ ! -d /tmp/Scratch ]] ; then mkdir /tmp/Scratch; echo -e “\n\t/tmp/Scratch created\n” ; fi’)
psi4_io.set_default_path(’/tmp/Scratch’)

[2]

Sends scratch files to directory from which psi4 was called.

Useful when running from scratch in a queued cluster system.

#psi4_io.set_default_path(’./’)

[3]

Sends scratch files to directory in an environment variable.

Useful in a queued cluster system when running from a working directory

but want big scratch files in an on-the-fly-named scratch directory $myscratch

#job_scratch_pbs = os.environ.get(‘myscratch’)
#if job_scratch_pbs == None:

psi4_io.set_default_path(’./’)

#else:

job_scratch_pbs += ‘/’

psi4_io.set_default_path(job_scratch_pbs)

Specifications for particular files like the below work with any option

above, but cause trouble for multijob input files

Set the path for files of a specific type

This keeps the chkpt on the NFS, while the heavies go to scratch

#psi4_io.set_specific_path(32, ‘./’)

Set a specific file number to be retained where it lies

and not be removed by psiclean

#psi4_io.set_specific_retention(32, True)

psi4_io.set_default_path("/tmp/")
geometry("""
0 1
H
H 1 0.74
“”",“blank_molecule_psi4_yo”)
core.efp_init()
geometry("""
He
“”")
core.IO.set_default_namespace("")
energy(‘hf/cc-pvdz’)
compare_values(-2.85518839, get_variable(‘current energy’), 5, ‘SCF E’)

Traceback (most recent call last):
File “/usr/local/mytmp/Psi4-git/psi-inst/bin/psi4”, line 250, in
exec(content)

SyntaxError: invalid syntax (, line 17)

*** Psi4 encountered an error. Buy a developer more coffee!
*** Resources and help at github.com/psi4/psi4.

Hmm, that line no longer exists in Psi4 master and the hash is apparently no longer valid (was rebased out) so I cannot tell when this copy was from. Can you do a fresh clone from psi4/psi4:master and recompile? Everything should work then.

Strange, I installed from git on April 6. Thanks a lot.
//Thijs H.