Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,18 @@ jobs:
/var/cache/dnf/
key: ${{ runner.os }}-centos${{ matrix.centos }}-yum-${{ secrets.yum_cache }}

- name: Fix repository URLs (CentOS 8 only)
if: matrix.centos == 8
run: |
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

- name: Add Python 3 and other dependencies
run: yum update -y && yum install -y python3-devel gcc-c++ make

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

- name: Install Git > 2.18
run: yum install -y git
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -39,7 +39,7 @@ repos:

# Changes tabs to spaces
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.10
rev: v1.1.13
hooks:
- id: remove-tabs

Expand All @@ -50,15 +50,15 @@ repos:
name: isort (python)

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

- repo: https://gitlab.com/PyCQA/flake8
rev: 4.0.1
rev: 3.9.2
hooks:
- id: flake8
name: flake8-strict
Expand All @@ -73,7 +73,7 @@ repos:
files: ^(.*_test\.py)$

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

- repo: https://github.com/mgedmin/check-manifest
rev: '0.47'
rev: '0.48'
hooks:
- id: check-manifest
additional_dependencies: ['setuptools-scm', 'pybind11>=2.6']
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.7.2] - 2022-04-11

### Changed

- Added IonQ dynamic backends fetch.

### Repository

- Fix issues with building on CentOS 7 & 8
- Update `pre-commit/pre-commit-hooks` to v4.2.0
- Update `Lucas-C/pre-commit-hooks` hook to v1.1.13
- Update `flake8` hook to v4.0.1
- Update `pylint` hook to v3.0.0a4
- Update `black` hook to v22.3.0
- Update `check-manifest` to v0.48

## [0.7.1] - 2022-01-10

### Added
Expand Down Expand Up @@ -168,7 +184,9 @@ The ProjectQ v0.5.x release branch is the last one that is guaranteed to work wi

Future releases might introduce changes that will require Python 3.5 (Python 3.4 and earlier have already been declared deprecated at the time of this writing)

[Unreleased]: https://github.com/ProjectQ-Framework/ProjectQ/compare/v0.7.1...HEAD
[Unreleased]: https://github.com/ProjectQ-Framework/ProjectQ/compare/v0.7.2...HEAD

[v0.7.2]: https://github.com/ProjectQ-Framework/ProjectQ/compare/v0.7.1...v0.7.2

[0.7.1]: https://github.com/ProjectQ-Framework/ProjectQ/compare/v0.7.0...v0.7.1

Expand Down
2 changes: 1 addition & 1 deletion examples/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def main():

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

# Show the unitaries separated by measurement:
Expand Down
3 changes: 1 addition & 2 deletions projectq/backends/_aqt/_aqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ def get_probabilities(self, qureg):
raise RuntimeError("Please, run the circuit first!")

probability_dict = {}
for state in self._probabilities:
for state, probability in self._probabilities.items():
mapped_state = ['0'] * len(qureg)
for i, qubit in enumerate(qureg):
mapped_state[i] = state[self._logical_to_physical(qubit.id)]
probability = self._probabilities[state]
mapped_state = "".join(mapped_state)

probability_dict[mapped_state] = probability_dict.get(mapped_state, 0) + probability
Expand Down
110 changes: 50 additions & 60 deletions projectq/backends/_awsbraket/_awsbraket.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,49 +172,43 @@ def is_available(self, cmd): # pylint: disable=too-many-return-statements,too-m
if get_control_count(cmd) == 1:
return isinstance(gate, (R, ZGate, XGate, SwapGate))
if get_control_count(cmd) == 0:
return (
isinstance(
gate,
(
R,
Rx,
Ry,
Rz,
XGate,
YGate,
ZGate,
HGate,
SGate,
TGate,
SwapGate,
),
)
or gate in (Sdag, Tdag)
)
return isinstance(
gate,
(
R,
Rx,
Ry,
Rz,
XGate,
YGate,
ZGate,
HGate,
SGate,
TGate,
SwapGate,
),
) or gate in (Sdag, Tdag)

if self.device == 'IonQ Device':
if get_control_count(cmd) == 1:
return isinstance(gate, XGate)
if get_control_count(cmd) == 0:
return (
isinstance(
gate,
(
Rx,
Ry,
Rz,
XGate,
YGate,
ZGate,
HGate,
SGate,
TGate,
SqrtXGate,
SwapGate,
),
)
or gate in (Sdag, Tdag)
)
return isinstance(
gate,
(
Rx,
Ry,
Rz,
XGate,
YGate,
ZGate,
HGate,
SGate,
TGate,
SqrtXGate,
SwapGate,
),
) or gate in (Sdag, Tdag)

if self.device == 'SV1':
if get_control_count(cmd) == 2:
Expand All @@ -224,26 +218,23 @@ def is_available(self, cmd): # pylint: disable=too-many-return-statements,too-m
if get_control_count(cmd) == 0:
# TODO: add MatrixGate to cover the unitary operation
# TODO: Missing XY gate in ProjectQ
return (
isinstance(
gate,
(
R,
Rx,
Ry,
Rz,
XGate,
YGate,
ZGate,
HGate,
SGate,
TGate,
SqrtXGate,
SwapGate,
),
)
or gate in (Sdag, Tdag)
)
return isinstance(
gate,
(
R,
Rx,
Ry,
Rz,
XGate,
YGate,
ZGate,
HGate,
SGate,
TGate,
SqrtXGate,
SwapGate,
),
) or gate in (Sdag, Tdag)
return False

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

probability_dict = {}
for state in self._probabilities:
for state, probability in self._probabilities.items():
mapped_state = ['0'] * len(qureg)
for i, qubit in enumerate(qureg):
if self._logical_to_physical(qubit.id) >= len(state): # pragma: no cover
raise IndexError('Physical ID {} > length of internal probabilities array'.format(qubit.id))
mapped_state[i] = state[self._logical_to_physical(qubit.id)]
probability = self._probabilities[state]
mapped_state = "".join(mapped_state)
if mapped_state not in probability_dict:
probability_dict[mapped_state] = probability
Expand Down
4 changes: 2 additions & 2 deletions projectq/backends/_circuits/_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ def get_latex(self, ordered=False, draw_gates_in_parallel=True):
"""
qubit_lines = {}

for line in range(len(self._qubit_lines)):
for line, qubit_line in self._qubit_lines.items():
new_line = self._map[line]
qubit_lines[new_line] = []
for cmd in self._qubit_lines[line]:
for cmd in qubit_line:
lines = [self._map[qb_id] for qb_id in cmd.lines]
ctrl_lines = [self._map[qb_id] for qb_id in cmd.ctrl_lines]
gate = cmd.gate
Expand Down
8 changes: 4 additions & 4 deletions projectq/backends/_circuits/_drawer_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _process(self, cmd): # pylint: disable=too-many-branches
# considering the qubit axes that are between the topmost and
# bottommost qubit axes of the current command.
if len(targets) + len(controls) > 1:
max_depth = max(len(self._qubit_lines[qubit_id]) for qubit_id in self._qubit_lines)
max_depth = max(len(line) for qubit_id, line in self._qubit_lines.items())

for qb_id in itertools.chain(targets, controls):
depth = len(self._qubit_lines[qb_id])
Expand Down Expand Up @@ -206,9 +206,9 @@ def draw(self, qubit_labels=None, drawing_order=None, **kwargs):
- wire_height (1): Vertical spacing between two qubit
wires (roughly in inches)
"""
max_depth = max(len(self._qubit_lines[qubit_id]) for qubit_id in self._qubit_lines)
for qubit_id in self._qubit_lines:
depth = len(self._qubit_lines[qubit_id])
max_depth = max(len(line) for qubit_id, line in self._qubit_lines.items())
for qubit_id, line in self._qubit_lines.items():
depth = len(line)
if depth < max_depth:
self._qubit_lines[qubit_id] += [None] * (max_depth - depth)

Expand Down
2 changes: 1 addition & 1 deletion projectq/backends/_circuits/_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def to_tikz( # pylint: disable=too-many-branches,too-many-locals,too-many-state
tikz_code.append(connections)

if not draw_gates_in_parallel:
for _line in range(len(self.pos)):
for _line, _ in enumerate(self.pos):
if _line != line:
self.pos[_line] = self.pos[line]

Expand Down
3 changes: 1 addition & 2 deletions projectq/backends/_ibm/_ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,10 @@ def get_probabilities(self, qureg):
raise RuntimeError("Please, run the circuit first!")

probability_dict = {}
for state in self._probabilities:
for state, probability in self._probabilities.items():
mapped_state = ['0'] * len(qureg)
for i, val in enumerate(qureg):
mapped_state[i] = state[self._logical_to_physical(val.id)]
probability = self._probabilities[state]
mapped_state = "".join(mapped_state)
if mapped_state not in probability_dict:
probability_dict[mapped_state] = probability
Expand Down
3 changes: 1 addition & 2 deletions projectq/backends/_ionq/_ionq.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,14 @@ def get_probabilities(self, qureg):
raise RuntimeError("Please, run the circuit first!")

probability_dict = {}
for state in self._probabilities:
for state, probability in self._probabilities.items():
mapped_state = ['0'] * len(qureg)
for i, qubit in enumerate(qureg):
try:
meas_idx = self._measured_ids.index(qubit.id)
except ValueError:
continue
mapped_state[i] = state[meas_idx]
probability = self._probabilities[state]
mapped_state = "".join(mapped_state)
probability_dict[mapped_state] = probability_dict.get(mapped_state, 0) + probability
return probability_dict
Expand Down
27 changes: 14 additions & 13 deletions projectq/backends/_ionq/_ionq_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def __init__(self, verbose=False):

def update_devices_list(self):
"""Update the list of devices this backend can support."""
self.authenticate(self.token)
req = super().get(urljoin(_API_URL, 'backends'))
req.raise_for_status()
r_json = req.json()
# Legacy backends, kept for backward compatibility.
self.backends = {
'ionq_simulator': {
'nq': 29,
Expand All @@ -57,6 +62,8 @@ def update_devices_list(self):
'target': 'qpu',
},
}
for backend in r_json:
self.backends[backend["backend"]] = {"nq": backend["qubits"], "target": backend["backend"]}
if self._verbose: # pragma: no cover
print('- List of IonQ devices available:')
print(self.backends)
Expand Down Expand Up @@ -240,19 +247,14 @@ def _handle_sigint_during_get_result(*_): # pragma: no cover

raise RequestTimeoutError("Timeout. The ID of your submitted job is {}.".format(execution_id))

def show_devices(self):
"""Show the currently available device list for the IonQ provider.

def show_devices(verbose=False):
"""Show the currently available device list for the IonQ provider.

Args:
verbose (bool): If True, additional information is printed

Returns:
list: list of available devices and their properties.
"""
ionq_session = IonQ(verbose=verbose)
ionq_session.update_devices_list()
return ionq_session.backends
Returns:
list: list of available devices and their properties.
"""
self.update_devices_list()
return self.backends


def retrieve(
Expand Down Expand Up @@ -398,6 +400,5 @@ def send(
__all__ = [
'send',
'retrieve',
'show_devices',
'IonQ',
]
Loading