Skip to content
This repository was archived by the owner on May 17, 2022. It is now read-only.

Commit fdc806a

Browse files
authored
fix: Fix test with new opencontrol version (#24)
1 parent 5969701 commit fdc806a

File tree

6 files changed

+182
-112
lines changed

6 files changed

+182
-112
lines changed

.github/workflows/on-push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1919
run: |
2020
source <(curl -sL http://ci.q-ctrl.com)
21-
./ci vault login -r ${{ secrets.VAULT_ROLE_ID }} -s ${{ secrets.VAULT_SECRET_ID }}
21+
./ci vault login -r ${{ secrets.VAULT_ROLE_ID }} -s ${{ secrets.VAULT_SECRET_ID }}
2222
./ci docker run qctrl/ci-images:python-3.7-ci /scripts/housekeeping.sh
2323
2424
linting:
@@ -44,7 +44,7 @@ jobs:
4444
runs-on: ubuntu-latest
4545
strategy:
4646
matrix:
47-
python: [3.7, 3.8, 3.9]
47+
python: [3.7, 3.8]
4848
steps:
4949
- uses: actions/checkout@v1
5050
- name: Install Python dependencies

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ license = "Apache-2.0"
66
authors = ["Q-CTRL <[email protected]>"]
77
readme = "README.md"
88
keywords = [
9-
"quantum",
10-
"computing",
11-
"open source",
9+
"quantum",
10+
"computing",
11+
"open source",
1212
"engineering",
1313
"qiskit"
1414
]
@@ -33,7 +33,7 @@ packages = [
3333
]
3434

3535
[tool.poetry.dependencies] # https://poetry.eustace.io/docs/versions
36-
python = ">=3.7,<3.10"
36+
python = ">=3.7,<3.9"
3737
numpy = "^1.16"
3838
scipy = "^1.3"
3939
toml = "^0.10.0"
@@ -50,6 +50,11 @@ pylint_runner = "*"
5050
sphinx = "^2.2.0"
5151
nbval = "^0.9.5"
5252
qctrl-visualizer = "^2.12.1"
53+
isort = "^5.7.0"
54+
55+
[tool.isort]
56+
profile = "black"
57+
force_grid_wrap = "2"
5358

5459
[tool.dephell.main]
5560
from = {format = "poetry", path = "pyproject.toml"}
@@ -70,4 +75,3 @@ build-backend = "poetry.masonry.api"
7075
# (__)\ )\/\
7176
# ||----w |
7277
# || ||
73-

qctrlqiskit/quantum_circuit.py

Lines changed: 94 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,32 @@
1313
# limitations under the License.
1414

1515
"""
16-
======================
1716
qiskit.quantum_circuit
18-
======================
1917
"""
2018

2119
import numpy as np
22-
20+
from qctrlopencontrols import DynamicDecouplingSequence
21+
from qctrlopencontrols.exceptions import ArgumentsValueError
2322
from qiskit import (
24-
QuantumRegister, ClassicalRegister, QuantumCircuit)
23+
ClassicalRegister,
24+
QuantumCircuit,
25+
QuantumRegister,
26+
)
2527
from qiskit.qasm import pi
2628

27-
from qctrlopencontrols import DynamicDecouplingSequence
28-
29-
from qctrlopencontrols.globals import (FIX_DURATION_UNITARY, INSTANT_UNITARY)
30-
from qctrlopencontrols.exceptions.exceptions import ArgumentsValueError
29+
FIX_DURATION_UNITARY = "fixed duration unitary"
30+
INSTANT_UNITARY = "instant unitary"
3131

3232

3333
def convert_dds_to_qiskit_quantum_circuit(
34-
dynamic_decoupling_sequence,
35-
target_qubits=None,
36-
gate_time=0.1,
37-
add_measurement=True,
38-
algorithm=INSTANT_UNITARY,
39-
quantum_registers=None,
40-
circuit_name=None):
34+
dynamic_decoupling_sequence,
35+
target_qubits=None,
36+
gate_time=0.1,
37+
add_measurement=True,
38+
algorithm=INSTANT_UNITARY,
39+
quantum_registers=None,
40+
circuit_name=None,
41+
):
4142
"""Converts a Dynamic Decoupling Sequence into QuantumCircuit
4243
as defined in Qiskit
4344
@@ -99,39 +100,50 @@ def convert_dds_to_qiskit_quantum_circuit(
99100
"""
100101

101102
if dynamic_decoupling_sequence is None:
102-
raise ArgumentsValueError('No dynamic decoupling sequence provided.',
103-
{'dynamic_decoupling_sequence': dynamic_decoupling_sequence})
103+
raise ArgumentsValueError(
104+
"No dynamic decoupling sequence provided.",
105+
{"dynamic_decoupling_sequence": dynamic_decoupling_sequence},
106+
)
104107

105108
if not isinstance(dynamic_decoupling_sequence, DynamicDecouplingSequence):
106-
raise ArgumentsValueError('Dynamical decoupling sequence is not recognized.'
107-
'Expected DynamicDecouplingSequence instance',
108-
{'type(dynamic_decoupling_sequence)':
109-
type(dynamic_decoupling_sequence)})
109+
raise ArgumentsValueError(
110+
"Dynamical decoupling sequence is not recognized."
111+
"Expected DynamicDecouplingSequence instance",
112+
{"type(dynamic_decoupling_sequence)": type(dynamic_decoupling_sequence)},
113+
)
110114

111115
target_qubits = target_qubits or [0]
112116

113117
if gate_time <= 0:
114118
raise ArgumentsValueError(
115-
'Time delay of identity gate must be greater than zero.',
116-
{'gate_time': gate_time})
119+
"Time delay of identity gate must be greater than zero.",
120+
{"gate_time": gate_time},
121+
)
117122

118123
if np.any(target_qubits) < 0:
119124
raise ArgumentsValueError(
120-
'Every target qubits index must be non-negative.',
121-
{'target_qubits': target_qubits})
125+
"Every target qubits index must be non-negative.",
126+
{"target_qubits": target_qubits},
127+
)
122128

123129
if algorithm not in [FIX_DURATION_UNITARY, INSTANT_UNITARY]:
124-
raise ArgumentsValueError('Algorithm must be one of {} or {}'.format(
125-
INSTANT_UNITARY, FIX_DURATION_UNITARY), {'algorithm': algorithm})
130+
raise ArgumentsValueError(
131+
f"Algorithm must be one of {INSTANT_UNITARY} or {FIX_DURATION_UNITARY}",
132+
{"algorithm": algorithm},
133+
)
126134

127135
if quantum_registers is not None:
128-
if (max(target_qubits)+1) > len(quantum_registers):
129-
raise ArgumentsValueError('Target qubit is not present in quantum_registers',
130-
{'target_qubits': target_qubits,
131-
'size(quantum_registers)': len(quantum_registers)},
132-
extras={'max(target_qubits)': max(target_qubits)})
136+
if (max(target_qubits) + 1) > len(quantum_registers):
137+
raise ArgumentsValueError(
138+
"Target qubit is not present in quantum_registers",
139+
{
140+
"target_qubits": target_qubits,
141+
"size(quantum_registers)": len(quantum_registers),
142+
},
143+
extras={"max(target_qubits)": max(target_qubits)},
144+
)
133145
else:
134-
quantum_registers = QuantumRegister(max(target_qubits)+1)
146+
quantum_registers = QuantumRegister(max(target_qubits) + 1)
135147

136148
classical_registers = None
137149
if add_measurement:
@@ -143,7 +155,7 @@ def convert_dds_to_qiskit_quantum_circuit(
143155
if circuit_name is not None:
144156
quantum_circuit.name = circuit_name
145157

146-
unitary_time = 0.
158+
unitary_time = 0.0
147159
if algorithm == FIX_DURATION_UNITARY:
148160
unitary_time = gate_time
149161

@@ -155,8 +167,11 @@ def convert_dds_to_qiskit_quantum_circuit(
155167

156168
time_covered = 0
157169
for offset, rabi_rotation, azimuthal_angle, detuning_rotation in zip(
158-
list(offsets), list(rabi_rotations),
159-
list(azimuthal_angles), list(detuning_rotations)):
170+
list(offsets),
171+
list(rabi_rotations),
172+
list(azimuthal_angles),
173+
list(detuning_rotations),
174+
):
160175

161176
offset_distance = offset - time_covered
162177

@@ -168,13 +183,20 @@ def convert_dds_to_qiskit_quantum_circuit(
168183
"Offsets cannot be placed properly. Spacing between the rotations"
169184
"is smaller than the time required to perform the rotation. Provide"
170185
"a longer dynamic decoupling sequence or shorted gate time.",
171-
{'dynamic_decoupling_sequence': dynamic_decoupling_sequence,
172-
'gate_time': gate_time})
186+
{
187+
"dynamic_decoupling_sequence": dynamic_decoupling_sequence,
188+
"gate_time": gate_time,
189+
},
190+
)
173191

174-
while (time_covered+gate_time) <= offset:
192+
while (time_covered + gate_time) <= offset:
175193
for qubit in target_qubits:
176-
quantum_circuit.iden(quantum_registers[qubit]) # pylint: disable=no-member
177-
quantum_circuit.barrier(quantum_registers[qubit]) # pylint: disable=no-member
194+
quantum_circuit.iden( # pylint: disable=no-member
195+
quantum_registers[qubit]
196+
)
197+
quantum_circuit.barrier( # pylint: disable=no-member
198+
quantum_registers[qubit]
199+
)
178200
time_covered += gate_time
179201

180202
x_rotation = rabi_rotation * np.cos(azimuthal_angle)
@@ -186,41 +208,53 @@ def convert_dds_to_qiskit_quantum_circuit(
186208
nonzero_pulse_counts = 3 - np.sum(zero_pulses)
187209
if nonzero_pulse_counts > 1:
188210
raise ArgumentsValueError(
189-
'Open Controls support a sequence with one '
190-
'valid rotation at any offset. Found a sequence '
191-
'with multiple rotation operations at an offset.',
192-
{'dynamic_decoupling_sequence': dynamic_decoupling_sequence},
193-
extras={'offset': offset,
194-
'rabi_rotation': rabi_rotation,
195-
'azimuthal_angle': azimuthal_angle,
196-
'detuning_rotation': detuning_rotation}
211+
"Open Controls support a sequence with one "
212+
"valid rotation at any offset. Found a sequence "
213+
"with multiple rotation operations at an offset.",
214+
{"dynamic_decoupling_sequence": dynamic_decoupling_sequence},
215+
extras={
216+
"offset": offset,
217+
"rabi_rotation": rabi_rotation,
218+
"azimuthal_angle": azimuthal_angle,
219+
"detuning_rotation": detuning_rotation,
220+
},
197221
)
198222

199223
for qubit in target_qubits:
200224
if nonzero_pulse_counts == 0:
201225
quantum_circuit.u3(
202-
0., 0., 0., # pylint: disable=no-member
203-
quantum_registers[qubit])
226+
0.0, 0.0, 0.0, quantum_registers[qubit] # pylint: disable=no-member
227+
)
204228
else:
205229
if not np.isclose(rotations[0], 0.0):
206230
quantum_circuit.u3(
207-
rotations[0], -pi / 2, pi / 2, # pylint: disable=no-member
208-
quantum_registers[qubit])
231+
rotations[0],
232+
-pi / 2,
233+
pi / 2, # pylint: disable=no-member
234+
quantum_registers[qubit],
235+
)
209236
elif not np.isclose(rotations[1], 0.0):
210237
quantum_circuit.u3(
211-
rotations[1], 0., 0., # pylint: disable=no-member
212-
quantum_registers[qubit])
213-
elif not np.isclose(rotations[2], 0.):
238+
rotations[1],
239+
0.0,
240+
0.0, # pylint: disable=no-member
241+
quantum_registers[qubit],
242+
)
243+
elif not np.isclose(rotations[2], 0.0):
214244
quantum_circuit.u1(
215245
rotations[2], # pylint: disable=no-member
216-
quantum_registers[qubit])
217-
quantum_circuit.barrier(quantum_registers[qubit]) # pylint: disable=no-member
246+
quantum_registers[qubit],
247+
)
248+
quantum_circuit.barrier(
249+
quantum_registers[qubit]
250+
) # pylint: disable=no-member
218251

219252
time_covered = offset + unitary_time
220253

221254
if add_measurement:
222255
for q_index, qubit in enumerate(target_qubits):
223-
quantum_circuit.measure(quantum_registers[qubit], #pylint: disable=no-member
224-
classical_registers[q_index])
256+
quantum_circuit.measure( # pylint: disable=no-member
257+
quantum_registers[qubit], classical_registers[q_index]
258+
)
225259

226260
return quantum_circuit

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
name='qctrl-qiskit',
2727
version='0.0.3',
2828
description='Q-CTRL Qiskit Adapter',
29-
python_requires='<3.10,>=3.7',
29+
python_requires='<3.9,>=3.7',
3030
project_urls={"repository": "https://github.com/qctrl/python-qiskit"},
3131
author='Q-CTRL',
3232
author_email='[email protected]',
@@ -37,5 +37,5 @@
3737
package_dir={"": "."},
3838
package_data={},
3939
install_requires=['numpy==1.*,>=1.16.0', 'qctrl-open-controls==8.*,>=8.5.1', 'qiskit-ibmq-provider==0.*,>=0.3.3', 'qiskit-terra==0.*,>=0.12.0', 'scipy==1.*,>=1.3.0', 'toml==0.*,>=0.10.0'],
40-
extras_require={"dev": ["nbval==0.*,>=0.9.5", "pylama", "pylint", "pylint-runner", "pytest", "qctrl-visualizer==2.*,>=2.12.1", "sphinx==2.*,>=2.2.0"]},
40+
extras_require={"dev": ["isort==5.*,>=5.7.0", "nbval==0.*,>=0.9.5", "pylama", "pylint", "pylint-runner", "pytest", "qctrl-visualizer==2.*,>=2.12.1", "sphinx==2.*,>=2.2.0"]},
4141
)

0 commit comments

Comments
 (0)