Skip to content

Commit 6f2c2be

Browse files
authored
Update pre commit hooks and fix failing CentOS CI builds (#429)
* Update pre-commit hook versions * Fix linter/formatter warnings * Fix issues with CentOS build on the CI
1 parent 0d32c16 commit 6f2c2be

36 files changed

+147
-151
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,18 @@ jobs:
228228
/var/cache/dnf/
229229
key: ${{ runner.os }}-centos${{ matrix.centos }}-yum-${{ secrets.yum_cache }}
230230

231+
- name: Fix repository URLs (CentOS 8 only)
232+
if: matrix.centos == 8
233+
run: |
234+
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
235+
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
236+
231237
- name: Add Python 3 and other dependencies
232238
run: yum update -y && yum install -y python3-devel gcc-c++ make
233239

234240
- name: Setup Endpoint repository (CentOS 7 only)
235241
if: matrix.centos == 7
236-
run: yum -y install https://packages.endpoint.com/rhel/7/os/x86_64/endpoint-repo-1.7-1.x86_64.rpm
242+
run: yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
237243

238244
- name: Install Git > 2.18
239245
run: yum install -y git

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repos:
3939

4040
# Changes tabs to spaces
4141
- repo: https://github.com/Lucas-C/pre-commit-hooks
42-
rev: v1.1.10
42+
rev: v1.1.13
4343
hooks:
4444
- id: remove-tabs
4545

@@ -50,15 +50,15 @@ repos:
5050
name: isort (python)
5151

5252
- repo: https://github.com/psf/black
53-
rev: 21.12b0
53+
rev: 22.3.0
5454
hooks:
5555
- id: black
5656
language_version: python3
5757
# This is a slow hook, so only run this if --hook-stage manual is passed
5858
stages: [manual]
5959

6060
- repo: https://gitlab.com/PyCQA/flake8
61-
rev: 4.0.1
61+
rev: 3.9.2
6262
hooks:
6363
- id: flake8
6464
name: flake8-strict
@@ -73,7 +73,7 @@ repos:
7373
files: ^(.*_test\.py)$
7474

7575
- repo: https://github.com/pre-commit/mirrors-pylint
76-
rev: 'v3.0.0a3'
76+
rev: 'v3.0.0a4'
7777
hooks:
7878
- id: pylint
7979
args: ['--score=n']
@@ -82,7 +82,7 @@ repos:
8282
additional_dependencies: [pybind11>=2.6, numpy, requests, boto3, matplotlib, networkx, sympy]
8383

8484
- repo: https://github.com/mgedmin/check-manifest
85-
rev: '0.47'
85+
rev: '0.48'
8686
hooks:
8787
- id: check-manifest
8888
additional_dependencies: ['setuptools-scm', 'pybind11>=2.6']

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Repository
11+
12+
- Fix issues with building on CentOS 7 & 8
13+
- Update `Lucas-C/pre-commit-hooks` hook to v1.1.13
14+
- Update `flake8` hook to v4.0.1
15+
- Update `pylint` hook to v3.0.0a4
16+
- Update `black` hook to v22.3.0
17+
- Update `check-manifest` to v0.48
18+
1019
## [0.7.1] - 2022-01-10
1120

1221
### Added

examples/unitary_simulator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def main():
7070

7171
# Output the final state of the qubits (assuming they all start in state |0>)
7272
print('The final state of the qubits is:')
73-
print(eng.backend.unitary @ np.array([1] + ([0] * (2 ** n_qubits - 1))))
73+
print(eng.backend.unitary @ np.array([1] + ([0] * (2**n_qubits - 1))))
7474
print('\n')
7575

7676
# Show the unitaries separated by measurement:

projectq/backends/_aqt/_aqt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,10 @@ def get_probabilities(self, qureg):
222222
raise RuntimeError("Please, run the circuit first!")
223223

224224
probability_dict = {}
225-
for state in self._probabilities:
225+
for state, probability in self._probabilities.items():
226226
mapped_state = ['0'] * len(qureg)
227227
for i, qubit in enumerate(qureg):
228228
mapped_state[i] = state[self._logical_to_physical(qubit.id)]
229-
probability = self._probabilities[state]
230229
mapped_state = "".join(mapped_state)
231230

232231
probability_dict[mapped_state] = probability_dict.get(mapped_state, 0) + probability

projectq/backends/_awsbraket/_awsbraket.py

Lines changed: 50 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -172,49 +172,43 @@ def is_available(self, cmd): # pylint: disable=too-many-return-statements,too-m
172172
if get_control_count(cmd) == 1:
173173
return isinstance(gate, (R, ZGate, XGate, SwapGate))
174174
if get_control_count(cmd) == 0:
175-
return (
176-
isinstance(
177-
gate,
178-
(
179-
R,
180-
Rx,
181-
Ry,
182-
Rz,
183-
XGate,
184-
YGate,
185-
ZGate,
186-
HGate,
187-
SGate,
188-
TGate,
189-
SwapGate,
190-
),
191-
)
192-
or gate in (Sdag, Tdag)
193-
)
175+
return isinstance(
176+
gate,
177+
(
178+
R,
179+
Rx,
180+
Ry,
181+
Rz,
182+
XGate,
183+
YGate,
184+
ZGate,
185+
HGate,
186+
SGate,
187+
TGate,
188+
SwapGate,
189+
),
190+
) or gate in (Sdag, Tdag)
194191

195192
if self.device == 'IonQ Device':
196193
if get_control_count(cmd) == 1:
197194
return isinstance(gate, XGate)
198195
if get_control_count(cmd) == 0:
199-
return (
200-
isinstance(
201-
gate,
202-
(
203-
Rx,
204-
Ry,
205-
Rz,
206-
XGate,
207-
YGate,
208-
ZGate,
209-
HGate,
210-
SGate,
211-
TGate,
212-
SqrtXGate,
213-
SwapGate,
214-
),
215-
)
216-
or gate in (Sdag, Tdag)
217-
)
196+
return isinstance(
197+
gate,
198+
(
199+
Rx,
200+
Ry,
201+
Rz,
202+
XGate,
203+
YGate,
204+
ZGate,
205+
HGate,
206+
SGate,
207+
TGate,
208+
SqrtXGate,
209+
SwapGate,
210+
),
211+
) or gate in (Sdag, Tdag)
218212

219213
if self.device == 'SV1':
220214
if get_control_count(cmd) == 2:
@@ -224,26 +218,23 @@ def is_available(self, cmd): # pylint: disable=too-many-return-statements,too-m
224218
if get_control_count(cmd) == 0:
225219
# TODO: add MatrixGate to cover the unitary operation
226220
# TODO: Missing XY gate in ProjectQ
227-
return (
228-
isinstance(
229-
gate,
230-
(
231-
R,
232-
Rx,
233-
Ry,
234-
Rz,
235-
XGate,
236-
YGate,
237-
ZGate,
238-
HGate,
239-
SGate,
240-
TGate,
241-
SqrtXGate,
242-
SwapGate,
243-
),
244-
)
245-
or gate in (Sdag, Tdag)
246-
)
221+
return isinstance(
222+
gate,
223+
(
224+
R,
225+
Rx,
226+
Ry,
227+
Rz,
228+
XGate,
229+
YGate,
230+
ZGate,
231+
HGate,
232+
SGate,
233+
TGate,
234+
SqrtXGate,
235+
SwapGate,
236+
),
237+
) or gate in (Sdag, Tdag)
247238
return False
248239

249240
def _reset(self):
@@ -372,13 +363,12 @@ def get_probabilities(self, qureg):
372363
raise RuntimeError("Please, run the circuit first!")
373364

374365
probability_dict = {}
375-
for state in self._probabilities:
366+
for state, probability in self._probabilities.items():
376367
mapped_state = ['0'] * len(qureg)
377368
for i, qubit in enumerate(qureg):
378369
if self._logical_to_physical(qubit.id) >= len(state): # pragma: no cover
379370
raise IndexError('Physical ID {} > length of internal probabilities array'.format(qubit.id))
380371
mapped_state[i] = state[self._logical_to_physical(qubit.id)]
381-
probability = self._probabilities[state]
382372
mapped_state = "".join(mapped_state)
383373
if mapped_state not in probability_dict:
384374
probability_dict[mapped_state] = probability

projectq/backends/_circuits/_drawer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ def get_latex(self, ordered=False, draw_gates_in_parallel=True):
265265
"""
266266
qubit_lines = {}
267267

268-
for line in range(len(self._qubit_lines)):
268+
for line, qubit_line in self._qubit_lines.items():
269269
new_line = self._map[line]
270270
qubit_lines[new_line] = []
271-
for cmd in self._qubit_lines[line]:
271+
for cmd in qubit_line:
272272
lines = [self._map[qb_id] for qb_id in cmd.lines]
273273
ctrl_lines = [self._map[qb_id] for qb_id in cmd.ctrl_lines]
274274
gate = cmd.gate

projectq/backends/_circuits/_drawer_matplotlib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _process(self, cmd): # pylint: disable=too-many-branches
144144
# considering the qubit axes that are between the topmost and
145145
# bottommost qubit axes of the current command.
146146
if len(targets) + len(controls) > 1:
147-
max_depth = max(len(self._qubit_lines[qubit_id]) for qubit_id in self._qubit_lines)
147+
max_depth = max(len(line) for qubit_id, line in self._qubit_lines.items())
148148

149149
for qb_id in itertools.chain(targets, controls):
150150
depth = len(self._qubit_lines[qb_id])
@@ -206,9 +206,9 @@ def draw(self, qubit_labels=None, drawing_order=None, **kwargs):
206206
- wire_height (1): Vertical spacing between two qubit
207207
wires (roughly in inches)
208208
"""
209-
max_depth = max(len(self._qubit_lines[qubit_id]) for qubit_id in self._qubit_lines)
210-
for qubit_id in self._qubit_lines:
211-
depth = len(self._qubit_lines[qubit_id])
209+
max_depth = max(len(line) for qubit_id, line in self._qubit_lines.items())
210+
for qubit_id, line in self._qubit_lines.items():
211+
depth = len(line)
212212
if depth < max_depth:
213213
self._qubit_lines[qubit_id] += [None] * (max_depth - depth)
214214

projectq/backends/_circuits/_to_latex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def to_tikz( # pylint: disable=too-many-branches,too-many-locals,too-many-state
423423
tikz_code.append(connections)
424424

425425
if not draw_gates_in_parallel:
426-
for _line in range(len(self.pos)):
426+
for _line, _ in enumerate(self.pos):
427427
if _line != line:
428428
self.pos[_line] = self.pos[line]
429429

projectq/backends/_ibm/_ibm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,10 @@ def get_probabilities(self, qureg):
247247
raise RuntimeError("Please, run the circuit first!")
248248

249249
probability_dict = {}
250-
for state in self._probabilities:
250+
for state, probability in self._probabilities.items():
251251
mapped_state = ['0'] * len(qureg)
252252
for i, val in enumerate(qureg):
253253
mapped_state[i] = state[self._logical_to_physical(val.id)]
254-
probability = self._probabilities[state]
255254
mapped_state = "".join(mapped_state)
256255
if mapped_state not in probability_dict:
257256
probability_dict[mapped_state] = probability

0 commit comments

Comments
 (0)