Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version info at the end of output and stdout #148

Merged
merged 4 commits into from
Feb 22, 2024

Conversation

kohei-noda-qcrg
Copy link
Member

@kohei-noda-qcrg kohei-noda-qcrg commented Feb 17, 2024

このプルリクは何?

プルリクの内容を記述してください

  • バージョン情報を表示する #146 を実装

  • アウトプットの例

    • コミットハッシュがunknownの時
    ================= Calculation finished ================
    User Command : /home/noda/develop/dirac_caspt2/bin/dcaspt2 -i 
    /home/noda/develop/dirac_caspt2/test/dev/c1_methane_dev/active.inp -o 
    /home/noda/develop/dirac_caspt2/test/dev/c1_methane_dev/c1_methane_dev.caspt2.out --mpi 8 --omp 5
    Auto-created Command : mpirun -np 8 /home/noda/develop/dirac_caspt2/bin/r4dcascicoexe && mpirun -np 8 
    /home/noda/develop/dirac_caspt2/bin/r4dcaspt2ocoexe
    Scratch directory : /home/noda/dcaspt2_scratch/active_2024-02-17_16-53-18_rqdftbcv
    Output file : /home/noda/develop/dirac_caspt2/test/dev/c1_methane_dev/c1_methane_dev.caspt2.out
    Calculation started at : 2024-02-17 16:53:18
    Calculation finished at : 2024-02-17 16:53:21
    Elapsed time (sec) : 2.4537 sec
    Elapsed time : 0 day 0 hour 0 min 2 sec 453713 millisecond
    dirac-caspt2 version (commit hash) : unknown
    NORMAL END OF dirac-caspt2 CALCULATION
    
    • コミットハッシュが取得できたとき
    ================= Calculation finished ================
    User Command : /home/noda/develop/dirac_caspt2/bin/dcaspt2 -i 
    /home/noda/develop/dirac_caspt2/test/dev/c1_methane_dev/active.inp -o 
    /home/noda/develop/dirac_caspt2/test/dev/c1_methane_dev/c1_methane_dev.caspt2.out --mpi 8 --omp 5
    Auto-created Command : mpirun -np 8 /home/noda/develop/dirac_caspt2/bin/r4dcascicoexe && mpirun -np 8 
    /home/noda/develop/dirac_caspt2/bin/r4dcaspt2ocoexe
    Scratch directory : /home/noda/dcaspt2_scratch/active_2024-02-17_17-12-05_b_41nvqv
    Output file : /home/noda/develop/dirac_caspt2/test/dev/c1_methane_dev/c1_methane_dev.caspt2.out
    Calculation started at : 2024-02-17 17:12:05
    Calculation finished at : 2024-02-17 17:12:08
    Elapsed time (sec) : 2.4412 sec
    Elapsed time : 0 day 0 hour 0 min 2 sec 441214 millisecond
    dirac-caspt2 version (commit hash) : 7778dce5ad270ffc111bd31fb6247529cfa6764a
    NORMAL END OF dirac-caspt2 CALCULATION
    
  • dcaspt2 -vでもバージョン情報を表示できます

    • ~/develop/dirac_caspt2 (version-commit-hash)
      $ ./bin/dcaspt2 -v
      dirac-caspt2 version (commit hash): 26788fbbfd523ef1c19c9ae8a971e54de520fdb0

実装の内容

実装の内容を記述してください

  • CMakeLists.txtにgitのコミットハッシュを読んでbin/.commit_hashに保存する処理を追加

    # Git commit hash
    set(git_hash "unknown") # Default value
    # If .git/HEAD exists, get the commit hash
    if(EXISTS "${PROJECT_SOURCE_DIR}/.git/HEAD")
    file(STRINGS "${PROJECT_SOURCE_DIR}/.git/HEAD" git_head)
    if(git_head MATCHES "ref: ")
    string(REGEX REPLACE "ref: " "" git_head "${git_head}")
    file(STRINGS "${PROJECT_SOURCE_DIR}/.git/${git_head}" git_hash LIMIT_COUNT 1)
    else()
    set(git_hash "${git_head}")
    endif()
    message(STATUS "Git commit hash: ${git_hash}")
    endif()
    # Save the git commit hash to a file
    file(WRITE ${EXECUTABLE_OUTPUT_PATH}/.commit_hash "${git_hash}")
    install(FILES ${EXECUTABLE_OUTPUT_PATH}/.commit_hash DESTINATION ${CMAKE_INSTALL_PREFIX})

  • dcaspt2スクリプトにbin/.commit_hashを読む処理を追加

    def get_version(binary_dir: Path) -> str:
    """Get the version of the dirac-caspt2 binary
    Args:
    binary_dir (Path): Path to the directory where the compiled binaries are stored
    Returns:
    str: Version of the dirac-caspt2 binary
    """
    version_file = binary_dir / ".commit_hash"
    if version_file.exists():
    with open(version_file, "r", encoding="utf-8") as f:
    version = f.read().strip()
    else:
    version = "unknown"
    return version

  • アウトプットと標準出力にバージョン情報としてコミットハッシュを出力する

    end_message += f"dirac-caspt2 version (commit hash) : {version}\n"

(optional) 考慮事項

起こりうるバグなどがわかっている場合記述してください

  • .gitディレクトリがない状態でビルドしたり、ビルド後bin/.commit_hashファイルを削除したりするとどのバージョンのdirac-caspt2なのかが分からなくなり、unknownが出力されるようになります

@kohei-noda-qcrg kohei-noda-qcrg added the enhancement New feature or request label Feb 17, 2024
@kohei-noda-qcrg kohei-noda-qcrg merged commit 20e68a2 into main Feb 22, 2024
14 checks passed
@kohei-noda-qcrg kohei-noda-qcrg deleted the version-commit-hash branch February 22, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants