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

Commit

Permalink
Merge pull request #370 from CQCL/release/1.1
Browse files Browse the repository at this point in the history
Release/1.1
  • Loading branch information
cqc-alec authored Apr 12, 2022
2 parents dd0b1a1 + 8c769f6 commit 07280d0
Show file tree
Hide file tree
Showing 81 changed files with 818 additions and 131 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/modules/pytket-iqm/ @cqc-alec
/modules/pytket-projectq/ @lmondada
/modules/pytket-pyquil/ @sjdilkes @lmondada
/modules/pytket-pysimplex/ @cqc-alec
/modules/pytket-pyzx/ @cqc-alec
/modules/pytket-qiskit/ @ss2165
/modules/pytket-qsharp/ @cqc-alec
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/build-test
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ function skip_tests() {
case "$1" in
pytket-qsharp)
case "${PLAT}" in
Windows)
# https://github.com/CQCL/pytket-extensions/issues/180
# https://github.com/microsoft/iqsharp/issues/512
true && return
;;
Darwin)
# Test timeout issues
[[ ${PYVER} == "3.10" ]] && return
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ jobs:
docker pull rigetti/qvm
- name: Install dotnet SDK
if: contains(env.MODULES_TO_TEST, 'pytket-qsharp')
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: '3.1.x'
dotnet-version: '6.0.x'
- name: Install iqsharp
if: contains(env.MODULES_TO_TEST, 'pytket-qsharp')
run: dotnet tool install -g Microsoft.Quantum.IQSharp
Expand Down Expand Up @@ -113,9 +113,9 @@ jobs:
- name: Install dotnet SDK
if: contains(env.MODULES_TO_TEST, 'pytket-qsharp')
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: '3.1.x'
dotnet-version: '6.0.x'
- name: Install iqsharp
if: contains(env.MODULES_TO_TEST, 'pytket-qsharp')
run: |
Expand Down Expand Up @@ -180,9 +180,9 @@ jobs:
- name: Install dotnet SDK
if: contains(env.MODULES_TO_TEST, 'pytket-qsharp')
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: '3.1.x'
dotnet-version: '6.0.x'
- name: Install iqsharp
if: contains(env.MODULES_TO_TEST, 'pytket-qsharp')
run: dotnet tool install -g Microsoft.Quantum.IQSharp
Expand Down Expand Up @@ -261,9 +261,9 @@ jobs:
- name: Install extensions
run: for w in `find wheelhouse/ -type f -name "*.whl"` ; do pip install $w ; done
- name: Install dotnet SDK
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: '3.1.x'
dotnet-version: '6.0.x'
- name: Install iqsharp
run: |
dotnet tool install -g Microsoft.Quantum.IQSharp
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
cd ../..
done
- name: Install dotnet SDK
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: '3.1.x'
dotnet-version: '6.0.x'
- name: Install iqsharp
run: |
dotnet tool install -g Microsoft.Quantum.IQSharp
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/hotfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ jobs:
docker pull rigetti/qvm
- name: Install dotnet SDK
if: contains(env.MODULES_TO_TEST, 'pytket-qsharp')
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: '3.1.x'
dotnet-version: '6.0.x'
- name: Install iqsharp
if: contains(env.MODULES_TO_TEST, 'pytket-qsharp')
run: dotnet tool install -g Microsoft.Quantum.IQSharp
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ subdirectory of the `modules` directory:
* `pytket-iqm`
* `pytket-projectq`
* `pytket-pyquil`
* `pytket-pysimplex`
* `pytket-pyzx`
* `pytket-qiskit`
* `pytket-qsharp`
* `pytket-quantinumm`
* `pytket-quantinuum`
* `pytket-qulacs`
* `pytket-stim`

Expand Down
2 changes: 2 additions & 0 deletions modules/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ filterwarnings =
ignore:Call to deprecated create function EnumValueDescriptor
ignore:Call to deprecated create function FileDescriptor
ignore:Call to deprecated create function OneofDescriptor
ignore:The value of the smallest subnormal for <class 'numpy.float32'> type is zero
ignore:The value of the smallest subnormal for <class 'numpy.float64'> type is zero
2 changes: 1 addition & 1 deletion modules/pytket-aqt/_metadata.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__extension_version__ = "0.18.0"
__extension_version__ = "0.19.0"
__extension_name__ = "pytket-aqt"
5 changes: 5 additions & 0 deletions modules/pytket-aqt/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
~~~~~~~~~

0.19.0 (April 2022)
-------------------

* Updated pytket version requirement to 1.1.

0.18.0 (March 2022)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion modules/pytket-aqt/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
license="Apache 2",
packages=find_namespace_packages(include=["pytket.*"]),
include_package_data=True,
install_requires=["pytket ~= 1.0", "requests ~= 2.22", "types-requests"],
install_requires=["pytket ~= 1.1", "requests ~= 2.22", "types-requests"],
classifiers=[
"Environment :: Console",
"Programming Language :: Python :: 3.8",
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.17.0"
__extension_version__ = "0.18.0"
__extension_name__ = "pytket-braket"
7 changes: 7 additions & 0 deletions modules/pytket-braket/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
~~~~~~~~~

0.18.0 (April 2022)
-------------------

* Allow user to specify different local backends.
* Fix dimension mismatch for measurements for Braket QPU results.
* Updated pytket version requirement to 1.1.

0.17.0 (March 2022)
-------------------

Expand Down
33 changes: 19 additions & 14 deletions modules/pytket-braket/pytket/extensions/braket/backends/braket.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"ti": OpType.Tdg,
"two_qubit_dephasing": None,
"two_qubit_depolarizing": None,
"two_qubit_pauli_channel": None,
"unitary": None,
"v": OpType.V,
"vi": OpType.Vdg,
Expand Down Expand Up @@ -202,20 +203,21 @@ def _obs_from_qpo(operator: QubitPauliOperator, n_qubits: int) -> Observable:

def _get_result(
completed_task: Union[AwsQuantumTask, LocalQuantumTask],
n_qubits: int,
target_qubits: str,
want_state: bool,
want_dm: bool,
ppcirc: Optional[Circuit] = None,
) -> Dict[str, BackendResult]:
result = completed_task.result()
kwargs = {}
qubits_index = json.loads(target_qubits)
if want_state or want_dm:
assert ppcirc is None
if want_state:
kwargs["state"] = result.get_value_by_result_type(ResultType.StateVector())
if want_dm:
m = result.get_value_by_result_type(
ResultType.DensityMatrix(target=list(range(n_qubits)))
ResultType.DensityMatrix(target=qubits_index)
)
if type(completed_task) == AwsQuantumTask:
kwargs["density_matrix"] = np.array(
Expand All @@ -224,7 +226,8 @@ def _get_result(
else:
kwargs["density_matrix"] = m
else:
kwargs["shots"] = OutcomeArray.from_readouts(result.measurements)
measurements = result.measurements[:, qubits_index]
kwargs["shots"] = OutcomeArray.from_readouts(measurements)
kwargs["ppcirc"] = ppcirc
return {"result": BackendResult(**kwargs)}

Expand All @@ -243,6 +246,7 @@ class BraketBackend(Backend):
def __init__(
self,
local: bool = False,
local_device: str = "default",
device: Optional[str] = None,
region: str = "",
s3_bucket: Optional[str] = None,
Expand All @@ -264,6 +268,8 @@ def __init__(
:param local: use simulator running on local machine,
default: False
:param local_device: name of local device (ignored if local=False) -- e.g.
"braket_sv" (default) or "braket_dm".
:param device: device name from device ARN (e.g. "ionQdevice", "Aspen-8", ...),
default: "sv1"
:param s3_bucket: name of S3 bucket to store results
Expand Down Expand Up @@ -300,7 +306,7 @@ def __init__(
self._aws_session = aws_session

if local:
self._device = LocalSimulator()
self._device = LocalSimulator(backend=local_device)
self._device_type = _DeviceType.LOCAL
else:
self._device = AwsDevice(
Expand Down Expand Up @@ -605,7 +611,7 @@ def default_compilation_pass(self, optimisation_level: int = 1) -> BasePass:
def _result_id_type(self) -> _ResultIdTuple:
# (task ID, whether state vector / density matrix are wanted, serialized ppcirc
# or "null")
return (str, int, bool, bool, str)
return (str, str, bool, bool, str)

def _run(
self, bkcirc: braket.circuits.Circuit, n_shots: int = 0, **kwargs: KwargTypes
Expand Down Expand Up @@ -661,6 +667,9 @@ def process_circuits(
for circ, n_shots in zip(circuits, n_shots_list):
want_state = (n_shots == 0) and self.supports_state
want_dm = (n_shots == 0) and self.supports_density_matrix
problem_qubits = [x.index[0] for x in circ.qubits]
device_qubits = [x.index[0] for x in self._backend_info.nodes]
target_qubits = json.dumps([device_qubits.index(x) for x in problem_qubits])
if postprocess:
circ_measured = circ.copy()
circ_measured.measure_all()
Expand All @@ -682,7 +691,7 @@ def process_circuits(
if task is not None:
assert task.state() == "COMPLETED"
results = _get_result(
task, bkcirc.qubit_count, want_state, want_dm, ppcirc
task, target_qubits, want_state, want_dm, ppcirc
)
else:
results = {"result": self.empty_result(circ, n_shots=n_shots)}
Expand All @@ -691,15 +700,11 @@ def process_circuits(
results = {}
if task is not None:
handle = ResultHandle(
task.id,
bkcirc.qubit_count,
want_state,
want_dm,
json.dumps(ppcirc_rep),
task.id, target_qubits, want_state, want_dm, json.dumps(ppcirc_rep)
)
else:
handle = ResultHandle(
str(uuid4()), bkcirc.qubit_count, False, False, json.dumps(None)
str(uuid4()), target_qubits, False, False, json.dumps(None)
)
self._cache[handle] = results
handles.append(handle)
Expand All @@ -716,7 +721,7 @@ def _update_cache_result(
def circuit_status(self, handle: ResultHandle) -> CircuitStatus:
if self._device_type == _DeviceType.LOCAL:
return CircuitStatus(StatusEnum.COMPLETED)
task_id, n_qubits, want_state, want_dm, ppcirc_str = handle
task_id, target_qubits, 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)
Expand All @@ -727,7 +732,7 @@ def circuit_status(self, handle: ResultHandle) -> CircuitStatus:
return CircuitStatus(StatusEnum.CANCELLED)
elif state == "COMPLETED":
self._update_cache_result(
handle, _get_result(task, n_qubits, want_state, want_dm, ppcirc)
handle, _get_result(task, target_qubits, want_state, want_dm, ppcirc)
)
return CircuitStatus(StatusEnum.COMPLETED)
elif state == "QUEUED" or state == "CREATED":
Expand Down
3 changes: 2 additions & 1 deletion modules/pytket-braket/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
packages=find_namespace_packages(include=["pytket.*"]),
include_package_data=True,
install_requires=[
"pytket ~= 1.0",
"pytket ~= 1.1",
"amazon-braket-sdk~=1.16",
"amazon-braket-schemas~=1.7",
"amazon-braket-default-simulator~=1.5",
],
classifiers=[
"Environment :: Console",
Expand Down
43 changes: 43 additions & 0 deletions modules/pytket-braket/tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ def test_dm_simulator() -> None:
assert np.allclose(m, m0)


@pytest.mark.skipif(skip_remote_tests, reason=REASON)
def test_tn1_simulator() -> None:
b = BraketBackend(
device_type="quantum-simulator",
provider="amazon",
device="tn1",
)
assert b.supports_shots
c = Circuit(2).H(0).CX(0, 1)
c = b.get_compiled_circuit(c)
n_shots = 100
h0, h1 = b.process_circuits([c, c], n_shots)
res0 = b.get_result(h0)
readouts = res0.get_shots()
assert all(readouts[i][0] == readouts[i][1] for i in range(n_shots))
res1 = b.get_result(h1)
counts = res1.get_counts()
assert len(counts) <= 2
assert sum(counts.values()) == n_shots
# Circuit with unused qubits
c = Circuit(3).H(1).CX(1, 2)
c = b.get_compiled_circuit(c)
h = b.process_circuit(c, 1)
res = b.get_result(h)
readout = res.get_shots()[0]
assert readout[1] == readout[2]


@pytest.mark.skipif(skip_remote_tests, reason=REASON)
def test_ionq() -> None:
b = BraketBackend(
Expand Down Expand Up @@ -229,6 +257,21 @@ def test_local_simulator() -> None:
assert sum(counts.values()) == n_shots


def test_local_dm_simulator() -> None:
b = BraketBackend(local=True, local_device="braket_dm")
assert b.supports_shots
assert b.supports_counts
assert b.supports_density_matrix
c = Circuit(2).H(0).CX(0, 1)
c = b.get_compiled_circuit(c)
h = b.process_circuit(c)
res = b.get_result(h)
dm = res.get_density_matrix()
dm0 = np.zeros((4, 4), dtype=complex)
dm0[0, 0] = dm0[0, 3] = dm0[3, 0] = dm0[3, 3] = 0.5
assert np.allclose(dm, dm0)


def test_expectation() -> None:
b = BraketBackend(local=True)
assert b.supports_expectation
Expand Down
2 changes: 1 addition & 1 deletion modules/pytket-cirq/_metadata.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__extension_version__ = "0.21.0"
__extension_version__ = "0.22.0"
__extension_name__ = "pytket-cirq"
8 changes: 8 additions & 0 deletions modules/pytket-cirq/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
~~~~~~~~~

0.22.0 (April 2022)
-------------------

* Updated cirq version requirement to 0.14.
* Changed `process_characterisation()` so that it expects a `SerializableDevice`
instead of an `XmonDevice`.
* Updated pytket version requirement to 1.1.

0.21.0 (March 2022)
-------------------

Expand Down
Loading

0 comments on commit 07280d0

Please sign in to comment.