Skip to content

Commit

Permalink
Merge pull request #956 from alenaizan/timer
Browse files Browse the repository at this point in the history
add total execution time to output.
  • Loading branch information
amjames committed Apr 18, 2018
2 parents 5f8e8a3 + 486384c commit 8a8c779
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
24 changes: 20 additions & 4 deletions psi4/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,26 @@ def clean_numpy_files():

atexit.register(clean_numpy_files)

# Exit printing
def exit_printing():
time_string = datetime.datetime.now().strftime('%A, %d %B %Y %I:%M%p')
core.print_out( "\n Psi4 stopped on: %s\n" % time_string)
def exit_printing(start_time=None):
"""Prints the exit time and status.
Parameters
----------
start_time : datetime.datetime, optional
starting time from which the elapsed time is computed.
Returns
-------
None
"""
end_time = datetime.datetime.now()
core.print_out( "\n Psi4 stopped on: {}".format(end_time.strftime('%A, %d %B %Y %I:%M%p')))
if start_time is not None:
run_time = end_time - start_time
run_time = str(run_time).split('.')
run_time = run_time[0] + '.' + run_time[1][:2]
core.print_out( "\n Psi4 wall time for execution: {}\n".format(run_time))
if _success_flag_:
core.print_out( "\n*** Psi4 exiting successfully. Buy a developer a beer!\n")
else:
Expand Down
18 changes: 9 additions & 9 deletions psi4/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def print_header():
header = """
-----------------------------------------------------------------------
Psi4: An Open-Source Ab Initio Electronic Structure Package
Psi4 %s
Psi4 {}
Git: Rev %s
Git: Rev {}
R. M. Parrish, L. A. Burns, D. G. A. Smith, A. C. Simmonett,
Expand All @@ -71,12 +71,12 @@ def print_header():
-----------------------------------------------------------------------
Psi4 started on: %s
Psi4 started on: {}
Process ID: %d
Host: %s
PSIDATADIR: %s
Memory: %s
Threads: %s
""" % (driver_info, git_info, time_string, pid, hostname, datadir, memory, threads)
Process ID: {}
Host: {}
PSIDATADIR: {}
Memory: {}
Threads: {}
""".format(driver_info, git_info, time_string, pid, hostname, datadir, memory, threads)
core.print_out(header)
6 changes: 4 additions & 2 deletions psi4/run_psi4.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import sys
import os
import json
import datetime
import argparse
from argparse import RawTextHelpFormatter

Expand Down Expand Up @@ -200,6 +201,7 @@
psi4.core.set_memory_bytes(524288000, True)
psi4.extras._input_dir_ = os.path.dirname(os.path.abspath(args["input"]))
psi4.print_header()
start_time = datetime.datetime.now()

# Prepare scratch for inputparser
if args["scratch"] is not None:
Expand All @@ -214,7 +216,7 @@
json_data = json.load(f)

psi4.extras._success_flag_ = True
psi4.extras.exit_printing()
psi4.extras.exit_printing(start_time)
psi4.json_wrapper.run_json(json_data)

with open(args["input"], 'w') as f:
Expand Down Expand Up @@ -255,7 +257,7 @@
atexit._exithandlers.remove(handler)

# Register exit printing, failure GOTO coffee ELSE beer
atexit.register(psi4.extras.exit_printing)
atexit.register(psi4.extras.exit_printing, start_time)

# Run the program!
try:
Expand Down

0 comments on commit 8a8c779

Please sign in to comment.