-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing Qubits and Clbits classes #2414
Merged
Merged
Changes from all commits
Commits
Show all changes
113 commits
Select commit
Hold shift + click to select a range
ee9982c
bit class
f33fb6d
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
209e526
compare to tuple
e818061
hashable bits
41d4570
iter
ee328c4
getitem
1bdb163
avoid duplication of code
7769daf
test_barrier_none
88927cb
allow direct access to index and register
fb73984
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
449b693
layout
428948d
snapshot
1ea2c86
conditional
98fe0d8
defintions
05ef560
layout
345cfba
test.python.circuit.test_circuit_registers.TestCircuitRegisters.test_…
b978268
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
0017f18
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
b6498c7
removing some tuple representation
1e4de02
removing some tuple representation
306251a
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
ecd101d
repr
4a677a8
None
c5d6697
test.python.transpiler.test_layout
82de9cd
dag
b2fed7e
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
ee3526e
test.python.compiler.test_compiler.TestCompiler.test_compile_single_q…
5635a49
test.python.compiler.test_compiler
4ae377a
order
dfc4ac6
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
0d109fe
StochasticSwap
b10d03b
lint
d042a1e
register have order
2b32d5f
Merge branch 'master' into no_tuple_bits
d898e1c
Merge branch 'no_tuple_bits' of https://github.com/1ucian0/qiskit-ter…
5da818b
lint
0602230
test.python.visualization.test_visualization
dc9ff57
test.python.visualization.test_circuit_text_drawer
ca0d461
test.python.basicaer.test_basicaer_integration
8783026
test.python.compiler.test_transpiler
cd91ef4
test.python.transpiler.test_remove_diagonal_gates_before_measure
741c7e7
test.python.transpiler.test_stochastic_swap.TestStochasticSwap
996ad52
test.python.transpiler.test_unroller
f87ee33
test.python.circuit.test_circuit_registers
0cffeb8
test.python.transpiler.test_noise_adaptive_layout
8288799
test.python.quantum_info.operators.test_operator.TestOperator
9d02bb2
Merge branch 'master' into no_tuple_bits
61b4e57
merge
02f758d
mappers
524e9a1
pickles
687b067
latex lint
8d8d359
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
14c3c9f
test.python.transpiler.test_full_ancilla_allocation
7fb84ae
test.python.transpiler.test_consolidate_blocks
33de488
test.python.transpiler.test_commutative_cancellation
1338af1
test.python.transpiler.test_basic_swap
1e6188e
test.python.quantum_info.operators.channel.test_superop
37436ca
lint qiskit/converters/ast_to_dag.py
cde5339
test/python/test_dagcircuit.py
69a00b7
test/python/test_dagcircuit.py
e8c4176
test.python.compiler.test_assembler
e8e5d48
test.python.circuit.test_unitary
0c0fcc9
condition
ec09bb5
test.python.circuit.test_circuit_properties
3226a18
instruction.control
2962853
lint
6ee6ca4
latex condition
5e2931d
qiskit/dagcircuit/dagcircuit.py
bb8e943
qiskit/circuit/quantumcircuit.py
6c79906
qiskit/assembler/assemble_circuits.py
934495f
test for 1898
0523436
https://github.com/Qiskit/qiskit-terra/pull/2414#discussion_r284383842
22d9999
Merge branch 'master' into no_tuple_bits
1ucian0 3a3f92c
docstrings
b465e17
Merge branch 'no_tuple_bits' of https://github.com/1ucian0/qiskit-ter…
7866e38
removing order by comparing sets in Collect2qBlocks
2a350f9
QuBit-> Qubit and ClBit-> Clbit
74c1f24
errors
ff8770f
lint
34cb7a9
QuBit -> Qubit
8b66ddb
ctrl_reg, ctrl_val = instruction._control
36a65b8
https://github.com/Qiskit/qiskit-terra/pull/2414/files/ff8770f7b195f6…
6c8bb16
explicit globals
2c9ae5e
lint
865f864
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
3398896
__getitem__ for deprecation
5f44f9b
from_tuple
b26051a
new pickles
79a5197
docstring
fc4e0ea
accept gate arguments as tuples and mark them as deprecated
829828d
this fix contradicts whats expected from a negative key lookup
126110b
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
00b0a82
promote __iter__
ebb58b7
simpler negative index check...
bf912ca
https://github.com/Qiskit/qiskit-terra/pull/2414/files#r284542889
f2abad6
docstring lint
0db6ad5
getitem
139b1cd
layout backwards compatibility
29dbbdf
lint
702f35a
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
16f90b9
lint!
d876acf
deprecated messager only when _is_bit
803ea5b
changelog
ed5f9a6
Merge branch 'master' into no_tuple_bits
1ucian0 bd4f833
expose less the contructor
5811aac
Merge branch 'master' of github.com:Qiskit/qiskit-terra into no_tuple…
91c6e81
remove prints and raised text
b2132b8
simplifications
1910b6f
lint
4d8ca18
Merge branch 'master' into no_tuple_bits
1ucian0 80693b5
Merge branch 'master' into no_tuple_bits
1ucian0 0a2117d
Merge branch 'master' into no_tuple_bits
1ucian0 9939176
Merge branch 'master' into no_tuple_bits
1ucian0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
1ucian0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this just be
qubit_labels.index(qubit)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you're leaving that to a future PR but without it you don't get the benefit of not having to touch almost all the same pieces of code again when it is implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.. it is not equivalente, because
qubit_labels
's keys are things like['c1', 0]
. I do see that there is room for optimization... but I would prefer to do that in a different PR.