Skip to content

benchmarks: Improve path handling in benchmark script #31

Description

@bettinakeller

In most scripts, the parent directory is simply appended to the system path

#-----------------------------------------
# I M P O R T S
#-----------------------------------------
import sys
sys.path.append("..")

If the kernel is not restarted, ".." is appended every time the script is run, leading to an overly long system path. A better alternative is

#-----------------------------------------
# I M P O R T S
#-----------------------------------------
import sys
import os

# Get the absolute path of the parent directory
parent_dir = os.path.abspath("..")

# Append the parent directory to sys.path if it is not already included
if parent_dir not in sys.path:
sys.path.append(parent_dir)

print("---------------------------------------")
print("System path:")
print(sys.path)

See benchmarks/potentials_D1_Quadratic.py

Add this improved system-path handling to all other benchmark scripts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Slow lane

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions