forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing Qubits and Clbits classes (Qiskit#2414)
* bit class * compare to tuple * hashable bits * iter * getitem * avoid duplication of code * test_barrier_none * allow direct access to index and register * layout * snapshot * conditional * defintions * layout * test.python.circuit.test_circuit_registers.TestCircuitRegisters.test_measure_slice * removing some tuple representation * removing some tuple representation * repr * None * test.python.transpiler.test_layout * dag * test.python.compiler.test_compiler.TestCompiler.test_compile_single_qubit * test.python.compiler.test_compiler * order * StochasticSwap * lint * register have order * lint * test.python.visualization.test_visualization * test.python.visualization.test_circuit_text_drawer * test.python.basicaer.test_basicaer_integration * test.python.compiler.test_transpiler * test.python.transpiler.test_remove_diagonal_gates_before_measure * test.python.transpiler.test_stochastic_swap.TestStochasticSwap * test.python.transpiler.test_unroller * test.python.circuit.test_circuit_registers * test.python.transpiler.test_noise_adaptive_layout * test.python.quantum_info.operators.test_operator.TestOperator * mappers * pickles * latex lint * test.python.transpiler.test_full_ancilla_allocation * test.python.transpiler.test_consolidate_blocks * test.python.transpiler.test_commutative_cancellation * test.python.transpiler.test_basic_swap * test.python.quantum_info.operators.channel.test_superop * lint qiskit/converters/ast_to_dag.py * test/python/test_dagcircuit.py * test/python/test_dagcircuit.py * test.python.compiler.test_assembler * test.python.circuit.test_unitary * condition * test.python.circuit.test_circuit_properties * instruction.control * lint * latex condition * qiskit/dagcircuit/dagcircuit.py * qiskit/circuit/quantumcircuit.py * qiskit/assembler/assemble_circuits.py * test for 1898 * Qiskit#2414 (comment) * docstrings * removing order by comparing sets in Collect2qBlocks * QuBit-> Qubit and ClBit-> Clbit * errors * lint * QuBit -> Qubit * ctrl_reg, ctrl_val = instruction._control * https://github.com/Qiskit/qiskit-terra/pull/2414/files/ff8770f7b195f66997a45f01943059d1c6ffaf13#r284695050 * explicit globals * lint * __getitem__ for deprecation * from_tuple * new pickles * docstring * accept gate arguments as tuples and mark them as deprecated * this fix contradicts whats expected from a negative key lookup * promote __iter__ * simpler negative index check... * https://github.com/Qiskit/qiskit-terra/pull/2414/files#r284542889 * docstring lint * getitem * layout backwards compatibility * lint * lint! * deprecated messager only when _is_bit * changelog * expose less the contructor * remove prints and raised text * simplifications * lint
- Loading branch information
Showing
59 changed files
with
872 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2019. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
""" | ||
Quantum bit and Classical bit objects. | ||
""" | ||
from warnings import warn | ||
from qiskit.exceptions import QiskitError | ||
|
||
|
||
class Bit: | ||
"""Implement a generic bit.""" | ||
|
||
def __init__(self, register, index): | ||
"""Create a new generic bit. | ||
""" | ||
try: | ||
index = int(index) | ||
except Exception: | ||
raise QiskitError("index needs to be castable to an int: type %s was provided" % | ||
type(index)) | ||
|
||
if index < 0: | ||
index += register.size | ||
|
||
if index >= register.size: | ||
raise QiskitError("index must be under the size of the register: %s was provided" % | ||
index) | ||
|
||
self.register = register | ||
self.index = index | ||
|
||
def __repr__(self): | ||
"""Return the official string representing the bit.""" | ||
return "%s(%s, %s)" % (self.__class__.__name__, self.register, self.index) | ||
|
||
def __getitem__(self, item): | ||
warn('Accessing a bit register by bit[0] or its index by bit[1] is deprecated. ' | ||
'Go for bit.register and bit.index.', DeprecationWarning) | ||
if item == 0: | ||
return self.register | ||
elif item == 1: | ||
return self.index | ||
else: | ||
raise IndexError | ||
|
||
def __hash__(self): | ||
return hash((self.register, self.index)) | ||
|
||
def __eq__(self, other): | ||
if isinstance(other, tuple): | ||
return other[1] == self.index and other[0] == self.register | ||
return other.index == self.index and other.register == self.register |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.