Skip to content
New issue

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

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

Already on GitHub? # to your account

add seed list feature #197

Merged
merged 4 commits into from
Nov 8, 2023
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
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ unreleased
* Update qiskit-ibm-runtime version to 0.13.0.
* Update qiskit-aer version to 0.13.0.
* Introduce dependency on qiskit-algorithms.
* Seed given to ``process_circuits()`` will be automatically incremented
for the different circuit batches submitted.

0.45.0 (October 2023)
---------------------
Expand Down
8 changes: 7 additions & 1 deletion pytket/extensions/qiskit/backends/aer.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def process_circuits(
valid_check: bool = True,
**kwargs: KwargTypes,
) -> List[ResultHandle]:
"""
See :py:meth:`pytket.backends.Backend.process_circuits`.
Supported kwargs: `seed`, `postprocess`.
"""
circuits = list(circuits)
n_shots_list = Backend._get_n_shots_as_list(
n_shots,
Expand All @@ -258,6 +262,7 @@ def process_circuits(
circuits = noisy_circuits

handle_list: List[Optional[ResultHandle]] = [None] * len(circuits)
seed = kwargs.get("seed")
circuit_batches, batch_order = _batch_circuits(circuits, n_shots_list)

replace_implicit_swaps = self.supports_state or self.supports_unitary
Expand All @@ -275,14 +280,15 @@ def process_circuits(
if self._needs_transpile:
qcs = transpile(qcs, self._qiskit_backend)

seed = cast(Optional[int], kwargs.get("seed"))
job = self._qiskit_backend.run(
qcs,
shots=n_shots,
memory=self._memory,
seed_simulator=seed,
noise_model=self._noise_model,
)
if type(seed) is int:
seed += 1
jobid = job.job_id()
for i, ind in enumerate(indices):
handle = ResultHandle(jobid, i)
Expand Down
3 changes: 2 additions & 1 deletion pytket/extensions/qiskit/backends/ibm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@


def _batch_circuits(
circuits: Sequence["Circuit"], n_shots: Sequence[Optional[int]]
circuits: Sequence["Circuit"],
n_shots: Sequence[Optional[int]],
) -> Tuple[List[Tuple[Optional[int], List["Circuit"]]], List[List[int]]]:
"""
Groups circuits into sets of circuits with the same number of shots.
Expand Down
5 changes: 4 additions & 1 deletion pytket/extensions/qiskit/backends/ibmq_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def process_circuits(
)

handle_list: List[Optional[ResultHandle]] = [None] * len(circuits)
seed = kwargs.get("seed")
circuit_batches, batch_order = _batch_circuits(circuits, n_shots_list)

batch_id = 0 # identify batches for debug purposes only
Expand Down Expand Up @@ -173,7 +174,9 @@ def process_circuits(
options.resilience_level = 0
options.execution.shots = n_shots
options.simulator.noise_model = self._noise_model
options.seed_simulator = kwargs.get("seed")
options.seed_simulator = seed
if type(seed) is int:
seed += 1
sampler = Sampler(session=self._session, options=options)
job = sampler.run(circuits=qcs)
job_id = job.job_id()
Expand Down