Skip to content

Allow specifying timeout_seconds when constructing an ionq Sampler #5133

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

Merged
merged 4 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion cirq-ionq/cirq_ionq/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
self,
service: 'cirq_ionq.Service',
target: Optional[str],
timeout_seconds: Optional[int] = None,
seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
):
"""Construct the sampler.
Expand All @@ -57,10 +58,12 @@ def __init__(
seed: If the target is `simulation` the seed for generating results. If None, this
will be `np.random`, if an int, will be `np.random.RandomState(int)`, otherwise
must be a modulate similar to `np.random`.
timeout_seconds: Length of time to wait for results. Default is specified in the job.
"""
self._service = service
self._target = target
self._seed = seed
self._timeout_seconds = timeout_seconds

def run_sweep(
self,
Expand All @@ -86,7 +89,10 @@ def run_sweep(
)
for resolver in resolvers
]
job_results = [job.results() for job in jobs]
kwargs = {}
if self._timeout_seconds is not None:
kwargs = {"timeout_seconds": self._timeout_seconds}
job_results = [job.results(**kwargs) for job in jobs]
cirq_results = []
for result, params in zip(job_results, resolvers):
if isinstance(result, results.QPUResult):
Expand Down
2 changes: 1 addition & 1 deletion cirq-ionq/cirq_ionq/sampler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_sampler_multiple_jobs():
job1 = ionq.Job(client=mock_service, job_dict=job_dict1)
mock_service.create_job.side_effect = [job0, job1]

sampler = ionq.Sampler(service=mock_service, target='qpu')
sampler = ionq.Sampler(service=mock_service, timeout_seconds=10, target='qpu')
q0 = cirq.LineQubit(0)
x = sp.Symbol('x')
circuit = cirq.Circuit(cirq.X(q0) ** x, cirq.measure(q0, key='a'))
Expand Down