forked from ProjectQ-Framework/ProjectQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaqt.py
More file actions
68 lines (61 loc) · 2.95 KB
/
aqt.py
File metadata and controls
68 lines (61 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
# Copyright 2020 ProjectQ-Framework (www.projectq.ch)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
A setup for AQT trapped ion devices.
Defines a setup allowing to compile code for the AQT trapped ion devices:
->The 4 qubits device
->The 11 qubits simulator
->The 11 qubits noisy simulator
It provides the `engine_list` for the `MainEngine' based on the requested
device. Decompose the circuit into a Rx/Ry/Rxx gate set that will be
translated in the backend in the Rx/Ry/MS gate set.
"""
from projectq.backends._aqt._aqt_http_client import show_devices
from projectq.backends._exceptions import DeviceNotHandledError, DeviceOfflineError
from projectq.cengines import BasicMapperEngine
from projectq.ops import Barrier, Rx, Rxx, Ry
from projectq.setups import restrictedgateset
def get_engine_list(token=None, device=None):
"""Return the default list of compiler engine for the AQT plaftorm."""
# Access to the hardware properties via show_devices
# Can also be extended to take into account gate fidelities, new available
# gate, etc..
devices = show_devices(token)
aqt_setup = []
if device not in devices:
raise DeviceOfflineError('Error when configuring engine list: device requested for Backend not connected')
if device == 'aqt_simulator':
# The 11 qubit online simulator doesn't need a specific mapping for
# gates. Can also run wider gateset but this setup keep the
# restrictedgateset setup for coherence
mapper = BasicMapperEngine()
# Note: Manual Mapper doesn't work, because its map is updated only if
# gates are applied if gates in the register are not used, then it
# will lead to state errors
res = {}
for i in range(devices[device]['nq']):
res[i] = i
mapper.current_mapping = res
aqt_setup = [mapper]
else:
# If there is an online device not handled into ProjectQ it's not too
# bad, the engine_list can be constructed manually with the
# appropriate mapper and the 'coupling_map' parameter
raise DeviceNotHandledError('Device not yet fully handled by ProjectQ')
# Most gates need to be decomposed into a subset that is manually converted
# in the backend (until the implementation of the U1,U2,U3)
setup = restrictedgateset.get_engine_list(one_qubit_gates=(Rx, Ry), two_qubit_gates=(Rxx,), other_gates=(Barrier,))
setup.extend(aqt_setup)
return setup