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

feat: use results dir as working directory for decorator jobs #743

Merged
merged 12 commits into from
Oct 14, 2023
47 changes: 29 additions & 18 deletions src/braket/jobs/_entry_point_template.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
run_entry_point = """
import cloudpickle
from braket.jobs import save_job_result
import os
from braket.jobs import get_results_dir, save_job_result
from braket.jobs_data import PersistedJobDataFormat


# set working directory to results dir
os.chdir(get_results_dir())

mbeach-aws marked this conversation as resolved.
Show resolved Hide resolved
# create symlinks to input data
link_input()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we prevent the input data from getting populated in the results? Since the "recovered()" function encapsulates the entirety of the job script, could we unlink the input data in our template after that function finishes execution? This would ensure that the function has had a chance to consume the input data, but remove the input data before the results are packaged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can add that. I can make sure that each link is a symlink and points to the original destination before deleting, in case it has been overwritten explicitly by the user.


# load and run serialized entry point function
recovered = cloudpickle.loads({serialized})
def {function_name}():
Expand All @@ -16,31 +24,34 @@ def {function_name}():
from pathlib import Path
from braket.jobs import get_input_data_dir

# map of data sources to lists of matched local files
prefix_matches = {prefix_matches}

def make_link(input_link_path, input_data_path):
""" Create symlink from input_link_path to input_data_path. """
input_link_path.parent.mkdir(parents=True, exist_ok=True)
input_link_path.symlink_to(input_data_path)
print(input_link_path, '->', input_data_path)

for channel, data in {input_data_items}:

if channel in {prefix_channels}:
# link all matched files
for input_link_name in prefix_matches[channel]:
input_link_path = Path(input_link_name)
input_data_path = Path(get_input_data_dir(channel)) / input_link_path.name
make_link(input_link_path, input_data_path)
def link_input():
# map of data sources to lists of matched local files
prefix_matches = {prefix_matches}

for channel, data in {input_data_items}:

if channel in {prefix_channels}:
# link all matched files
for input_link_name in prefix_matches[channel]:
input_link_path = Path(input_link_name)
input_data_path = Path(get_input_data_dir(channel)) / input_link_path.name
make_link(input_link_path, input_data_path)

else:
input_link_path = Path(data)
if channel in {directory_channels}:
# link directory source directly to input channel directory
input_data_path = Path(get_input_data_dir(channel))
else:
# link file source to file within input channel directory
input_data_path = Path(get_input_data_dir(channel), Path(data).name)
make_link(input_link_path, input_data_path)
input_link_path = Path(data)
if channel in {directory_channels}:
# link directory source directly to input channel directory
input_data_path = Path(get_input_data_dir(channel))
else:
# link file source to file within input channel directory
input_data_path = Path(get_input_data_dir(channel), Path(data).name)
make_link(input_link_path, input_data_path)
'''