Spaces:
Runtime error
Runtime error
harishaseebat92 commited on
Commit ·
317f297
1
Parent(s): eda035c
Fix: Define ADAPT_MODULE and PROJECT_ROOT for ADAPT-AQC
Browse files
utils/EBU_Quantum/no_body/base_functions.py
CHANGED
|
@@ -683,24 +683,31 @@ from qiskit import QuantumCircuit
|
|
| 683 |
from qiskit.qasm3 import dumps, loads
|
| 684 |
|
| 685 |
# --- Dynamic Path Detection ---
|
| 686 |
-
#
|
| 687 |
-
#
|
| 688 |
-
#
|
|
|
|
| 689 |
CURRENT_FILE = Path(__file__).resolve()
|
| 690 |
-
PROJECT_ROOT = CURRENT_FILE.parents[4]
|
| 691 |
|
| 692 |
-
#
|
| 693 |
-
#
|
| 694 |
-
|
| 695 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
|
| 697 |
if sys.platform == "win32":
|
| 698 |
ADAPT_PYTHON = str(VENV_DIR / "Scripts" / "python.exe")
|
| 699 |
else:
|
| 700 |
ADAPT_PYTHON = str(VENV_DIR / "bin" / "python")
|
| 701 |
|
| 702 |
-
# 3. Define the module path
|
| 703 |
-
ADAPT_MODULE = "
|
| 704 |
|
| 705 |
def generate_optimized_circuit(qc: QuantumCircuit) -> QuantumCircuit:
|
| 706 |
"""
|
|
@@ -718,9 +725,9 @@ import sys
|
|
| 718 |
import os
|
| 719 |
|
| 720 |
# Add paths to the research libraries
|
| 721 |
-
#
|
| 722 |
-
sys.path.append(os.path.join(os.getcwd(), '
|
| 723 |
-
sys.path.append(os.path.join(os.getcwd(), '
|
| 724 |
|
| 725 |
from qiskit.qasm3 import loads, dumps
|
| 726 |
# Now we can import the module
|
|
@@ -740,7 +747,7 @@ sys.stdout.write(dumps(qc_opt))
|
|
| 740 |
"""
|
| 741 |
|
| 742 |
# Launch subprocess, pipe in QASM3 string
|
| 743 |
-
# We set cwd to PROJECT_ROOT so imports like '
|
| 744 |
proc = subprocess.run(
|
| 745 |
[ADAPT_PYTHON, "-c", code],
|
| 746 |
input=qasm_str,
|
|
|
|
| 683 |
from qiskit.qasm3 import dumps, loads
|
| 684 |
|
| 685 |
# --- Dynamic Path Detection ---
|
| 686 |
+
# This file is at: .../quantum/utils/EBU_Quantum/no_body/base_functions.py
|
| 687 |
+
# In Docker: /home/user/app/utils/EBU_Quantum/no_body/base_functions.py
|
| 688 |
+
# We need to find the 'utils' directory which is 3 levels up from this file
|
| 689 |
+
|
| 690 |
CURRENT_FILE = Path(__file__).resolve()
|
|
|
|
| 691 |
|
| 692 |
+
# Go up to the 'utils' directory (3 levels up from base_functions.py)
|
| 693 |
+
# base_functions.py -> no_body -> EBU_Quantum -> utils
|
| 694 |
+
UTILS_DIR = CURRENT_FILE.parents[2]
|
| 695 |
+
|
| 696 |
+
# The aqc_venv is directly inside utils/
|
| 697 |
+
VENV_DIR = UTILS_DIR / "aqc_venv"
|
| 698 |
+
|
| 699 |
+
# PROJECT_ROOT is the parent of 'utils' (needed for module imports in subprocess)
|
| 700 |
+
# In Docker: /home/user/app
|
| 701 |
+
# Locally: .../quantum (or .../webui_trame/quantum)
|
| 702 |
+
PROJECT_ROOT = UTILS_DIR.parent
|
| 703 |
|
| 704 |
if sys.platform == "win32":
|
| 705 |
ADAPT_PYTHON = str(VENV_DIR / "Scripts" / "python.exe")
|
| 706 |
else:
|
| 707 |
ADAPT_PYTHON = str(VENV_DIR / "bin" / "python")
|
| 708 |
|
| 709 |
+
# 3. Define the module path - this should work from PROJECT_ROOT
|
| 710 |
+
ADAPT_MODULE = "utils.EBU_Quantum.no_body.run_adapt_aqc"
|
| 711 |
|
| 712 |
def generate_optimized_circuit(qc: QuantumCircuit) -> QuantumCircuit:
|
| 713 |
"""
|
|
|
|
| 725 |
import os
|
| 726 |
|
| 727 |
# Add paths to the research libraries
|
| 728 |
+
# CWD will be PROJECT_ROOT (e.g., /home/user/app in Docker)
|
| 729 |
+
sys.path.append(os.path.join(os.getcwd(), 'utils', 'aqc-research'))
|
| 730 |
+
sys.path.append(os.path.join(os.getcwd(), 'utils', 'adapt-aqc'))
|
| 731 |
|
| 732 |
from qiskit.qasm3 import loads, dumps
|
| 733 |
# Now we can import the module
|
|
|
|
| 747 |
"""
|
| 748 |
|
| 749 |
# Launch subprocess, pipe in QASM3 string
|
| 750 |
+
# We set cwd to PROJECT_ROOT so imports like 'utils...' work correctly
|
| 751 |
proc = subprocess.run(
|
| 752 |
[ADAPT_PYTHON, "-c", code],
|
| 753 |
input=qasm_str,
|