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

Save local mode jobs #1854

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dbb7df6
initial commit
kt474 Aug 12, 2024
342df6d
Cherry pick 0.27.1 release notes into main
kt474 Aug 12, 2024
737dbdf
Merge branch 'main' of https://github.com/kt474/qiskit-ibm-runtime
kt474 Aug 13, 2024
8459017
Merge branch 'main' of https://github.com/kt474/qiskit-ibm-runtime
kt474 Aug 14, 2024
296e5e2
Merge branch 'main' into save-local-jobs
kt474 Aug 14, 2024
186a70a
initial working poc
kt474 Aug 14, 2024
97d8e4f
Add file path env var
kt474 Aug 14, 2024
cbe5c48
Merge branch 'main' of https://github.com/kt474/qiskit-ibm-runtime
kt474 Aug 14, 2024
c53f968
Merge branch 'main' of https://github.com/kt474/qiskit-ibm-runtime
kt474 Aug 14, 2024
39715b0
Merge branch 'main' into save-local-jobs
kt474 Aug 14, 2024
ed1e468
Update local service & reno
kt474 Aug 15, 2024
de78a27
cleanup unit tests
kt474 Aug 16, 2024
f1e4276
Merge branch 'main' into save-local-jobs
kt474 Aug 19, 2024
c684d88
figure out unit tests
kt474 Aug 19, 2024
d1081ac
update unit tests
kt474 Aug 19, 2024
7a65afe
revert previous commit
kt474 Aug 19, 2024
1a5ceb8
add tests
kt474 Aug 19, 2024
2db9f41
Merge branch 'main' into save-local-jobs
kt474 Aug 20, 2024
4944ee3
check for directory
kt474 Aug 20, 2024
cf866f6
Merge branch 'save-local-jobs' of https://github.com/kt474/qiskit-ibm…
kt474 Aug 20, 2024
e0777d6
figure out what unit test fails
kt474 Aug 20, 2024
4a1d9bb
update tests
kt474 Aug 20, 2024
a4a8ca8
revert
kt474 Aug 20, 2024
6f9f6c8
Merge branch 'main' into save-local-jobs
ptristan3 Sep 3, 2024
0a6eda7
Merge branch 'main' into save-local-jobs
ptristan3 Sep 17, 2024
ab8481c
Merge branch 'main' into save-local-jobs
kt474 Dec 3, 2024
98dcc77
Fix merge conflict mistakes
kt474 Dec 3, 2024
360de23
Merge branch 'main' into save-local-jobs
kt474 Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add file path env var
kt474 committed Aug 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 97d8e4f1a89bf7974ae30286dfda0acc59cd3d95
27 changes: 15 additions & 12 deletions qiskit_ibm_runtime/fake_provider/local_service.py
Original file line number Diff line number Diff line change
@@ -55,6 +55,10 @@ def __init__(self) -> None:

"""
self._channel_strategy = None
self._saved_jobs_directory = (
os.getenv("QISKIT_LOCAL_JOBS_DIRECTORY")
or f"{os.path.dirname(os.path.realpath(__file__))}/local_jobs"
)

def backend(
self, name: str = None, instance: str = None # pylint: disable=unused-argument
@@ -223,7 +227,7 @@ def _run(
options=inputs.get("options", {}),
inputs=primitive_inputs,
)
self._save_job(job, inputs.get("options", {}).get("filename"))
self._save_job(job)
return job

def _run_aer_primitive_v1(
@@ -358,26 +362,25 @@ def job(self, job_id: str) -> PrimitiveJob:
def jobs(self) -> List[PrimitiveJob]:
"""Return all saved local jobs."""
all_jobs = []
file_path = f"{os.path.dirname(os.path.realpath(__file__))}/local_jobs"
for filename in os.listdir(file_path):
with open(f"{file_path}/{filename}", "rb") as file:
for filename in os.listdir(self._saved_jobs_directory):
with open(f"{self._saved_jobs_directory}/{filename}", "rb") as file:
all_jobs.append(pickle.load(file))
return all_jobs

@staticmethod
def _save_job(job: PrimitiveJob, filename: str) -> None:
"""Pickle and save job locally in the local_jobs folder.
def delete_job(self, job_id: str) -> None:
"""Delete a local job."""
os.remove(f"{self._saved_jobs_directory}/{job_id}.pkl")

def _save_job(self, job: PrimitiveJob) -> None:
"""Pickle and save job locally in the specified directory.

Args:
job: PrimitiveJob.
filename: file location to store job.
"""
try:
job._prepare_dump()

file_path = filename or (f"{os.path.dirname(os.path.realpath(__file__))}/local_jobs")
os.makedirs(f"{file_path}", exist_ok=True)
with open(f"{file_path}/{job.job_id()}.pkl", "wb") as file:
os.makedirs(f"{self._saved_jobs_directory}", exist_ok=True)
with open(f"{self._saved_jobs_directory}/{job.job_id()}.pkl", "wb") as file:
pickle.dump(job, file)
except Exception as ex: # pylint: disable=broad-except
logger.warning("Unable to save job %s. %s", job.job_id(), ex)