Skip to content

Commit

Permalink
Fix warnings from linters/formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
Takishima committed Jan 4, 2022
1 parent 77840df commit 94eb28d
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 253 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ jobs:
- name: Build and install package (Unix)
if: runner.os != 'Windows'
run: |
python -m pip install -ve .[braket,revkit,test,qiskit,pyparsing]
python -m pip install -ve .[braket,revkit,test,qiskit,pyparsing]
- name: Build and install package (Windows)
if: runner.os == 'Windows'
run: |
python -m pip install -ve .[braket,test,qiskit,pyparsing]
python -m pip install -ve .[braket,test,qiskit,pyparsing]
- name: Pytest
run: |
Expand Down
46 changes: 19 additions & 27 deletions projectq/backends/_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,40 @@
# 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.
""" Backend to convert ProjectQ commands to OpenQASM. """
"""Backend to convert ProjectQ commands to OpenQASM."""

from copy import deepcopy

from projectq.cengines import BasicEngine
from projectq.meta import get_control_count, has_negative_control
from projectq.ops import (
X,
NOT,
Y,
Z,
T,
Tdag,
S,
Sdag,
Allocate,
Barrier,
Deallocate,
FlushGate,
H,
Measure,
Ph,
R,
Rx,
Ry,
Rz,
S,
Sdag,
Swap,
Measure,
Allocate,
Deallocate,
Barrier,
FlushGate,
T,
Tdag,
X,
Y,
Z,
)


# ==============================================================================


class OpenQASMBackend(BasicEngine): # pylint: disable=too-many-instance-attributes
"""
Engine to convert ProjectQ commands to OpenQASM format (either string or file)
"""
"""Engine to convert ProjectQ commands to OpenQASM format (either string or file)."""

def __init__(
self,
Expand Down Expand Up @@ -87,18 +84,16 @@ def __init__(
self._qubit_id_mapping_redux = qubit_id_mapping_redux

self._output = []
self._qreg_dict = dict()
self._creg_dict = dict()
self._qreg_dict = {}
self._creg_dict = {}
self._reg_index = 0
self._available_indices = []

self._insert_openqasm_header()

@property
def qasm(self):
"""
Access to the QASM representation of the circuit.
"""
"""Access to the QASM representation of the circuit."""
return self._output

def is_available(self, cmd):
Expand Down Expand Up @@ -146,8 +141,7 @@ def is_available(self, cmd):

def receive(self, command_list):
"""
Receives a command list and, for each command, stores it until
completion.
Receives a command list and, for each command, stores it until completion.
Args:
command_list: List of commands to execute
Expand Down Expand Up @@ -309,9 +303,7 @@ def _insert_openqasm_header(self):
self._output.append('include "stdgates.inc";')

def _reset_after_flush(self):
"""
Reset the internal quantum circuit after a FlushGate
"""
"""Reset the internal quantum circuit after a FlushGate."""
if not self._collate_callback:
self._output.append('# ' + '=' * 80)
else:
Expand Down
34 changes: 18 additions & 16 deletions projectq/backends/_qasm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,37 @@
# limitations under the License.
"""Tests for projectq.cengines._openqasm.py."""

import re

import pytest

import re
from projectq.cengines import MainEngine, DummyEngine
from projectq.cengines import DummyEngine, MainEngine
from projectq.meta import Control
from projectq.ops import (
X,
NOT,
Y,
Z,
T,
Tdagger,
S,
Sdagger,
All,
Allocate,
Barrier,
Command,
Deallocate,
Entangle,
H,
Measure,
Ph,
R,
Rx,
Ry,
Rz,
Allocate,
Deallocate,
Measure,
Barrier,
Entangle,
Command,
All,
S,
Sdagger,
T,
Tdagger,
X,
Y,
Z,
)
from projectq.types import WeakQubitRef

from ._qasm import OpenQASMBackend

# ==============================================================================
Expand Down
Loading

0 comments on commit 94eb28d

Please sign in to comment.