Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
[hotfix] [pytket-braket] Merge pull request #415 from CQCL/hotfix/bra…
Browse files Browse the repository at this point in the history
…ket-rigetti-fix
  • Loading branch information
cqc-alec authored Jun 13, 2022
2 parents 3c8a63d + 2c7952e commit 66da3a6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/hotfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ jobs:
python-version: '3.10'
- name: Build and test
run: |
./.github/workflows/build-test nomypy
for mod in ${MODULES_TO_TEST}
do
MODULE=${mod} ./.github/workflows/build-test nomypy
done
- uses: actions/upload-artifact@v3
with:
name: artefacts
Expand Down
2 changes: 1 addition & 1 deletion modules/pytket-braket/_metadata.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__extension_version__ = "0.19.0"
__extension_version__ = "0.19.1"
__extension_name__ = "pytket-braket"
5 changes: 5 additions & 0 deletions modules/pytket-braket/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
~~~~~~~~~

0.19.1 (June 2022)
------------------

* Fixes to qubit index handling.

0.19.0 (May 2022)
-----------------

Expand Down
17 changes: 15 additions & 2 deletions modules/pytket-braket/pytket/extensions/braket/backends/braket.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,16 @@ def _get_arch_info(
connectivity_graph = dict(
(int(k), [int(v) for v in l]) for k, l in connectivity_graph.items()
)
all_qubits = sorted(connectivity_graph.keys())
# each connectivity graph key will be an int
# connectivity_graph values will be lists
qubit_list = [
[*connectivity_graph.keys()],
*connectivity_graph.values(),
]
# summing lists will flatten them
# example [[0,1], [0,2]] would be [0,1,0,2] when summed
# returns unique ordered list since taking set of sum
all_qubits = list(set(sum(qubit_list, [])))
if n_qubits < len(all_qubits):
# This can happen, at least on rigetti devices, and causes errors.
# As a kludgy workaround, remove some qubits from the architecture.
Expand Down Expand Up @@ -685,6 +694,9 @@ def process_circuits(
else:
c0, ppcirc, ppcirc_rep = circ, None, None
bkcirc, measures = self._to_bkcirc(c0)
# maps to index of measured qubits in the circuit
# this is necessary because qubit number doesn't map to index for Rigetti
measures = {k: self._all_qubits.index(v) for k, v in measures.items()}
if want_state:
bkcirc.add_result_type(ResultType.StateVector())
if want_dm:
Expand Down Expand Up @@ -739,13 +751,14 @@ def circuit_status(self, handle: ResultHandle) -> CircuitStatus:
if self._device_type == _DeviceType.LOCAL:
return CircuitStatus(StatusEnum.COMPLETED)
task_id, target_qubits, measures, want_state, want_dm, ppcirc_str = handle

ppcirc_rep = json.loads(ppcirc_str)
ppcirc = Circuit.from_dict(ppcirc_rep) if ppcirc_rep is not None else None
task = AwsQuantumTask(task_id, aws_session=self._aws_session)
state = task.state()
if state == "FAILED":
return CircuitStatus(StatusEnum.ERROR, task.metadata()["failureReason"])
elif state == "CANCELLED":
elif state in ["CANCELLED", "CANCELLING"]:
return CircuitStatus(StatusEnum.CANCELLED)
elif state == "COMPLETED":
self._update_cache_result(
Expand Down

0 comments on commit 66da3a6

Please sign in to comment.