partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
test
QuantumCircuit.add_register
Add registers.
qiskit/circuit/quantumcircuit.py
def add_register(self, *regs): """Add registers.""" if not regs: return if any([isinstance(reg, int) for reg in regs]): # QuantumCircuit defined without registers if len(regs) == 1 and isinstance(regs[0], int): # QuantumCircuit with anonymous ...
def add_register(self, *regs): """Add registers.""" if not regs: return if any([isinstance(reg, int) for reg in regs]): # QuantumCircuit defined without registers if len(regs) == 1 and isinstance(regs[0], int): # QuantumCircuit with anonymous ...
[ "Add", "registers", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L296-L323
[ "def", "add_register", "(", "self", ",", "*", "regs", ")", ":", "if", "not", "regs", ":", "return", "if", "any", "(", "[", "isinstance", "(", "reg", ",", "int", ")", "for", "reg", "in", "regs", "]", ")", ":", "# QuantumCircuit defined without registers",...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit._check_dups
Raise exception if list of qubits contains duplicates.
qiskit/circuit/quantumcircuit.py
def _check_dups(self, qubits): """Raise exception if list of qubits contains duplicates.""" squbits = set(qubits) if len(squbits) != len(qubits): raise QiskitError("duplicate qubit arguments")
def _check_dups(self, qubits): """Raise exception if list of qubits contains duplicates.""" squbits = set(qubits) if len(squbits) != len(qubits): raise QiskitError("duplicate qubit arguments")
[ "Raise", "exception", "if", "list", "of", "qubits", "contains", "duplicates", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L325-L329
[ "def", "_check_dups", "(", "self", ",", "qubits", ")", ":", "squbits", "=", "set", "(", "qubits", ")", "if", "len", "(", "squbits", ")", "!=", "len", "(", "qubits", ")", ":", "raise", "QiskitError", "(", "\"duplicate qubit arguments\"", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit._check_qargs
Raise exception if a qarg is not in this circuit or bad format.
qiskit/circuit/quantumcircuit.py
def _check_qargs(self, qargs): """Raise exception if a qarg is not in this circuit or bad format.""" if not all(isinstance(i, tuple) and isinstance(i[0], QuantumRegister) and isinstance(i[1], int) for i in qargs): raise QiskitError("qarg not (QuantumRegi...
def _check_qargs(self, qargs): """Raise exception if a qarg is not in this circuit or bad format.""" if not all(isinstance(i, tuple) and isinstance(i[0], QuantumRegister) and isinstance(i[1], int) for i in qargs): raise QiskitError("qarg not (QuantumRegi...
[ "Raise", "exception", "if", "a", "qarg", "is", "not", "in", "this", "circuit", "or", "bad", "format", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L331-L340
[ "def", "_check_qargs", "(", "self", ",", "qargs", ")", ":", "if", "not", "all", "(", "isinstance", "(", "i", ",", "tuple", ")", "and", "isinstance", "(", "i", "[", "0", "]", ",", "QuantumRegister", ")", "and", "isinstance", "(", "i", "[", "1", "]",...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit._check_cargs
Raise exception if clbit is not in this circuit or bad format.
qiskit/circuit/quantumcircuit.py
def _check_cargs(self, cargs): """Raise exception if clbit is not in this circuit or bad format.""" if not all(isinstance(i, tuple) and isinstance(i[0], ClassicalRegister) and isinstance(i[1], int) for i in cargs): raise QiskitError("carg not (ClassicalR...
def _check_cargs(self, cargs): """Raise exception if clbit is not in this circuit or bad format.""" if not all(isinstance(i, tuple) and isinstance(i[0], ClassicalRegister) and isinstance(i[1], int) for i in cargs): raise QiskitError("carg not (ClassicalR...
[ "Raise", "exception", "if", "clbit", "is", "not", "in", "this", "circuit", "or", "bad", "format", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L342-L351
[ "def", "_check_cargs", "(", "self", ",", "cargs", ")", ":", "if", "not", "all", "(", "isinstance", "(", "i", ",", "tuple", ")", "and", "isinstance", "(", "i", "[", "0", "]", ",", "ClassicalRegister", ")", "and", "isinstance", "(", "i", "[", "1", "]...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.decompose
Call a decomposition pass on this circuit, to decompose one level (shallow decompose). Returns: QuantumCircuit: a circuit one level decomposed
qiskit/circuit/quantumcircuit.py
def decompose(self): """Call a decomposition pass on this circuit, to decompose one level (shallow decompose). Returns: QuantumCircuit: a circuit one level decomposed """ from qiskit.transpiler.passes.decompose import Decompose from qiskit.converters.circuit_...
def decompose(self): """Call a decomposition pass on this circuit, to decompose one level (shallow decompose). Returns: QuantumCircuit: a circuit one level decomposed """ from qiskit.transpiler.passes.decompose import Decompose from qiskit.converters.circuit_...
[ "Call", "a", "decomposition", "pass", "on", "this", "circuit", "to", "decompose", "one", "level", "(", "shallow", "decompose", ")", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L363-L375
[ "def", "decompose", "(", "self", ")", ":", "from", "qiskit", ".", "transpiler", ".", "passes", ".", "decompose", "import", "Decompose", "from", "qiskit", ".", "converters", ".", "circuit_to_dag", "import", "circuit_to_dag", "from", "qiskit", ".", "converters", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit._check_compatible_regs
Raise exception if the circuits are defined on incompatible registers
qiskit/circuit/quantumcircuit.py
def _check_compatible_regs(self, rhs): """Raise exception if the circuits are defined on incompatible registers""" list1 = self.qregs + self.cregs list2 = rhs.qregs + rhs.cregs for element1 in list1: for element2 in list2: if element2.name == element1.name: ...
def _check_compatible_regs(self, rhs): """Raise exception if the circuits are defined on incompatible registers""" list1 = self.qregs + self.cregs list2 = rhs.qregs + rhs.cregs for element1 in list1: for element2 in list2: if element2.name == element1.name: ...
[ "Raise", "exception", "if", "the", "circuits", "are", "defined", "on", "incompatible", "registers" ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L377-L385
[ "def", "_check_compatible_regs", "(", "self", ",", "rhs", ")", ":", "list1", "=", "self", ".", "qregs", "+", "self", ".", "cregs", "list2", "=", "rhs", ".", "qregs", "+", "rhs", ".", "cregs", "for", "element1", "in", "list1", ":", "for", "element2", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.qasm
Return OpenQASM string.
qiskit/circuit/quantumcircuit.py
def qasm(self): """Return OpenQASM string.""" string_temp = self.header + "\n" string_temp += self.extension_lib + "\n" for register in self.qregs: string_temp += register.qasm() + "\n" for register in self.cregs: string_temp += register.qasm() + "\n" ...
def qasm(self): """Return OpenQASM string.""" string_temp = self.header + "\n" string_temp += self.extension_lib + "\n" for register in self.qregs: string_temp += register.qasm() + "\n" for register in self.cregs: string_temp += register.qasm() + "\n" ...
[ "Return", "OpenQASM", "string", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L387-L406
[ "def", "qasm", "(", "self", ")", ":", "string_temp", "=", "self", ".", "header", "+", "\"\\n\"", "string_temp", "+=", "self", ".", "extension_lib", "+", "\"\\n\"", "for", "register", "in", "self", ".", "qregs", ":", "string_temp", "+=", "register", ".", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.draw
Draw the quantum circuit Using the output parameter you can specify the format. The choices are: 0. text: ASCII art string 1. latex: high-quality images, but heavy external software dependencies 2. matplotlib: purely in Python with no external dependencies Defaults to an overco...
qiskit/circuit/quantumcircuit.py
def draw(self, scale=0.7, filename=None, style=None, output='text', interactive=False, line_length=None, plot_barriers=True, reverse_bits=False, justify=None): """Draw the quantum circuit Using the output parameter you can specify the format. The choices are: 0. text: ...
def draw(self, scale=0.7, filename=None, style=None, output='text', interactive=False, line_length=None, plot_barriers=True, reverse_bits=False, justify=None): """Draw the quantum circuit Using the output parameter you can specify the format. The choices are: 0. text: ...
[ "Draw", "the", "quantum", "circuit" ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L408-L467
[ "def", "draw", "(", "self", ",", "scale", "=", "0.7", ",", "filename", "=", "None", ",", "style", "=", "None", ",", "output", "=", "'text'", ",", "interactive", "=", "False", ",", "line_length", "=", "None", ",", "plot_barriers", "=", "True", ",", "r...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.size
Returns total number of gate operations in circuit. Returns: int: Total number of gate operations.
qiskit/circuit/quantumcircuit.py
def size(self): """Returns total number of gate operations in circuit. Returns: int: Total number of gate operations. """ gate_ops = 0 for instr, _, _ in self.data: if instr.name not in ['barrier', 'snapshot']: gate_ops += 1 return...
def size(self): """Returns total number of gate operations in circuit. Returns: int: Total number of gate operations. """ gate_ops = 0 for instr, _, _ in self.data: if instr.name not in ['barrier', 'snapshot']: gate_ops += 1 return...
[ "Returns", "total", "number", "of", "gate", "operations", "in", "circuit", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L469-L479
[ "def", "size", "(", "self", ")", ":", "gate_ops", "=", "0", "for", "instr", ",", "_", ",", "_", "in", "self", ".", "data", ":", "if", "instr", ".", "name", "not", "in", "[", "'barrier'", ",", "'snapshot'", "]", ":", "gate_ops", "+=", "1", "return...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.depth
Return circuit depth (i.e. length of critical path). This does not include compiler or simulator directives such as 'barrier' or 'snapshot'. Returns: int: Depth of circuit. Notes: The circuit depth and the DAG depth need not bt the same.
qiskit/circuit/quantumcircuit.py
def depth(self): """Return circuit depth (i.e. length of critical path). This does not include compiler or simulator directives such as 'barrier' or 'snapshot'. Returns: int: Depth of circuit. Notes: The circuit depth and the DAG depth need not bt the ...
def depth(self): """Return circuit depth (i.e. length of critical path). This does not include compiler or simulator directives such as 'barrier' or 'snapshot'. Returns: int: Depth of circuit. Notes: The circuit depth and the DAG depth need not bt the ...
[ "Return", "circuit", "depth", "(", "i", ".", "e", ".", "length", "of", "critical", "path", ")", ".", "This", "does", "not", "include", "compiler", "or", "simulator", "directives", "such", "as", "barrier", "or", "snapshot", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L481-L536
[ "def", "depth", "(", "self", ")", ":", "# Labels the registers by ints", "# and then the qubit position in", "# a register is given by reg_int+qubit_num", "reg_offset", "=", "0", "reg_map", "=", "{", "}", "for", "reg", "in", "self", ".", "qregs", "+", "self", ".", "...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.width
Return number of qubits plus clbits in circuit. Returns: int: Width of circuit.
qiskit/circuit/quantumcircuit.py
def width(self): """Return number of qubits plus clbits in circuit. Returns: int: Width of circuit. """ return sum(reg.size for reg in self.qregs+self.cregs)
def width(self): """Return number of qubits plus clbits in circuit. Returns: int: Width of circuit. """ return sum(reg.size for reg in self.qregs+self.cregs)
[ "Return", "number", "of", "qubits", "plus", "clbits", "in", "circuit", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L538-L545
[ "def", "width", "(", "self", ")", ":", "return", "sum", "(", "reg", ".", "size", "for", "reg", "in", "self", ".", "qregs", "+", "self", ".", "cregs", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.count_ops
Count each operation kind in the circuit. Returns: dict: a breakdown of how many operations of each kind.
qiskit/circuit/quantumcircuit.py
def count_ops(self): """Count each operation kind in the circuit. Returns: dict: a breakdown of how many operations of each kind. """ count_ops = {} for instr, _, _ in self.data: if instr.name in count_ops.keys(): count_ops[instr.name] += ...
def count_ops(self): """Count each operation kind in the circuit. Returns: dict: a breakdown of how many operations of each kind. """ count_ops = {} for instr, _, _ in self.data: if instr.name in count_ops.keys(): count_ops[instr.name] += ...
[ "Count", "each", "operation", "kind", "in", "the", "circuit", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L547-L559
[ "def", "count_ops", "(", "self", ")", ":", "count_ops", "=", "{", "}", "for", "instr", ",", "_", ",", "_", "in", "self", ".", "data", ":", "if", "instr", ".", "name", "in", "count_ops", ".", "keys", "(", ")", ":", "count_ops", "[", "instr", ".", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.num_connected_components
How many non-entangled subcircuits can the circuit be factored to. Args: unitary_only (bool): Compute only unitary part of graph. Returns: int: Number of connected components in circuit.
qiskit/circuit/quantumcircuit.py
def num_connected_components(self, unitary_only=False): """How many non-entangled subcircuits can the circuit be factored to. Args: unitary_only (bool): Compute only unitary part of graph. Returns: int: Number of connected components in circuit. """ # Co...
def num_connected_components(self, unitary_only=False): """How many non-entangled subcircuits can the circuit be factored to. Args: unitary_only (bool): Compute only unitary part of graph. Returns: int: Number of connected components in circuit. """ # Co...
[ "How", "many", "non", "-", "entangled", "subcircuits", "can", "the", "circuit", "be", "factored", "to", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L561-L639
[ "def", "num_connected_components", "(", "self", ",", "unitary_only", "=", "False", ")", ":", "# Convert registers to ints (as done in depth).", "reg_offset", "=", "0", "reg_map", "=", "{", "}", "if", "unitary_only", ":", "regs", "=", "self", ".", "qregs", "else", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit.bind_parameters
Assign parameters to values yielding a new circuit. Args: value_dict (dict): {parameter: value, ...} Raises: QiskitError: If value_dict contains parameters not present in the circuit Returns: QuantumCircuit: copy of self with assignment substitution.
qiskit/circuit/quantumcircuit.py
def bind_parameters(self, value_dict): """Assign parameters to values yielding a new circuit. Args: value_dict (dict): {parameter: value, ...} Raises: QiskitError: If value_dict contains parameters not present in the circuit Returns: QuantumCircuit:...
def bind_parameters(self, value_dict): """Assign parameters to values yielding a new circuit. Args: value_dict (dict): {parameter: value, ...} Raises: QiskitError: If value_dict contains parameters not present in the circuit Returns: QuantumCircuit:...
[ "Assign", "parameters", "to", "values", "yielding", "a", "new", "circuit", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L700-L723
[ "def", "bind_parameters", "(", "self", ",", "value_dict", ")", ":", "new_circuit", "=", "self", ".", "copy", "(", ")", "if", "value_dict", ".", "keys", "(", ")", ">", "self", ".", "parameters", ":", "raise", "QiskitError", "(", "'Cannot bind parameters ({}) ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QuantumCircuit._bind_parameter
Assigns a parameter value to matching instructions in-place.
qiskit/circuit/quantumcircuit.py
def _bind_parameter(self, parameter, value): """Assigns a parameter value to matching instructions in-place.""" for (instr, param_index) in self._parameter_table[parameter]: instr.params[param_index] = value
def _bind_parameter(self, parameter, value): """Assigns a parameter value to matching instructions in-place.""" for (instr, param_index) in self._parameter_table[parameter]: instr.params[param_index] = value
[ "Assigns", "a", "parameter", "value", "to", "matching", "instructions", "in", "-", "place", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/quantumcircuit.py#L725-L728
[ "def", "_bind_parameter", "(", "self", ",", "parameter", ",", "value", ")", ":", "for", "(", "instr", ",", "param_index", ")", "in", "self", ".", "_parameter_table", "[", "parameter", "]", ":", "instr", ".", "params", "[", "param_index", "]", "=", "value...
d4f58d903bc96341b816f7c35df936d6421267d1
test
pulse_drawer
Plot the interpolated envelope of pulse Args: samples (ndarray): Data points of complex pulse envelope. duration (int): Pulse length (number of points). dt (float): Time interval of samples. interp_method (str): Method of interpolation (set `None` for turn off the interp...
qiskit/visualization/pulse_visualization.py
def pulse_drawer(samples, duration, dt=None, interp_method='None', filename=None, interactive=False, dpi=150, nop=1000, size=(6, 5)): """Plot the interpolated envelope of pulse Args: samples (ndarray): Data points of complex pulse envelope. duration (int): Puls...
def pulse_drawer(samples, duration, dt=None, interp_method='None', filename=None, interactive=False, dpi=150, nop=1000, size=(6, 5)): """Plot the interpolated envelope of pulse Args: samples (ndarray): Data points of complex pulse envelope. duration (int): Puls...
[ "Plot", "the", "interpolated", "envelope", "of", "pulse" ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/visualization/pulse_visualization.py#L20-L103
[ "def", "pulse_drawer", "(", "samples", ",", "duration", ",", "dt", "=", "None", ",", "interp_method", "=", "'None'", ",", "filename", "=", "None", ",", "interactive", "=", "False", ",", "dpi", "=", "150", ",", "nop", "=", "1000", ",", "size", "=", "(...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_search_forward_n_swaps
Search for SWAPs which allow for application of largest number of gates. Arguments: layout (Layout): Map from virtual qubit index to physical qubit index. gates (list): Gates to be mapped. coupling_map (CouplingMap): CouplingMap of the target backend. depth (int): Number of SWAP lay...
qiskit/transpiler/passes/mapping/lookahead_swap.py
def _search_forward_n_swaps(layout, gates, coupling_map, depth=SEARCH_DEPTH, width=SEARCH_WIDTH): """Search for SWAPs which allow for application of largest number of gates. Arguments: layout (Layout): Map from virtual qubit index to physical qubit index. gates (list...
def _search_forward_n_swaps(layout, gates, coupling_map, depth=SEARCH_DEPTH, width=SEARCH_WIDTH): """Search for SWAPs which allow for application of largest number of gates. Arguments: layout (Layout): Map from virtual qubit index to physical qubit index. gates (list...
[ "Search", "for", "SWAPs", "which", "allow", "for", "application", "of", "largest", "number", "of", "gates", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/lookahead_swap.py#L126-L181
[ "def", "_search_forward_n_swaps", "(", "layout", ",", "gates", ",", "coupling_map", ",", "depth", "=", "SEARCH_DEPTH", ",", "width", "=", "SEARCH_WIDTH", ")", ":", "gates_mapped", ",", "gates_remaining", "=", "_map_free_gates", "(", "layout", ",", "gates", ",", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_map_free_gates
Map all gates that can be executed with the current layout. Args: layout (Layout): Map from virtual qubit index to physical qubit index. gates (list): Gates to be mapped. coupling_map (CouplingMap): CouplingMap for target device topology. Returns: tuple: mapped_gate...
qiskit/transpiler/passes/mapping/lookahead_swap.py
def _map_free_gates(layout, gates, coupling_map): """Map all gates that can be executed with the current layout. Args: layout (Layout): Map from virtual qubit index to physical qubit index. gates (list): Gates to be mapped. coupling_map (CouplingMap): CouplingMap for target device topol...
def _map_free_gates(layout, gates, coupling_map): """Map all gates that can be executed with the current layout. Args: layout (Layout): Map from virtual qubit index to physical qubit index. gates (list): Gates to be mapped. coupling_map (CouplingMap): CouplingMap for target device topol...
[ "Map", "all", "gates", "that", "can", "be", "executed", "with", "the", "current", "layout", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/lookahead_swap.py#L184-L236
[ "def", "_map_free_gates", "(", "layout", ",", "gates", ",", "coupling_map", ")", ":", "blocked_qubits", "=", "set", "(", ")", "mapped_gates", "=", "[", "]", "remaining_gates", "=", "[", "]", "for", "gate", "in", "gates", ":", "# Gates without a partition (barr...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_calc_layout_distance
Return the sum of the distances of two-qubit pairs in each CNOT in gates according to the layout and the coupling.
qiskit/transpiler/passes/mapping/lookahead_swap.py
def _calc_layout_distance(gates, coupling_map, layout, max_gates=None): """Return the sum of the distances of two-qubit pairs in each CNOT in gates according to the layout and the coupling. """ if max_gates is None: max_gates = 50 + 10 * len(coupling_map.physical_qubits) return sum(couplin...
def _calc_layout_distance(gates, coupling_map, layout, max_gates=None): """Return the sum of the distances of two-qubit pairs in each CNOT in gates according to the layout and the coupling. """ if max_gates is None: max_gates = 50 + 10 * len(coupling_map.physical_qubits) return sum(couplin...
[ "Return", "the", "sum", "of", "the", "distances", "of", "two", "-", "qubit", "pairs", "in", "each", "CNOT", "in", "gates", "according", "to", "the", "layout", "and", "the", "coupling", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/lookahead_swap.py#L239-L249
[ "def", "_calc_layout_distance", "(", "gates", ",", "coupling_map", ",", "layout", ",", "max_gates", "=", "None", ")", ":", "if", "max_gates", "is", "None", ":", "max_gates", "=", "50", "+", "10", "*", "len", "(", "coupling_map", ".", "physical_qubits", ")"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_score_step
Count the mapped two-qubit gates, less the number of added SWAPs.
qiskit/transpiler/passes/mapping/lookahead_swap.py
def _score_step(step): """Count the mapped two-qubit gates, less the number of added SWAPs.""" # Each added swap will add 3 ops to gates_mapped, so subtract 3. return len([g for g in step['gates_mapped'] if len(g.qargs) == 2]) - 3 * step['swaps_added']
def _score_step(step): """Count the mapped two-qubit gates, less the number of added SWAPs.""" # Each added swap will add 3 ops to gates_mapped, so subtract 3. return len([g for g in step['gates_mapped'] if len(g.qargs) == 2]) - 3 * step['swaps_added']
[ "Count", "the", "mapped", "two", "-", "qubit", "gates", "less", "the", "number", "of", "added", "SWAPs", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/lookahead_swap.py#L252-L257
[ "def", "_score_step", "(", "step", ")", ":", "# Each added swap will add 3 ops to gates_mapped, so subtract 3.", "return", "len", "(", "[", "g", "for", "g", "in", "step", "[", "'gates_mapped'", "]", "if", "len", "(", "g", ".", "qargs", ")", "==", "2", "]", "...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_copy_circuit_metadata
Return a copy of source_dag with metadata but empty. Generate only a single qreg in the output DAG, matching the size of the coupling_map.
qiskit/transpiler/passes/mapping/lookahead_swap.py
def _copy_circuit_metadata(source_dag, coupling_map): """Return a copy of source_dag with metadata but empty. Generate only a single qreg in the output DAG, matching the size of the coupling_map.""" target_dag = DAGCircuit() target_dag.name = source_dag.name for creg in source_dag.cregs.values...
def _copy_circuit_metadata(source_dag, coupling_map): """Return a copy of source_dag with metadata but empty. Generate only a single qreg in the output DAG, matching the size of the coupling_map.""" target_dag = DAGCircuit() target_dag.name = source_dag.name for creg in source_dag.cregs.values...
[ "Return", "a", "copy", "of", "source_dag", "with", "metadata", "but", "empty", ".", "Generate", "only", "a", "single", "qreg", "in", "the", "output", "DAG", "matching", "the", "size", "of", "the", "coupling_map", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/lookahead_swap.py#L260-L274
[ "def", "_copy_circuit_metadata", "(", "source_dag", ",", "coupling_map", ")", ":", "target_dag", "=", "DAGCircuit", "(", ")", "target_dag", ".", "name", "=", "source_dag", ".", "name", "for", "creg", "in", "source_dag", ".", "cregs", ".", "values", "(", ")",...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_transform_gate_for_layout
Return op implementing a virtual gate on given layout.
qiskit/transpiler/passes/mapping/lookahead_swap.py
def _transform_gate_for_layout(gate, layout): """Return op implementing a virtual gate on given layout.""" mapped_op_node = deepcopy([n for n in gate['graph'].nodes() if n.type == 'op'][0]) # Workaround until #1816, apply mapped to qargs to both DAGNode and op device_qreg = QuantumRegister(len(layout....
def _transform_gate_for_layout(gate, layout): """Return op implementing a virtual gate on given layout.""" mapped_op_node = deepcopy([n for n in gate['graph'].nodes() if n.type == 'op'][0]) # Workaround until #1816, apply mapped to qargs to both DAGNode and op device_qreg = QuantumRegister(len(layout....
[ "Return", "op", "implementing", "a", "virtual", "gate", "on", "given", "layout", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/lookahead_swap.py#L277-L289
[ "def", "_transform_gate_for_layout", "(", "gate", ",", "layout", ")", ":", "mapped_op_node", "=", "deepcopy", "(", "[", "n", "for", "n", "in", "gate", "[", "'graph'", "]", ".", "nodes", "(", ")", "if", "n", ".", "type", "==", "'op'", "]", "[", "0", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_swap_ops_from_edge
Generate list of ops to implement a SWAP gate along a coupling edge.
qiskit/transpiler/passes/mapping/lookahead_swap.py
def _swap_ops_from_edge(edge, layout): """Generate list of ops to implement a SWAP gate along a coupling edge.""" device_qreg = QuantumRegister(len(layout.get_physical_bits()), 'q') qreg_edge = [(device_qreg, i) for i in edge] # TODO shouldn't be making other nodes not by the DAG!! return [ ...
def _swap_ops_from_edge(edge, layout): """Generate list of ops to implement a SWAP gate along a coupling edge.""" device_qreg = QuantumRegister(len(layout.get_physical_bits()), 'q') qreg_edge = [(device_qreg, i) for i in edge] # TODO shouldn't be making other nodes not by the DAG!! return [ ...
[ "Generate", "list", "of", "ops", "to", "implement", "a", "SWAP", "gate", "along", "a", "coupling", "edge", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/lookahead_swap.py#L292-L301
[ "def", "_swap_ops_from_edge", "(", "edge", ",", "layout", ")", ":", "device_qreg", "=", "QuantumRegister", "(", "len", "(", "layout", ".", "get_physical_bits", "(", ")", ")", ",", "'q'", ")", "qreg_edge", "=", "[", "(", "device_qreg", ",", "i", ")", "for...
d4f58d903bc96341b816f7c35df936d6421267d1
test
LookaheadSwap.run
Run one pass of the lookahead mapper on the provided DAG. Args: dag (DAGCircuit): the directed acyclic graph to be mapped Returns: DAGCircuit: A dag mapped to be compatible with the coupling_map in the property_set. Raises: TranspilerError: if...
qiskit/transpiler/passes/mapping/lookahead_swap.py
def run(self, dag): """Run one pass of the lookahead mapper on the provided DAG. Args: dag (DAGCircuit): the directed acyclic graph to be mapped Returns: DAGCircuit: A dag mapped to be compatible with the coupling_map in the property_set. Raises: ...
def run(self, dag): """Run one pass of the lookahead mapper on the provided DAG. Args: dag (DAGCircuit): the directed acyclic graph to be mapped Returns: DAGCircuit: A dag mapped to be compatible with the coupling_map in the property_set. Raises: ...
[ "Run", "one", "pass", "of", "the", "lookahead", "mapper", "on", "the", "provided", "DAG", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/lookahead_swap.py#L75-L123
[ "def", "run", "(", "self", ",", "dag", ")", ":", "coupling_map", "=", "self", ".", "_coupling_map", "ordered_virtual_gates", "=", "list", "(", "dag", ".", "serial_layers", "(", ")", ")", "if", "self", ".", "initial_layout", "is", "None", ":", "if", "self...
d4f58d903bc96341b816f7c35df936d6421267d1
test
CouplingMap.add_physical_qubit
Add a physical qubit to the coupling graph as a node. physical_qubit (int): An integer representing a physical qubit. Raises: CouplingError: if trying to add duplicate qubit
qiskit/transpiler/coupling.py
def add_physical_qubit(self, physical_qubit): """Add a physical qubit to the coupling graph as a node. physical_qubit (int): An integer representing a physical qubit. Raises: CouplingError: if trying to add duplicate qubit """ if not isinstance(physical_qubit, int):...
def add_physical_qubit(self, physical_qubit): """Add a physical qubit to the coupling graph as a node. physical_qubit (int): An integer representing a physical qubit. Raises: CouplingError: if trying to add duplicate qubit """ if not isinstance(physical_qubit, int):...
[ "Add", "a", "physical", "qubit", "to", "the", "coupling", "graph", "as", "a", "node", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/coupling.py#L65-L80
[ "def", "add_physical_qubit", "(", "self", ",", "physical_qubit", ")", ":", "if", "not", "isinstance", "(", "physical_qubit", ",", "int", ")", ":", "raise", "CouplingError", "(", "\"Physical qubits should be integers.\"", ")", "if", "physical_qubit", "in", "self", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
CouplingMap.add_edge
Add directed edge to coupling graph. src (int): source physical qubit dst (int): destination physical qubit
qiskit/transpiler/coupling.py
def add_edge(self, src, dst): """ Add directed edge to coupling graph. src (int): source physical qubit dst (int): destination physical qubit """ if src not in self.physical_qubits: self.add_physical_qubit(src) if dst not in self.physical_qubits: ...
def add_edge(self, src, dst): """ Add directed edge to coupling graph. src (int): source physical qubit dst (int): destination physical qubit """ if src not in self.physical_qubits: self.add_physical_qubit(src) if dst not in self.physical_qubits: ...
[ "Add", "directed", "edge", "to", "coupling", "graph", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/coupling.py#L82-L94
[ "def", "add_edge", "(", "self", ",", "src", ",", "dst", ")", ":", "if", "src", "not", "in", "self", ".", "physical_qubits", ":", "self", ".", "add_physical_qubit", "(", "src", ")", "if", "dst", "not", "in", "self", ".", "physical_qubits", ":", "self", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
CouplingMap.subgraph
Return a CouplingMap object for a subgraph of self. nodelist (list): list of integer node labels
qiskit/transpiler/coupling.py
def subgraph(self, nodelist): """Return a CouplingMap object for a subgraph of self. nodelist (list): list of integer node labels """ subcoupling = CouplingMap() subcoupling.graph = self.graph.subgraph(nodelist) for node in nodelist: if node not in subcouplin...
def subgraph(self, nodelist): """Return a CouplingMap object for a subgraph of self. nodelist (list): list of integer node labels """ subcoupling = CouplingMap() subcoupling.graph = self.graph.subgraph(nodelist) for node in nodelist: if node not in subcouplin...
[ "Return", "a", "CouplingMap", "object", "for", "a", "subgraph", "of", "self", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/coupling.py#L96-L106
[ "def", "subgraph", "(", "self", ",", "nodelist", ")", ":", "subcoupling", "=", "CouplingMap", "(", ")", "subcoupling", ".", "graph", "=", "self", ".", "graph", ".", "subgraph", "(", "nodelist", ")", "for", "node", "in", "nodelist", ":", "if", "node", "...
d4f58d903bc96341b816f7c35df936d6421267d1
test
CouplingMap.physical_qubits
Returns a sorted list of physical_qubits
qiskit/transpiler/coupling.py
def physical_qubits(self): """Returns a sorted list of physical_qubits""" if self._qubit_list is None: self._qubit_list = sorted([pqubit for pqubit in self.graph.nodes]) return self._qubit_list
def physical_qubits(self): """Returns a sorted list of physical_qubits""" if self._qubit_list is None: self._qubit_list = sorted([pqubit for pqubit in self.graph.nodes]) return self._qubit_list
[ "Returns", "a", "sorted", "list", "of", "physical_qubits" ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/coupling.py#L109-L113
[ "def", "physical_qubits", "(", "self", ")", ":", "if", "self", ".", "_qubit_list", "is", "None", ":", "self", ".", "_qubit_list", "=", "sorted", "(", "[", "pqubit", "for", "pqubit", "in", "self", ".", "graph", ".", "nodes", "]", ")", "return", "self", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
CouplingMap.is_connected
Test if the graph is connected. Return True if connected, False otherwise
qiskit/transpiler/coupling.py
def is_connected(self): """ Test if the graph is connected. Return True if connected, False otherwise """ try: return nx.is_weakly_connected(self.graph) except nx.exception.NetworkXException: return False
def is_connected(self): """ Test if the graph is connected. Return True if connected, False otherwise """ try: return nx.is_weakly_connected(self.graph) except nx.exception.NetworkXException: return False
[ "Test", "if", "the", "graph", "is", "connected", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/coupling.py#L115-L124
[ "def", "is_connected", "(", "self", ")", ":", "try", ":", "return", "nx", ".", "is_weakly_connected", "(", "self", ".", "graph", ")", "except", "nx", ".", "exception", ".", "NetworkXException", ":", "return", "False" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
CouplingMap._compute_distance_matrix
Compute the full distance matrix on pairs of nodes. The distance map self._dist_matrix is computed from the graph using all_pairs_shortest_path_length.
qiskit/transpiler/coupling.py
def _compute_distance_matrix(self): """Compute the full distance matrix on pairs of nodes. The distance map self._dist_matrix is computed from the graph using all_pairs_shortest_path_length. """ if not self.is_connected(): raise CouplingError("coupling graph not conn...
def _compute_distance_matrix(self): """Compute the full distance matrix on pairs of nodes. The distance map self._dist_matrix is computed from the graph using all_pairs_shortest_path_length. """ if not self.is_connected(): raise CouplingError("coupling graph not conn...
[ "Compute", "the", "full", "distance", "matrix", "on", "pairs", "of", "nodes", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/coupling.py#L126-L141
[ "def", "_compute_distance_matrix", "(", "self", ")", ":", "if", "not", "self", ".", "is_connected", "(", ")", ":", "raise", "CouplingError", "(", "\"coupling graph not connected\"", ")", "lengths", "=", "nx", ".", "all_pairs_shortest_path_length", "(", "self", "."...
d4f58d903bc96341b816f7c35df936d6421267d1
test
CouplingMap.distance
Returns the undirected distance between physical_qubit1 and physical_qubit2. Args: physical_qubit1 (int): A physical qubit physical_qubit2 (int): Another physical qubit Returns: int: The undirected distance Raises: CouplingError: if the qubits d...
qiskit/transpiler/coupling.py
def distance(self, physical_qubit1, physical_qubit2): """Returns the undirected distance between physical_qubit1 and physical_qubit2. Args: physical_qubit1 (int): A physical qubit physical_qubit2 (int): Another physical qubit Returns: int: The undirected dis...
def distance(self, physical_qubit1, physical_qubit2): """Returns the undirected distance between physical_qubit1 and physical_qubit2. Args: physical_qubit1 (int): A physical qubit physical_qubit2 (int): Another physical qubit Returns: int: The undirected dis...
[ "Returns", "the", "undirected", "distance", "between", "physical_qubit1", "and", "physical_qubit2", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/coupling.py#L143-L162
[ "def", "distance", "(", "self", ",", "physical_qubit1", ",", "physical_qubit2", ")", ":", "if", "physical_qubit1", "not", "in", "self", ".", "physical_qubits", ":", "raise", "CouplingError", "(", "\"%s not in coupling graph\"", "%", "(", "physical_qubit1", ",", ")...
d4f58d903bc96341b816f7c35df936d6421267d1
test
transpile
transpile one or more circuits. Args: circuits (QuantumCircuit or list[QuantumCircuit]): circuits to compile backend (BaseBackend): a backend to compile for basis_gates (list[str]): list of basis gate names supported by the target. Default: ['u1','u2','u3','cx','id'] cou...
qiskit/transpiler/transpiler.py
def transpile(circuits, backend=None, basis_gates=None, coupling_map=None, initial_layout=None, seed_mapper=None, pass_manager=None): """transpile one or more circuits. Args: circuits (QuantumCircuit or list[QuantumCircuit]): circuits to compile backend (BaseBackend): a backend to...
def transpile(circuits, backend=None, basis_gates=None, coupling_map=None, initial_layout=None, seed_mapper=None, pass_manager=None): """transpile one or more circuits. Args: circuits (QuantumCircuit or list[QuantumCircuit]): circuits to compile backend (BaseBackend): a backend to...
[ "transpile", "one", "or", "more", "circuits", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/transpiler.py#L19-L50
[ "def", "transpile", "(", "circuits", ",", "backend", "=", "None", ",", "basis_gates", "=", "None", ",", "coupling_map", "=", "None", ",", "initial_layout", "=", "None", ",", "seed_mapper", "=", "None", ",", "pass_manager", "=", "None", ")", ":", "warnings"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
transpile_dag
Deprecated - Use qiskit.compiler.transpile for transpiling from circuits to circuits. Transform a dag circuit into another dag circuit (transpile), through consecutive passes on the dag. Args: dag (DAGCircuit): dag circuit to transform via transpilation basis_gates (list[str]): list of ...
qiskit/transpiler/transpiler.py
def transpile_dag(dag, basis_gates=None, coupling_map=None, initial_layout=None, seed_mapper=None, pass_manager=None): """Deprecated - Use qiskit.compiler.transpile for transpiling from circuits to circuits. Transform a dag circuit into another dag circuit (transpile), through consecut...
def transpile_dag(dag, basis_gates=None, coupling_map=None, initial_layout=None, seed_mapper=None, pass_manager=None): """Deprecated - Use qiskit.compiler.transpile for transpiling from circuits to circuits. Transform a dag circuit into another dag circuit (transpile), through consecut...
[ "Deprecated", "-", "Use", "qiskit", ".", "compiler", ".", "transpile", "for", "transpiling", "from", "circuits", "to", "circuits", ".", "Transform", "a", "dag", "circuit", "into", "another", "dag", "circuit", "(", "transpile", ")", "through", "consecutive", "p...
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/transpiler.py#L53-L110
[ "def", "transpile_dag", "(", "dag", ",", "basis_gates", "=", "None", ",", "coupling_map", "=", "None", ",", "initial_layout", "=", "None", ",", "seed_mapper", "=", "None", ",", "pass_manager", "=", "None", ")", ":", "warnings", ".", "warn", "(", "\"transpi...
d4f58d903bc96341b816f7c35df936d6421267d1
test
cu1
Apply cu1 from ctl to tgt with angle theta.
qiskit/extensions/standard/cu1.py
def cu1(self, theta, ctl, tgt): """Apply cu1 from ctl to tgt with angle theta.""" return self.append(Cu1Gate(theta), [ctl, tgt], [])
def cu1(self, theta, ctl, tgt): """Apply cu1 from ctl to tgt with angle theta.""" return self.append(Cu1Gate(theta), [ctl, tgt], [])
[ "Apply", "cu1", "from", "ctl", "to", "tgt", "with", "angle", "theta", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/standard/cu1.py#L55-L57
[ "def", "cu1", "(", "self", ",", "theta", ",", "ctl", ",", "tgt", ")", ":", "return", "self", ".", "append", "(", "Cu1Gate", "(", "theta", ")", ",", "[", "ctl", ",", "tgt", "]", ",", "[", "]", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
InstructionSet.add
Add an instruction and its context (where it's attached).
qiskit/circuit/instructionset.py
def add(self, gate, qargs, cargs): """Add an instruction and its context (where it's attached).""" if not isinstance(gate, Instruction): raise QiskitError("attempt to add non-Instruction" + " to InstructionSet") self.instructions.append(gate) sel...
def add(self, gate, qargs, cargs): """Add an instruction and its context (where it's attached).""" if not isinstance(gate, Instruction): raise QiskitError("attempt to add non-Instruction" + " to InstructionSet") self.instructions.append(gate) sel...
[ "Add", "an", "instruction", "and", "its", "context", "(", "where", "it", "s", "attached", ")", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/instructionset.py#L36-L43
[ "def", "add", "(", "self", ",", "gate", ",", "qargs", ",", "cargs", ")", ":", "if", "not", "isinstance", "(", "gate", ",", "Instruction", ")", ":", "raise", "QiskitError", "(", "\"attempt to add non-Instruction\"", "+", "\" to InstructionSet\"", ")", "self", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
InstructionSet.inverse
Invert all instructions.
qiskit/circuit/instructionset.py
def inverse(self): """Invert all instructions.""" for index, instruction in enumerate(self.instructions): self.instructions[index] = instruction.inverse() return self
def inverse(self): """Invert all instructions.""" for index, instruction in enumerate(self.instructions): self.instructions[index] = instruction.inverse() return self
[ "Invert", "all", "instructions", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/instructionset.py#L45-L49
[ "def", "inverse", "(", "self", ")", ":", "for", "index", ",", "instruction", "in", "enumerate", "(", "self", ".", "instructions", ")", ":", "self", ".", "instructions", "[", "index", "]", "=", "instruction", ".", "inverse", "(", ")", "return", "self" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
InstructionSet.q_if
Add controls to all instructions.
qiskit/circuit/instructionset.py
def q_if(self, *qregs): """Add controls to all instructions.""" for gate in self.instructions: gate.q_if(*qregs) return self
def q_if(self, *qregs): """Add controls to all instructions.""" for gate in self.instructions: gate.q_if(*qregs) return self
[ "Add", "controls", "to", "all", "instructions", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/instructionset.py#L51-L55
[ "def", "q_if", "(", "self", ",", "*", "qregs", ")", ":", "for", "gate", "in", "self", ".", "instructions", ":", "gate", ".", "q_if", "(", "*", "qregs", ")", "return", "self" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
InstructionSet.c_if
Add classical control register to all instructions.
qiskit/circuit/instructionset.py
def c_if(self, classical, val): """Add classical control register to all instructions.""" for gate in self.instructions: gate.c_if(classical, val) return self
def c_if(self, classical, val): """Add classical control register to all instructions.""" for gate in self.instructions: gate.c_if(classical, val) return self
[ "Add", "classical", "control", "register", "to", "all", "instructions", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/circuit/instructionset.py#L57-L61
[ "def", "c_if", "(", "self", ",", "classical", ",", "val", ")", ":", "for", "gate", "in", "self", ".", "instructions", ":", "gate", ".", "c_if", "(", "classical", ",", "val", ")", "return", "self" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
_Broker.subscribe
Subscribes to an event, so when it's emitted all the callbacks subscribed, will be executed. We are not allowing double registration. Args event (string): The event to subscribed in the form of: "terra.<component>.<method>.<action>" callback (callable...
qiskit/tools/events/pubsub.py
def subscribe(self, event, callback): """Subscribes to an event, so when it's emitted all the callbacks subscribed, will be executed. We are not allowing double registration. Args event (string): The event to subscribed in the form of: "terra.<component>....
def subscribe(self, event, callback): """Subscribes to an event, so when it's emitted all the callbacks subscribed, will be executed. We are not allowing double registration. Args event (string): The event to subscribed in the form of: "terra.<component>....
[ "Subscribes", "to", "an", "event", "so", "when", "it", "s", "emitted", "all", "the", "callbacks", "subscribed", "will", "be", "executed", ".", "We", "are", "not", "allowing", "double", "registration", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/tools/events/pubsub.py#L53-L75
[ "def", "subscribe", "(", "self", ",", "event", ",", "callback", ")", ":", "if", "not", "callable", "(", "callback", ")", ":", "raise", "QiskitError", "(", "\"Callback is not a callable!\"", ")", "if", "event", "not", "in", "self", ".", "_subscribers", ":", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_Broker.dispatch
Emits an event if there are any subscribers. Args event (String): The event to be emitted args: Arguments linked with the event kwargs: Named arguments linked with the event
qiskit/tools/events/pubsub.py
def dispatch(self, event, *args, **kwargs): """Emits an event if there are any subscribers. Args event (String): The event to be emitted args: Arguments linked with the event kwargs: Named arguments linked with the event """ # No event, no subscribers...
def dispatch(self, event, *args, **kwargs): """Emits an event if there are any subscribers. Args event (String): The event to be emitted args: Arguments linked with the event kwargs: Named arguments linked with the event """ # No event, no subscribers...
[ "Emits", "an", "event", "if", "there", "are", "any", "subscribers", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/tools/events/pubsub.py#L77-L90
[ "def", "dispatch", "(", "self", ",", "event", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# No event, no subscribers.", "if", "event", "not", "in", "self", ".", "_subscribers", ":", "return", "for", "subscriber", "in", "self", ".", "_subscribers"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_Broker.unsubscribe
Unsubscribe the specific callback to the event. Args event (String): The event to unsubscribe callback (callable): The callback that won't be executed anymore Returns True: if we have successfully unsubscribed to the event False: if there's no callback p...
qiskit/tools/events/pubsub.py
def unsubscribe(self, event, callback): """ Unsubscribe the specific callback to the event. Args event (String): The event to unsubscribe callback (callable): The callback that won't be executed anymore Returns True: if we have successfully unsubscribed to t...
def unsubscribe(self, event, callback): """ Unsubscribe the specific callback to the event. Args event (String): The event to unsubscribe callback (callable): The callback that won't be executed anymore Returns True: if we have successfully unsubscribed to t...
[ "Unsubscribe", "the", "specific", "callback", "to", "the", "event", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/tools/events/pubsub.py#L92-L109
[ "def", "unsubscribe", "(", "self", ",", "event", ",", "callback", ")", ":", "try", ":", "self", ".", "_subscribers", "[", "event", "]", ".", "remove", "(", "self", ".", "_Subscription", "(", "event", ",", "callback", ")", ")", "except", "KeyError", ":"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Publisher.publish
Triggers an event, and associates some data to it, so if there are any subscribers, their callback will be called synchronously.
qiskit/tools/events/pubsub.py
def publish(self, event, *args, **kwargs): """ Triggers an event, and associates some data to it, so if there are any subscribers, their callback will be called synchronously. """ return self._broker.dispatch(event, *args, **kwargs)
def publish(self, event, *args, **kwargs): """ Triggers an event, and associates some data to it, so if there are any subscribers, their callback will be called synchronously. """ return self._broker.dispatch(event, *args, **kwargs)
[ "Triggers", "an", "event", "and", "associates", "some", "data", "to", "it", "so", "if", "there", "are", "any", "subscribers", "their", "callback", "will", "be", "called", "synchronously", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/tools/events/pubsub.py#L125-L128
[ "def", "publish", "(", "self", ",", "event", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_broker", ".", "dispatch", "(", "event", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
initialize
Apply initialize to circuit.
qiskit/extensions/initializer.py
def initialize(self, params, qubits): """Apply initialize to circuit.""" if isinstance(qubits, QuantumRegister): qubits = qubits[:] else: qubits = _convert_to_bits([qubits], [qbit for qreg in self.qregs for qbit in qreg])[0] return self.append(Initialize(params), qubits)
def initialize(self, params, qubits): """Apply initialize to circuit.""" if isinstance(qubits, QuantumRegister): qubits = qubits[:] else: qubits = _convert_to_bits([qubits], [qbit for qreg in self.qregs for qbit in qreg])[0] return self.append(Initialize(params), qubits)
[ "Apply", "initialize", "to", "circuit", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/initializer.py#L236-L242
[ "def", "initialize", "(", "self", ",", "params", ",", "qubits", ")", ":", "if", "isinstance", "(", "qubits", ",", "QuantumRegister", ")", ":", "qubits", "=", "qubits", "[", ":", "]", "else", ":", "qubits", "=", "_convert_to_bits", "(", "[", "qubits", "...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Initialize._define
Calculate a subcircuit that implements this initialization Implements a recursive initialization algorithm, including optimizations, from "Synthesis of Quantum Logic Circuits" Shende, Bullock, Markov https://arxiv.org/abs/quant-ph/0406176v5 Additionally implements some extra optimizati...
qiskit/extensions/initializer.py
def _define(self): """Calculate a subcircuit that implements this initialization Implements a recursive initialization algorithm, including optimizations, from "Synthesis of Quantum Logic Circuits" Shende, Bullock, Markov https://arxiv.org/abs/quant-ph/0406176v5 Additionally im...
def _define(self): """Calculate a subcircuit that implements this initialization Implements a recursive initialization algorithm, including optimizations, from "Synthesis of Quantum Logic Circuits" Shende, Bullock, Markov https://arxiv.org/abs/quant-ph/0406176v5 Additionally im...
[ "Calculate", "a", "subcircuit", "that", "implements", "this", "initialization" ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/initializer.py#L57-L80
[ "def", "_define", "(", "self", ")", ":", "# call to generate the circuit that takes the desired vector to zero", "disentangling_circuit", "=", "self", ".", "gates_to_uncompute", "(", ")", "# invert the circuit to create the desired vector from zero (assuming", "# the qubits are in the ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Initialize.gates_to_uncompute
Call to create a circuit with gates that take the desired vector to zero. Returns: QuantumCircuit: circuit to take self.params vector to |00..0>
qiskit/extensions/initializer.py
def gates_to_uncompute(self): """ Call to create a circuit with gates that take the desired vector to zero. Returns: QuantumCircuit: circuit to take self.params vector to |00..0> """ q = QuantumRegister(self.num_qubits) circuit = QuantumCircuit(q, nam...
def gates_to_uncompute(self): """ Call to create a circuit with gates that take the desired vector to zero. Returns: QuantumCircuit: circuit to take self.params vector to |00..0> """ q = QuantumRegister(self.num_qubits) circuit = QuantumCircuit(q, nam...
[ "Call", "to", "create", "a", "circuit", "with", "gates", "that", "take", "the", "desired", "vector", "to", "zero", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/initializer.py#L82-L109
[ "def", "gates_to_uncompute", "(", "self", ")", ":", "q", "=", "QuantumRegister", "(", "self", ".", "num_qubits", ")", "circuit", "=", "QuantumCircuit", "(", "q", ",", "name", "=", "'disentangler'", ")", "# kick start the peeling loop, and disentangle one-by-one from L...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Initialize._rotations_to_disentangle
Static internal method to work out Ry and Rz rotation angles used to disentangle the LSB qubit. These rotations make up the block diagonal matrix U (i.e. multiplexor) that disentangles the LSB. [[Ry(theta_1).Rz(phi_1) 0 . . 0], [0 Ry(theta_2).Rz(phi_2) . 0], ...
qiskit/extensions/initializer.py
def _rotations_to_disentangle(local_param): """ Static internal method to work out Ry and Rz rotation angles used to disentangle the LSB qubit. These rotations make up the block diagonal matrix U (i.e. multiplexor) that disentangles the LSB. [[Ry(theta_1).Rz(phi_1) 0 ...
def _rotations_to_disentangle(local_param): """ Static internal method to work out Ry and Rz rotation angles used to disentangle the LSB qubit. These rotations make up the block diagonal matrix U (i.e. multiplexor) that disentangles the LSB. [[Ry(theta_1).Rz(phi_1) 0 ...
[ "Static", "internal", "method", "to", "work", "out", "Ry", "and", "Rz", "rotation", "angles", "used", "to", "disentangle", "the", "LSB", "qubit", ".", "These", "rotations", "make", "up", "the", "block", "diagonal", "matrix", "U", "(", "i", ".", "e", ".",...
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/initializer.py#L112-L148
[ "def", "_rotations_to_disentangle", "(", "local_param", ")", ":", "remaining_vector", "=", "[", "]", "thetas", "=", "[", "]", "phis", "=", "[", "]", "param_len", "=", "len", "(", "local_param", ")", "for", "i", "in", "range", "(", "param_len", "//", "2",...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Initialize._bloch_angles
Static internal method to work out rotation to create the passed in qubit from the zero vector.
qiskit/extensions/initializer.py
def _bloch_angles(pair_of_complex): """ Static internal method to work out rotation to create the passed in qubit from the zero vector. """ [a_complex, b_complex] = pair_of_complex # Force a and b to be complex, as otherwise numpy.angle might fail. a_complex = com...
def _bloch_angles(pair_of_complex): """ Static internal method to work out rotation to create the passed in qubit from the zero vector. """ [a_complex, b_complex] = pair_of_complex # Force a and b to be complex, as otherwise numpy.angle might fail. a_complex = com...
[ "Static", "internal", "method", "to", "work", "out", "rotation", "to", "create", "the", "passed", "in", "qubit", "from", "the", "zero", "vector", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/initializer.py#L151-L174
[ "def", "_bloch_angles", "(", "pair_of_complex", ")", ":", "[", "a_complex", ",", "b_complex", "]", "=", "pair_of_complex", "# Force a and b to be complex, as otherwise numpy.angle might fail.", "a_complex", "=", "complex", "(", "a_complex", ")", "b_complex", "=", "complex...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Initialize._multiplex
Return a recursive implementation of a multiplexor circuit, where each instruction itself has a decomposition based on smaller multiplexors. The LSB is the multiplexor "data" and the other bits are multiplexor "select". Args: target_gate (Gate): Ry or Rz gate to apply to ta...
qiskit/extensions/initializer.py
def _multiplex(self, target_gate, list_of_angles): """ Return a recursive implementation of a multiplexor circuit, where each instruction itself has a decomposition based on smaller multiplexors. The LSB is the multiplexor "data" and the other bits are multiplexor "select". ...
def _multiplex(self, target_gate, list_of_angles): """ Return a recursive implementation of a multiplexor circuit, where each instruction itself has a decomposition based on smaller multiplexors. The LSB is the multiplexor "data" and the other bits are multiplexor "select". ...
[ "Return", "a", "recursive", "implementation", "of", "a", "multiplexor", "circuit", "where", "each", "instruction", "itself", "has", "a", "decomposition", "based", "on", "smaller", "multiplexors", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/initializer.py#L176-L233
[ "def", "_multiplex", "(", "self", ",", "target_gate", ",", "list_of_angles", ")", ":", "list_len", "=", "len", "(", "list_of_angles", ")", "local_num_qubits", "=", "int", "(", "math", ".", "log2", "(", "list_len", ")", ")", "+", "1", "q", "=", "QuantumRe...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.from_dict
Populates a Layout from a dictionary. The dictionary must be a bijective mapping between virtual qubits (tuple) and physical qubits (int). Args: input_dict (dict): e.g.: {(QuantumRegister(3, 'qr'), 0): 0, (QuantumRegister(3, 'qr'), 1)...
qiskit/transpiler/layout.py
def from_dict(self, input_dict): """ Populates a Layout from a dictionary. The dictionary must be a bijective mapping between virtual qubits (tuple) and physical qubits (int). Args: input_dict (dict): e.g.: {(QuantumRegister(3, 'qr'), ...
def from_dict(self, input_dict): """ Populates a Layout from a dictionary. The dictionary must be a bijective mapping between virtual qubits (tuple) and physical qubits (int). Args: input_dict (dict): e.g.: {(QuantumRegister(3, 'qr'), ...
[ "Populates", "a", "Layout", "from", "a", "dictionary", ".", "The", "dictionary", "must", "be", "a", "bijective", "mapping", "between", "virtual", "qubits", "(", "tuple", ")", "and", "physical", "qubits", "(", "int", ")", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L44-L101
[ "def", "from_dict", "(", "self", ",", "input_dict", ")", ":", "# TODO (luciano): Remove this full block after 0.8.", "# its here to support {(\"qr\", 0): (\"q\", 0),...}", "if", "len", "(", "input_dict", ")", ">=", "1", ":", "key", "=", "list", "(", "input_dict", ".", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.order_based_on_type
decides which one is physical/virtual based on the type. Returns (virtual, physical)
qiskit/transpiler/layout.py
def order_based_on_type(value1, value2): """decides which one is physical/virtual based on the type. Returns (virtual, physical)""" if isinstance(value1, int) and Layout.is_virtual(value2): physical = value1 virtual = value2 elif isinstance(value2, int) and Layout.is_virt...
def order_based_on_type(value1, value2): """decides which one is physical/virtual based on the type. Returns (virtual, physical)""" if isinstance(value1, int) and Layout.is_virtual(value2): physical = value1 virtual = value2 elif isinstance(value2, int) and Layout.is_virt...
[ "decides", "which", "one", "is", "physical", "/", "virtual", "based", "on", "the", "type", ".", "Returns", "(", "virtual", "physical", ")" ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L104-L115
[ "def", "order_based_on_type", "(", "value1", ",", "value2", ")", ":", "if", "isinstance", "(", "value1", ",", "int", ")", "and", "Layout", ".", "is_virtual", "(", "value2", ")", ":", "physical", "=", "value1", "virtual", "=", "value2", "elif", "isinstance"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.is_virtual
Checks if value has the format of a virtual qubit
qiskit/transpiler/layout.py
def is_virtual(value): """Checks if value has the format of a virtual qubit """ return value is None or isinstance(value, tuple) and len(value) == 2 and isinstance( value[0], Register) and isinstance(value[1], int)
def is_virtual(value): """Checks if value has the format of a virtual qubit """ return value is None or isinstance(value, tuple) and len(value) == 2 and isinstance( value[0], Register) and isinstance(value[1], int)
[ "Checks", "if", "value", "has", "the", "format", "of", "a", "virtual", "qubit" ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L118-L121
[ "def", "is_virtual", "(", "value", ")", ":", "return", "value", "is", "None", "or", "isinstance", "(", "value", ",", "tuple", ")", "and", "len", "(", "value", ")", "==", "2", "and", "isinstance", "(", "value", "[", "0", "]", ",", "Register", ")", "...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.copy
Returns a copy of a Layout instance.
qiskit/transpiler/layout.py
def copy(self): """Returns a copy of a Layout instance.""" layout_copy = type(self)() layout_copy._p2v = self._p2v.copy() layout_copy._v2p = self._v2p.copy() return layout_copy
def copy(self): """Returns a copy of a Layout instance.""" layout_copy = type(self)() layout_copy._p2v = self._p2v.copy() layout_copy._v2p = self._v2p.copy() return layout_copy
[ "Returns", "a", "copy", "of", "a", "Layout", "instance", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L160-L167
[ "def", "copy", "(", "self", ")", ":", "layout_copy", "=", "type", "(", "self", ")", "(", ")", "layout_copy", ".", "_p2v", "=", "self", ".", "_p2v", ".", "copy", "(", ")", "layout_copy", ".", "_v2p", "=", "self", ".", "_v2p", ".", "copy", "(", ")"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.add
Adds a map element between `bit` and `physical_bit`. If `physical_bit` is not defined, `bit` will be mapped to a new physical bit (extending the length of the layout by one.) Args: virtual_bit (tuple): A (qu)bit. For example, (QuantumRegister(3, 'qr'), 2). physical_bit (i...
qiskit/transpiler/layout.py
def add(self, virtual_bit, physical_bit=None): """ Adds a map element between `bit` and `physical_bit`. If `physical_bit` is not defined, `bit` will be mapped to a new physical bit (extending the length of the layout by one.) Args: virtual_bit (tuple): A (qu)bit. For ...
def add(self, virtual_bit, physical_bit=None): """ Adds a map element between `bit` and `physical_bit`. If `physical_bit` is not defined, `bit` will be mapped to a new physical bit (extending the length of the layout by one.) Args: virtual_bit (tuple): A (qu)bit. For ...
[ "Adds", "a", "map", "element", "between", "bit", "and", "physical_bit", ".", "If", "physical_bit", "is", "not", "defined", "bit", "will", "be", "mapped", "to", "a", "new", "physical", "bit", "(", "extending", "the", "length", "of", "the", "layout", "by", ...
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L169-L183
[ "def", "add", "(", "self", ",", "virtual_bit", ",", "physical_bit", "=", "None", ")", ":", "if", "physical_bit", "is", "None", ":", "physical_candidate", "=", "len", "(", "self", ")", "while", "physical_candidate", "in", "self", ".", "_p2v", ":", "physical...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.swap
Swaps the map between left and right. Args: left (tuple or int): Item to swap with right. right (tuple or int): Item to swap with left. Raises: LayoutError: If left and right have not the same type.
qiskit/transpiler/layout.py
def swap(self, left, right): """Swaps the map between left and right. Args: left (tuple or int): Item to swap with right. right (tuple or int): Item to swap with left. Raises: LayoutError: If left and right have not the same type. """ if type(l...
def swap(self, left, right): """Swaps the map between left and right. Args: left (tuple or int): Item to swap with right. right (tuple or int): Item to swap with left. Raises: LayoutError: If left and right have not the same type. """ if type(l...
[ "Swaps", "the", "map", "between", "left", "and", "right", ".", "Args", ":", "left", "(", "tuple", "or", "int", ")", ":", "Item", "to", "swap", "with", "right", ".", "right", "(", "tuple", "or", "int", ")", ":", "Item", "to", "swap", "with", "left",...
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L216-L228
[ "def", "swap", "(", "self", ",", "left", ",", "right", ")", ":", "if", "type", "(", "left", ")", "is", "not", "type", "(", "right", ")", ":", "raise", "LayoutError", "(", "'The method swap only works with elements of the same type.'", ")", "temp", "=", "self...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.combine_into_edge_map
Combines self and another_layout into an "edge map". For example:: self another_layout resulting edge map qr_1 -> 0 0 <- q_2 qr_1 -> q_2 qr_2 -> 2 2 <- q_1 qr_2 -> q_1 qr_3 -> 3 3 <- q_0 qr_3 -> q_0 The...
qiskit/transpiler/layout.py
def combine_into_edge_map(self, another_layout): """Combines self and another_layout into an "edge map". For example:: self another_layout resulting edge map qr_1 -> 0 0 <- q_2 qr_1 -> q_2 qr_2 -> 2 2 <- q_1 qr_2 -> q_1 ...
def combine_into_edge_map(self, another_layout): """Combines self and another_layout into an "edge map". For example:: self another_layout resulting edge map qr_1 -> 0 0 <- q_2 qr_1 -> q_2 qr_2 -> 2 2 <- q_1 qr_2 -> q_1 ...
[ "Combines", "self", "and", "another_layout", "into", "an", "edge", "map", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L230-L257
[ "def", "combine_into_edge_map", "(", "self", ",", "another_layout", ")", ":", "edge_map", "=", "dict", "(", ")", "for", "virtual", ",", "physical", "in", "self", ".", "get_virtual_bits", "(", ")", ".", "items", "(", ")", ":", "if", "physical", "not", "in...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.generate_trivial_layout
Creates a trivial ("one-to-one") Layout with the registers in `regs`. Args: *regs (Registers): registers to include in the layout. Returns: Layout: A layout with all the `regs` in the given order.
qiskit/transpiler/layout.py
def generate_trivial_layout(*regs): """ Creates a trivial ("one-to-one") Layout with the registers in `regs`. Args: *regs (Registers): registers to include in the layout. Returns: Layout: A layout with all the `regs` in the given order. """ layout ...
def generate_trivial_layout(*regs): """ Creates a trivial ("one-to-one") Layout with the registers in `regs`. Args: *regs (Registers): registers to include in the layout. Returns: Layout: A layout with all the `regs` in the given order. """ layout ...
[ "Creates", "a", "trivial", "(", "one", "-", "to", "-", "one", ")", "Layout", "with", "the", "registers", "in", "regs", ".", "Args", ":", "*", "regs", "(", "Registers", ")", ":", "registers", "to", "include", "in", "the", "layout", ".", "Returns", ":"...
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L260-L271
[ "def", "generate_trivial_layout", "(", "*", "regs", ")", ":", "layout", "=", "Layout", "(", ")", "for", "reg", "in", "regs", ":", "layout", ".", "add_register", "(", "reg", ")", "return", "layout" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.from_intlist
Converts a list of integers to a Layout mapping virtual qubits (index of the list) to physical qubits (the list values). Args: int_list (list): A list of integers. *qregs (QuantumRegisters): The quantum registers to apply the layout to. Returns: ...
qiskit/transpiler/layout.py
def from_intlist(int_list, *qregs): """Converts a list of integers to a Layout mapping virtual qubits (index of the list) to physical qubits (the list values). Args: int_list (list): A list of integers. *qregs (QuantumRegisters): The quantum registers to apply ...
def from_intlist(int_list, *qregs): """Converts a list of integers to a Layout mapping virtual qubits (index of the list) to physical qubits (the list values). Args: int_list (list): A list of integers. *qregs (QuantumRegisters): The quantum registers to apply ...
[ "Converts", "a", "list", "of", "integers", "to", "a", "Layout", "mapping", "virtual", "qubits", "(", "index", "of", "the", "list", ")", "to", "physical", "qubits", "(", "the", "list", "values", ")", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L274-L306
[ "def", "from_intlist", "(", "int_list", ",", "*", "qregs", ")", ":", "if", "not", "all", "(", "(", "isinstance", "(", "i", ",", "int", ")", "for", "i", "in", "int_list", ")", ")", ":", "raise", "LayoutError", "(", "'Expected a list of ints'", ")", "if"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Layout.from_tuplelist
Populates a Layout from a list containing virtual qubits---(QuantumRegister, int) tuples---, or None. Args: tuple_list (list): e.g.: [qr[0], None, qr[2], qr[3]] Returns: Layout: the corresponding Layout object Raises: LayoutError: If t...
qiskit/transpiler/layout.py
def from_tuplelist(tuple_list): """ Populates a Layout from a list containing virtual qubits---(QuantumRegister, int) tuples---, or None. Args: tuple_list (list): e.g.: [qr[0], None, qr[2], qr[3]] Returns: Layout: the corresponding Layout ...
def from_tuplelist(tuple_list): """ Populates a Layout from a list containing virtual qubits---(QuantumRegister, int) tuples---, or None. Args: tuple_list (list): e.g.: [qr[0], None, qr[2], qr[3]] Returns: Layout: the corresponding Layout ...
[ "Populates", "a", "Layout", "from", "a", "list", "containing", "virtual", "qubits", "---", "(", "QuantumRegister", "int", ")", "tuples", "---", "or", "None", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/layout.py#L309-L333
[ "def", "from_tuplelist", "(", "tuple_list", ")", ":", "out", "=", "Layout", "(", ")", "for", "physical", ",", "virtual", "in", "enumerate", "(", "tuple_list", ")", ":", "if", "virtual", "is", "None", ":", "continue", "elif", "Layout", ".", "is_virtual", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
ccx
Apply Toffoli to from ctl1 and ctl2 to tgt.
qiskit/extensions/standard/ccx.py
def ccx(self, ctl1, ctl2, tgt): """Apply Toffoli to from ctl1 and ctl2 to tgt.""" return self.append(ToffoliGate(), [ctl1, ctl2, tgt], [])
def ccx(self, ctl1, ctl2, tgt): """Apply Toffoli to from ctl1 and ctl2 to tgt.""" return self.append(ToffoliGate(), [ctl1, ctl2, tgt], [])
[ "Apply", "Toffoli", "to", "from", "ctl1", "and", "ctl2", "to", "tgt", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/standard/ccx.py#L82-L84
[ "def", "ccx", "(", "self", ",", "ctl1", ",", "ctl2", ",", "tgt", ")", ":", "return", "self", ".", "append", "(", "ToffoliGate", "(", ")", ",", "[", "ctl1", ",", "ctl2", ",", "tgt", "]", ",", "[", "]", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
ToffoliGate._define
gate ccx a,b,c { h c; cx b,c; tdg c; cx a,c; t c; cx b,c; tdg c; cx a,c; t b; t c; h c; cx a,b; t a; tdg b; cx a,b;}
qiskit/extensions/standard/ccx.py
def _define(self): """ gate ccx a,b,c { h c; cx b,c; tdg c; cx a,c; t c; cx b,c; tdg c; cx a,c; t b; t c; h c; cx a,b; t a; tdg b; cx a,b;} """ definition = [] q = QuantumRegister(3, "q") rule = [ (HGate(), [q[2]], []), ...
def _define(self): """ gate ccx a,b,c { h c; cx b,c; tdg c; cx a,c; t c; cx b,c; tdg c; cx a,c; t b; t c; h c; cx a,b; t a; tdg b; cx a,b;} """ definition = [] q = QuantumRegister(3, "q") rule = [ (HGate(), [q[2]], []), ...
[ "gate", "ccx", "a", "b", "c", "{", "h", "c", ";", "cx", "b", "c", ";", "tdg", "c", ";", "cx", "a", "c", ";", "t", "c", ";", "cx", "b", "c", ";", "tdg", "c", ";", "cx", "a", "c", ";", "t", "b", ";", "t", "c", ";", "h", "c", ";", "c...
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/standard/ccx.py#L32-L62
[ "def", "_define", "(", "self", ")", ":", "definition", "=", "[", "]", "q", "=", "QuantumRegister", "(", "3", ",", "\"q\"", ")", "rule", "=", "[", "(", "HGate", "(", ")", ",", "[", "q", "[", "2", "]", "]", ",", "[", "]", ")", ",", "(", "Cnot...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Collect2qBlocks.run
collect blocks of adjacent gates acting on a pair of "cx" qubits. The blocks contain "op" nodes in topological sort order such that all gates in a block act on the same pair of qubits and are adjacent in the circuit. the blocks are built by examining predecessors and successors of "cx" ...
qiskit/transpiler/passes/collect_2q_blocks.py
def run(self, dag): """collect blocks of adjacent gates acting on a pair of "cx" qubits. The blocks contain "op" nodes in topological sort order such that all gates in a block act on the same pair of qubits and are adjacent in the circuit. the blocks are built by examining prede...
def run(self, dag): """collect blocks of adjacent gates acting on a pair of "cx" qubits. The blocks contain "op" nodes in topological sort order such that all gates in a block act on the same pair of qubits and are adjacent in the circuit. the blocks are built by examining prede...
[ "collect", "blocks", "of", "adjacent", "gates", "acting", "on", "a", "pair", "of", "cx", "qubits", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/collect_2q_blocks.py#L30-L189
[ "def", "run", "(", "self", ",", "dag", ")", ":", "# Initiate the commutation set", "self", ".", "property_set", "[", "'commutation_set'", "]", "=", "defaultdict", "(", "list", ")", "good_names", "=", "[", "\"cx\"", ",", "\"u1\"", ",", "\"u2\"", ",", "\"u3\""...
d4f58d903bc96341b816f7c35df936d6421267d1
test
u2
Apply u2 to q.
qiskit/extensions/standard/u2.py
def u2(self, phi, lam, q): """Apply u2 to q.""" return self.append(U2Gate(phi, lam), [q], [])
def u2(self, phi, lam, q): """Apply u2 to q.""" return self.append(U2Gate(phi, lam), [q], [])
[ "Apply", "u2", "to", "q", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/standard/u2.py#L59-L61
[ "def", "u2", "(", "self", ",", "phi", ",", "lam", ",", "q", ")", ":", "return", "self", ".", "append", "(", "U2Gate", "(", "phi", ",", "lam", ")", ",", "[", "q", "]", ",", "[", "]", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
U2Gate.to_matrix
Return a Numpy.array for the U3 gate.
qiskit/extensions/standard/u2.py
def to_matrix(self): """Return a Numpy.array for the U3 gate.""" isqrt2 = 1 / numpy.sqrt(2) phi, lam = self.params phi, lam = float(phi), float(lam) return numpy.array([[isqrt2, -numpy.exp(1j * lam) * isqrt2], [ numpy.ex...
def to_matrix(self): """Return a Numpy.array for the U3 gate.""" isqrt2 = 1 / numpy.sqrt(2) phi, lam = self.params phi, lam = float(phi), float(lam) return numpy.array([[isqrt2, -numpy.exp(1j * lam) * isqrt2], [ numpy.ex...
[ "Return", "a", "Numpy", ".", "array", "for", "the", "U3", "gate", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/extensions/standard/u2.py#L44-L54
[ "def", "to_matrix", "(", "self", ")", ":", "isqrt2", "=", "1", "/", "numpy", ".", "sqrt", "(", "2", ")", "phi", ",", "lam", "=", "self", ".", "params", "phi", ",", "lam", "=", "float", "(", "phi", ")", ",", "float", "(", "lam", ")", "return", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Instruction.insert
Return a new schedule with `schedule` inserted within `self` at `start_time`. Args: start_time: time to be inserted schedule: schedule to be inserted
qiskit/pulse/commands/instruction.py
def insert(self, start_time: int, schedule: ScheduleComponent) -> 'ScheduleComponent': """Return a new schedule with `schedule` inserted within `self` at `start_time`. Args: start_time: time to be inserted schedule: schedule to be inserted """ return ops.insert(s...
def insert(self, start_time: int, schedule: ScheduleComponent) -> 'ScheduleComponent': """Return a new schedule with `schedule` inserted within `self` at `start_time`. Args: start_time: time to be inserted schedule: schedule to be inserted """ return ops.insert(s...
[ "Return", "a", "new", "schedule", "with", "schedule", "inserted", "within", "self", "at", "start_time", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/pulse/commands/instruction.py#L154-L161
[ "def", "insert", "(", "self", ",", "start_time", ":", "int", ",", "schedule", ":", "ScheduleComponent", ")", "->", "'ScheduleComponent'", ":", "return", "ops", ".", "insert", "(", "self", ",", "start_time", ",", "schedule", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
FencedObject._check_if_fenced
Checks if the attribute name is in the list of attributes to protect. If so, raises TranspilerAccessError. Args: name (string): the attribute name to check Raises: TranspilerAccessError: when name is the list of attributes to protect.
qiskit/transpiler/fencedobjs.py
def _check_if_fenced(self, name): """ Checks if the attribute name is in the list of attributes to protect. If so, raises TranspilerAccessError. Args: name (string): the attribute name to check Raises: TranspilerAccessError: when name is the list of attr...
def _check_if_fenced(self, name): """ Checks if the attribute name is in the list of attributes to protect. If so, raises TranspilerAccessError. Args: name (string): the attribute name to check Raises: TranspilerAccessError: when name is the list of attr...
[ "Checks", "if", "the", "attribute", "name", "is", "in", "the", "list", "of", "attributes", "to", "protect", ".", "If", "so", "raises", "TranspilerAccessError", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/fencedobjs.py#L33-L46
[ "def", "_check_if_fenced", "(", "self", ",", "name", ")", ":", "if", "name", "in", "object", ".", "__getattribute__", "(", "self", ",", "'_attributes_to_fence'", ")", ":", "raise", "TranspilerAccessError", "(", "\"The fenced %s has the property %s protected\"", "%", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Stinespring.is_cptp
Return True if completely-positive trace-preserving.
qiskit/quantum_info/operators/channel/stinespring.py
def is_cptp(self, atol=None, rtol=None): """Return True if completely-positive trace-preserving.""" if atol is None: atol = self._atol if rtol is None: rtol = self._rtol if self._data[1] is not None: return False check = np.dot(np.transpose(np....
def is_cptp(self, atol=None, rtol=None): """Return True if completely-positive trace-preserving.""" if atol is None: atol = self._atol if rtol is None: rtol = self._rtol if self._data[1] is not None: return False check = np.dot(np.transpose(np....
[ "Return", "True", "if", "completely", "-", "positive", "trace", "-", "preserving", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/channel/stinespring.py#L143-L152
[ "def", "is_cptp", "(", "self", ",", "atol", "=", "None", ",", "rtol", "=", "None", ")", ":", "if", "atol", "is", "None", ":", "atol", "=", "self", ".", "_atol", "if", "rtol", "is", "None", ":", "rtol", "=", "self", ".", "_rtol", "if", "self", "...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Stinespring.conjugate
Return the conjugate of the QuantumChannel.
qiskit/quantum_info/operators/channel/stinespring.py
def conjugate(self): """Return the conjugate of the QuantumChannel.""" # pylint: disable=assignment-from-no-return stine_l = np.conjugate(self._data[0]) stine_r = None if self._data[1] is not None: stine_r = np.conjugate(self._data[1]) return Stinespring((stin...
def conjugate(self): """Return the conjugate of the QuantumChannel.""" # pylint: disable=assignment-from-no-return stine_l = np.conjugate(self._data[0]) stine_r = None if self._data[1] is not None: stine_r = np.conjugate(self._data[1]) return Stinespring((stin...
[ "Return", "the", "conjugate", "of", "the", "QuantumChannel", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/channel/stinespring.py#L154-L162
[ "def", "conjugate", "(", "self", ")", ":", "# pylint: disable=assignment-from-no-return", "stine_l", "=", "np", ".", "conjugate", "(", "self", ".", "_data", "[", "0", "]", ")", "stine_r", "=", "None", "if", "self", ".", "_data", "[", "1", "]", "is", "not...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Stinespring.transpose
Return the transpose of the QuantumChannel.
qiskit/quantum_info/operators/channel/stinespring.py
def transpose(self): """Return the transpose of the QuantumChannel.""" din, dout = self.dim dtr = self._data[0].shape[0] // dout stine = [None, None] for i, mat in enumerate(self._data): if mat is not None: stine[i] = np.reshape( np...
def transpose(self): """Return the transpose of the QuantumChannel.""" din, dout = self.dim dtr = self._data[0].shape[0] // dout stine = [None, None] for i, mat in enumerate(self._data): if mat is not None: stine[i] = np.reshape( np...
[ "Return", "the", "transpose", "of", "the", "QuantumChannel", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/channel/stinespring.py#L164-L177
[ "def", "transpose", "(", "self", ")", ":", "din", ",", "dout", "=", "self", ".", "dim", "dtr", "=", "self", ".", "_data", "[", "0", "]", ".", "shape", "[", "0", "]", "//", "dout", "stine", "=", "[", "None", ",", "None", "]", "for", "i", ",", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Stinespring.compose
Return the composition channel self∘other. Args: other (QuantumChannel): a quantum channel subclass. qargs (list): a list of subsystem positions to compose other on. front (bool): If False compose in standard order other(self(input)) otherwise compo...
qiskit/quantum_info/operators/channel/stinespring.py
def compose(self, other, qargs=None, front=False): """Return the composition channel self∘other. Args: other (QuantumChannel): a quantum channel subclass. qargs (list): a list of subsystem positions to compose other on. front (bool): If False compose in standard orde...
def compose(self, other, qargs=None, front=False): """Return the composition channel self∘other. Args: other (QuantumChannel): a quantum channel subclass. qargs (list): a list of subsystem positions to compose other on. front (bool): If False compose in standard orde...
[ "Return", "the", "composition", "channel", "self∘other", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/channel/stinespring.py#L179-L212
[ "def", "compose", "(", "self", ",", "other", ",", "qargs", "=", "None", ",", "front", "=", "False", ")", ":", "if", "qargs", "is", "not", "None", ":", "return", "Stinespring", "(", "SuperOp", "(", "self", ")", ".", "compose", "(", "other", ",", "qa...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Stinespring.power
The matrix power of the channel. Args: n (int): compute the matrix power of the superoperator matrix. Returns: Stinespring: the matrix power of the SuperOp converted to a Stinespring channel. Raises: QiskitError: if the input and output dimensio...
qiskit/quantum_info/operators/channel/stinespring.py
def power(self, n): """The matrix power of the channel. Args: n (int): compute the matrix power of the superoperator matrix. Returns: Stinespring: the matrix power of the SuperOp converted to a Stinespring channel. Raises: QiskitError: i...
def power(self, n): """The matrix power of the channel. Args: n (int): compute the matrix power of the superoperator matrix. Returns: Stinespring: the matrix power of the SuperOp converted to a Stinespring channel. Raises: QiskitError: i...
[ "The", "matrix", "power", "of", "the", "channel", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/channel/stinespring.py#L214-L230
[ "def", "power", "(", "self", ",", "n", ")", ":", "if", "n", ">", "0", ":", "return", "super", "(", ")", ".", "power", "(", "n", ")", "return", "Stinespring", "(", "SuperOp", "(", "self", ")", ".", "power", "(", "n", ")", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
Stinespring.multiply
Return the QuantumChannel self + other. Args: other (complex): a complex number. Returns: Stinespring: the scalar multiplication other * self as a Stinespring object. Raises: QiskitError: if other is not a valid scalar.
qiskit/quantum_info/operators/channel/stinespring.py
def multiply(self, other): """Return the QuantumChannel self + other. Args: other (complex): a complex number. Returns: Stinespring: the scalar multiplication other * self as a Stinespring object. Raises: QiskitError: if other is not a v...
def multiply(self, other): """Return the QuantumChannel self + other. Args: other (complex): a complex number. Returns: Stinespring: the scalar multiplication other * self as a Stinespring object. Raises: QiskitError: if other is not a v...
[ "Return", "the", "QuantumChannel", "self", "+", "other", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/channel/stinespring.py#L298-L328
[ "def", "multiply", "(", "self", ",", "other", ")", ":", "if", "not", "isinstance", "(", "other", ",", "Number", ")", ":", "raise", "QiskitError", "(", "\"other is not a number\"", ")", "# If the number is complex or negative we need to convert to", "# general Stinesprin...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Stinespring._evolve
Evolve a quantum state by the QuantumChannel. Args: state (QuantumState): The input statevector or density matrix. qargs (list): a list of QuantumState subsystem positions to apply the operator on. Returns: QuantumState: the output quantum...
qiskit/quantum_info/operators/channel/stinespring.py
def _evolve(self, state, qargs=None): """Evolve a quantum state by the QuantumChannel. Args: state (QuantumState): The input statevector or density matrix. qargs (list): a list of QuantumState subsystem positions to apply the operator on. Retu...
def _evolve(self, state, qargs=None): """Evolve a quantum state by the QuantumChannel. Args: state (QuantumState): The input statevector or density matrix. qargs (list): a list of QuantumState subsystem positions to apply the operator on. Retu...
[ "Evolve", "a", "quantum", "state", "by", "the", "QuantumChannel", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/channel/stinespring.py#L330-L369
[ "def", "_evolve", "(", "self", ",", "state", ",", "qargs", "=", "None", ")", ":", "# If subsystem evolution we use the SuperOp representation", "if", "qargs", "is", "not", "None", ":", "return", "SuperOp", "(", "self", ")", ".", "_evolve", "(", "state", ",", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Stinespring._tensor_product
Return the tensor product channel. Args: other (QuantumChannel): a quantum channel subclass. reverse (bool): If False return self ⊗ other, if True return if True return (other ⊗ self) [Default: False] Returns: Stinespring: the tensor produ...
qiskit/quantum_info/operators/channel/stinespring.py
def _tensor_product(self, other, reverse=False): """Return the tensor product channel. Args: other (QuantumChannel): a quantum channel subclass. reverse (bool): If False return self ⊗ other, if True return if True return (other ⊗ self) [Default: False...
def _tensor_product(self, other, reverse=False): """Return the tensor product channel. Args: other (QuantumChannel): a quantum channel subclass. reverse (bool): If False return self ⊗ other, if True return if True return (other ⊗ self) [Default: False...
[ "Return", "the", "tensor", "product", "channel", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/channel/stinespring.py#L371-L434
[ "def", "_tensor_product", "(", "self", ",", "other", ",", "reverse", "=", "False", ")", ":", "# Convert other to Stinespring", "if", "not", "isinstance", "(", "other", ",", "Stinespring", ")", ":", "other", "=", "Stinespring", "(", "other", ")", "# Tensor stin...
d4f58d903bc96341b816f7c35df936d6421267d1
test
BasicSwap.run
Runs the BasicSwap pass on `dag`. Args: dag (DAGCircuit): DAG to map. Returns: DAGCircuit: A mapped DAG. Raises: TranspilerError: if the coupling map or the layout are not compatible with the DAG
qiskit/transpiler/passes/mapping/basic_swap.py
def run(self, dag): """ Runs the BasicSwap pass on `dag`. Args: dag (DAGCircuit): DAG to map. Returns: DAGCircuit: A mapped DAG. Raises: TranspilerError: if the coupling map or the layout are not compatible with the DAG ""...
def run(self, dag): """ Runs the BasicSwap pass on `dag`. Args: dag (DAGCircuit): DAG to map. Returns: DAGCircuit: A mapped DAG. Raises: TranspilerError: if the coupling map or the layout are not compatible with the DAG ""...
[ "Runs", "the", "BasicSwap", "pass", "on", "dag", ".", "Args", ":", "dag", "(", "DAGCircuit", ")", ":", "DAG", "to", "map", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/basic_swap.py#L43-L112
[ "def", "run", "(", "self", ",", "dag", ")", ":", "new_dag", "=", "DAGCircuit", "(", ")", "if", "self", ".", "initial_layout", "is", "None", ":", "if", "self", ".", "property_set", "[", "\"layout\"", "]", ":", "self", ".", "initial_layout", "=", "self",...
d4f58d903bc96341b816f7c35df936d6421267d1
test
_layer_permutation
Find a swap circuit that implements a permutation for this layer. Args: layer_partition (list): The layer_partition is a list of (qu)bit lists and each qubit is a tuple (qreg, index). initial_layout (Layout): The initial layout passed. layout (Layout): The layout is a Layout obj...
qiskit/transpiler/passes/mapping/stochastic_swap.py
def _layer_permutation(layer_partition, initial_layout, layout, qubit_subset, coupling, trials, qregs, rng): """Find a swap circuit that implements a permutation for this layer. Args: layer_partition (list): The layer_partition is a list of (qu)bit lists and each qubi...
def _layer_permutation(layer_partition, initial_layout, layout, qubit_subset, coupling, trials, qregs, rng): """Find a swap circuit that implements a permutation for this layer. Args: layer_partition (list): The layer_partition is a list of (qu)bit lists and each qubi...
[ "Find", "a", "swap", "circuit", "that", "implements", "a", "permutation", "for", "this", "layer", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/stochastic_swap.py#L390-L509
[ "def", "_layer_permutation", "(", "layer_partition", ",", "initial_layout", ",", "layout", ",", "qubit_subset", ",", "coupling", ",", "trials", ",", "qregs", ",", "rng", ")", ":", "logger", ".", "debug", "(", "\"layer_permutation: layer_partition = %s\"", ",", "pf...
d4f58d903bc96341b816f7c35df936d6421267d1
test
regtuple_to_numeric
Takes (QuantumRegister, int) tuples and converts them into an integer array. Args: items (list): List of tuples of (QuantumRegister, int) to convert. qregs (dict): List of )QuantumRegister, int) tuples. Returns: ndarray: Array of integers.
qiskit/transpiler/passes/mapping/stochastic_swap.py
def regtuple_to_numeric(items, qregs): """Takes (QuantumRegister, int) tuples and converts them into an integer array. Args: items (list): List of tuples of (QuantumRegister, int) to convert. qregs (dict): List of )QuantumRegister, int) tuples. Returns: nda...
def regtuple_to_numeric(items, qregs): """Takes (QuantumRegister, int) tuples and converts them into an integer array. Args: items (list): List of tuples of (QuantumRegister, int) to convert. qregs (dict): List of )QuantumRegister, int) tuples. Returns: nda...
[ "Takes", "(", "QuantumRegister", "int", ")", "tuples", "and", "converts", "them", "into", "an", "integer", "array", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/stochastic_swap.py#L512-L532
[ "def", "regtuple_to_numeric", "(", "items", ",", "qregs", ")", ":", "sizes", "=", "[", "qr", ".", "size", "for", "qr", "in", "qregs", ".", "values", "(", ")", "]", "reg_idx", "=", "np", ".", "cumsum", "(", "[", "0", "]", "+", "sizes", ")", "regin...
d4f58d903bc96341b816f7c35df936d6421267d1
test
gates_to_idx
Converts gate tuples into a nested list of integers. Args: gates (list): List of (QuantumRegister, int) pairs representing gates. qregs (dict): List of )QuantumRegister, int) tuples. Returns: list: Nested list of integers for gates.
qiskit/transpiler/passes/mapping/stochastic_swap.py
def gates_to_idx(gates, qregs): """Converts gate tuples into a nested list of integers. Args: gates (list): List of (QuantumRegister, int) pairs representing gates. qregs (dict): List of )QuantumRegister, int) tuples. Returns: list: Nested list of integers for...
def gates_to_idx(gates, qregs): """Converts gate tuples into a nested list of integers. Args: gates (list): List of (QuantumRegister, int) pairs representing gates. qregs (dict): List of )QuantumRegister, int) tuples. Returns: list: Nested list of integers for...
[ "Converts", "gate", "tuples", "into", "a", "nested", "list", "of", "integers", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/stochastic_swap.py#L535-L555
[ "def", "gates_to_idx", "(", "gates", ",", "qregs", ")", ":", "sizes", "=", "[", "qr", ".", "size", "for", "qr", "in", "qregs", ".", "values", "(", ")", "]", "reg_idx", "=", "np", ".", "cumsum", "(", "[", "0", "]", "+", "sizes", ")", "regint", "...
d4f58d903bc96341b816f7c35df936d6421267d1
test
StochasticSwap.run
Run the StochasticSwap pass on `dag`. Args: dag (DAGCircuit): DAG to map. Returns: DAGCircuit: A mapped DAG. Raises: TranspilerError: if the coupling map or the layout are not compatible with the DAG
qiskit/transpiler/passes/mapping/stochastic_swap.py
def run(self, dag): """ Run the StochasticSwap pass on `dag`. Args: dag (DAGCircuit): DAG to map. Returns: DAGCircuit: A mapped DAG. Raises: TranspilerError: if the coupling map or the layout are not compatible with the DAG ...
def run(self, dag): """ Run the StochasticSwap pass on `dag`. Args: dag (DAGCircuit): DAG to map. Returns: DAGCircuit: A mapped DAG. Raises: TranspilerError: if the coupling map or the layout are not compatible with the DAG ...
[ "Run", "the", "StochasticSwap", "pass", "on", "dag", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/stochastic_swap.py#L82-L120
[ "def", "run", "(", "self", ",", "dag", ")", ":", "if", "self", ".", "initial_layout", "is", "None", ":", "if", "self", ".", "property_set", "[", "\"layout\"", "]", ":", "self", ".", "initial_layout", "=", "self", ".", "property_set", "[", "\"layout\"", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
StochasticSwap._layer_permutation
Find a swap circuit that implements a permutation for this layer. The goal is to swap qubits such that qubits in the same two-qubit gates are adjacent. Based on S. Bravyi's algorithm. layer_partition (list): The layer_partition is a list of (qu)bit lists and each qubit is ...
qiskit/transpiler/passes/mapping/stochastic_swap.py
def _layer_permutation(self, layer_partition, layout, qubit_subset, coupling, trials): """Find a swap circuit that implements a permutation for this layer. The goal is to swap qubits such that qubits in the same two-qubit gates are adjacent. Based on S. Bravy...
def _layer_permutation(self, layer_partition, layout, qubit_subset, coupling, trials): """Find a swap circuit that implements a permutation for this layer. The goal is to swap qubits such that qubits in the same two-qubit gates are adjacent. Based on S. Bravy...
[ "Find", "a", "swap", "circuit", "that", "implements", "a", "permutation", "for", "this", "layer", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/stochastic_swap.py#L122-L159
[ "def", "_layer_permutation", "(", "self", ",", "layer_partition", ",", "layout", ",", "qubit_subset", ",", "coupling", ",", "trials", ")", ":", "return", "_layer_permutation", "(", "layer_partition", ",", "self", ".", "initial_layout", ",", "layout", ",", "qubit...
d4f58d903bc96341b816f7c35df936d6421267d1
test
StochasticSwap._layer_update
Provide a DAGCircuit for a new mapped layer. i (int) = layer number first_layer (bool) = True if this is the first layer in the circuit with any multi-qubit gates best_layout (Layout) = layout returned from _layer_permutation best_depth (int) = depth returned from _layer_per...
qiskit/transpiler/passes/mapping/stochastic_swap.py
def _layer_update(self, i, first_layer, best_layout, best_depth, best_circuit, layer_list): """Provide a DAGCircuit for a new mapped layer. i (int) = layer number first_layer (bool) = True if this is the first layer in the circuit with any multi-qubit gates ...
def _layer_update(self, i, first_layer, best_layout, best_depth, best_circuit, layer_list): """Provide a DAGCircuit for a new mapped layer. i (int) = layer number first_layer (bool) = True if this is the first layer in the circuit with any multi-qubit gates ...
[ "Provide", "a", "DAGCircuit", "for", "a", "new", "mapped", "layer", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/stochastic_swap.py#L161-L214
[ "def", "_layer_update", "(", "self", ",", "i", ",", "first_layer", ",", "best_layout", ",", "best_depth", ",", "best_circuit", ",", "layer_list", ")", ":", "layout", "=", "best_layout", "logger", ".", "debug", "(", "\"layer_update: layout = %s\"", ",", "pformat"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
StochasticSwap._mapper
Map a DAGCircuit onto a CouplingMap using swap gates. Use self.initial_layout for the initial layout. Args: circuit_graph (DAGCircuit): input DAG circuit coupling_graph (CouplingMap): coupling graph to map onto trials (int): number of trials. Returns: ...
qiskit/transpiler/passes/mapping/stochastic_swap.py
def _mapper(self, circuit_graph, coupling_graph, trials=20): """Map a DAGCircuit onto a CouplingMap using swap gates. Use self.initial_layout for the initial layout. Args: circuit_graph (DAGCircuit): input DAG circuit coupling_graph (CouplingMap): coupli...
def _mapper(self, circuit_graph, coupling_graph, trials=20): """Map a DAGCircuit onto a CouplingMap using swap gates. Use self.initial_layout for the initial layout. Args: circuit_graph (DAGCircuit): input DAG circuit coupling_graph (CouplingMap): coupli...
[ "Map", "a", "DAGCircuit", "onto", "a", "CouplingMap", "using", "swap", "gates", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/transpiler/passes/mapping/stochastic_swap.py#L216-L387
[ "def", "_mapper", "(", "self", ",", "circuit_graph", ",", "coupling_graph", ",", "trials", "=", "20", ")", ":", "# Schedule the input circuit by calling layers()", "layerlist", "=", "list", "(", "circuit_graph", ".", "layers", "(", ")", ")", "logger", ".", "debu...
d4f58d903bc96341b816f7c35df936d6421267d1
test
pauli_group
Return the Pauli group with 4^n elements. The phases have been removed. case 'weight' is ordered by Pauli weights and case 'tensor' is ordered by I,X,Y,Z counting lowest qubit fastest. Args: number_of_qubits (int): number of qubits case (str): determines ordering of group elements ('we...
qiskit/quantum_info/operators/pauli.py
def pauli_group(number_of_qubits, case='weight'): """Return the Pauli group with 4^n elements. The phases have been removed. case 'weight' is ordered by Pauli weights and case 'tensor' is ordered by I,X,Y,Z counting lowest qubit fastest. Args: number_of_qubits (int): number of qubits ...
def pauli_group(number_of_qubits, case='weight'): """Return the Pauli group with 4^n elements. The phases have been removed. case 'weight' is ordered by Pauli weights and case 'tensor' is ordered by I,X,Y,Z counting lowest qubit fastest. Args: number_of_qubits (int): number of qubits ...
[ "Return", "the", "Pauli", "group", "with", "4^n", "elements", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L517-L566
[ "def", "pauli_group", "(", "number_of_qubits", ",", "case", "=", "'weight'", ")", ":", "if", "number_of_qubits", "<", "5", ":", "temp_set", "=", "[", "]", "if", "case", "==", "'weight'", ":", "tmp", "=", "pauli_group", "(", "number_of_qubits", ",", "case",...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.from_label
r"""Take pauli string to construct pauli. The qubit index of pauli label is q_{n-1} ... q_0. E.g., a pauli is $P_{n-1} \otimes ... \otimes P_0$ Args: label (str): pauli label Returns: Pauli: the constructed pauli Raises: QiskitError: invali...
qiskit/quantum_info/operators/pauli.py
def from_label(cls, label): r"""Take pauli string to construct pauli. The qubit index of pauli label is q_{n-1} ... q_0. E.g., a pauli is $P_{n-1} \otimes ... \otimes P_0$ Args: label (str): pauli label Returns: Pauli: the constructed pauli Rai...
def from_label(cls, label): r"""Take pauli string to construct pauli. The qubit index of pauli label is q_{n-1} ... q_0. E.g., a pauli is $P_{n-1} \otimes ... \otimes P_0$ Args: label (str): pauli label Returns: Pauli: the constructed pauli Rai...
[ "r", "Take", "pauli", "string", "to", "construct", "pauli", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L82-L110
[ "def", "from_label", "(", "cls", ",", "label", ")", ":", "z", "=", "np", ".", "zeros", "(", "len", "(", "label", ")", ",", "dtype", "=", "np", ".", "bool", ")", "x", "=", "np", ".", "zeros", "(", "len", "(", "label", ")", ",", "dtype", "=", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli._init_from_bool
Construct pauli from boolean array. Args: z (numpy.ndarray): boolean, z vector x (numpy.ndarray): boolean, x vector Returns: Pauli: self Raises: QiskitError: if z or x are None or the length of z and x are different.
qiskit/quantum_info/operators/pauli.py
def _init_from_bool(self, z, x): """Construct pauli from boolean array. Args: z (numpy.ndarray): boolean, z vector x (numpy.ndarray): boolean, x vector Returns: Pauli: self Raises: QiskitError: if z or x are None or the length of z and x...
def _init_from_bool(self, z, x): """Construct pauli from boolean array. Args: z (numpy.ndarray): boolean, z vector x (numpy.ndarray): boolean, x vector Returns: Pauli: self Raises: QiskitError: if z or x are None or the length of z and x...
[ "Construct", "pauli", "from", "boolean", "array", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L112-L138
[ "def", "_init_from_bool", "(", "self", ",", "z", ",", "x", ")", ":", "if", "z", "is", "None", ":", "raise", "QiskitError", "(", "\"z vector must not be None.\"", ")", "if", "x", "is", "None", ":", "raise", "QiskitError", "(", "\"x vector must not be None.\"", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.sgn_prod
r""" Multiply two Paulis and track the phase. $P_3 = P_1 \otimes P_2$: X*Y Args: p1 (Pauli): pauli 1 p2 (Pauli): pauli 2 Returns: Pauli: the multiplied pauli complex: the sign of the multiplication, 1, -1, 1j or -1j
qiskit/quantum_info/operators/pauli.py
def sgn_prod(p1, p2): r""" Multiply two Paulis and track the phase. $P_3 = P_1 \otimes P_2$: X*Y Args: p1 (Pauli): pauli 1 p2 (Pauli): pauli 2 Returns: Pauli: the multiplied pauli complex: the sign of the multiplication, 1, -1, 1...
def sgn_prod(p1, p2): r""" Multiply two Paulis and track the phase. $P_3 = P_1 \otimes P_2$: X*Y Args: p1 (Pauli): pauli 1 p2 (Pauli): pauli 2 Returns: Pauli: the multiplied pauli complex: the sign of the multiplication, 1, -1, 1...
[ "r", "Multiply", "two", "Paulis", "and", "track", "the", "phase", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L228-L244
[ "def", "sgn_prod", "(", "p1", ",", "p2", ")", ":", "phase", "=", "Pauli", ".", "_prod_phase", "(", "p1", ",", "p2", ")", "new_pauli", "=", "p1", "*", "p2", "return", "new_pauli", ",", "phase" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.to_spmatrix
r""" Convert Pauli to a sparse matrix representation (CSR format). Order is q_{n-1} .... q_0, i.e., $P_{n-1} \otimes ... P_0$ Returns: scipy.sparse.csr_matrix: a sparse matrix with CSR format that represnets the pauli.
qiskit/quantum_info/operators/pauli.py
def to_spmatrix(self): r""" Convert Pauli to a sparse matrix representation (CSR format). Order is q_{n-1} .... q_0, i.e., $P_{n-1} \otimes ... P_0$ Returns: scipy.sparse.csr_matrix: a sparse matrix with CSR format that represnets the pauli. """ ...
def to_spmatrix(self): r""" Convert Pauli to a sparse matrix representation (CSR format). Order is q_{n-1} .... q_0, i.e., $P_{n-1} \otimes ... P_0$ Returns: scipy.sparse.csr_matrix: a sparse matrix with CSR format that represnets the pauli. """ ...
[ "r", "Convert", "Pauli", "to", "a", "sparse", "matrix", "representation", "(", "CSR", "format", ")", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L273-L295
[ "def", "to_spmatrix", "(", "self", ")", ":", "mat", "=", "sparse", ".", "coo_matrix", "(", "1", ")", "for", "z", ",", "x", "in", "zip", "(", "self", ".", "_z", ",", "self", ".", "_x", ")", ":", "if", "not", "z", "and", "not", "x", ":", "# I",...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.to_operator
Convert to Operator object.
qiskit/quantum_info/operators/pauli.py
def to_operator(self): """Convert to Operator object.""" # Place import here to avoid cyclic import from circuit visualization from qiskit.quantum_info.operators.operator import Operator return Operator(self.to_matrix())
def to_operator(self): """Convert to Operator object.""" # Place import here to avoid cyclic import from circuit visualization from qiskit.quantum_info.operators.operator import Operator return Operator(self.to_matrix())
[ "Convert", "to", "Operator", "object", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L297-L301
[ "def", "to_operator", "(", "self", ")", ":", "# Place import here to avoid cyclic import from circuit visualization", "from", "qiskit", ".", "quantum_info", ".", "operators", ".", "operator", "import", "Operator", "return", "Operator", "(", "self", ".", "to_matrix", "("...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.to_instruction
Convert to Pauli circuit instruction.
qiskit/quantum_info/operators/pauli.py
def to_instruction(self): """Convert to Pauli circuit instruction.""" from qiskit.circuit import QuantumCircuit, QuantumRegister from qiskit.extensions.standard import IdGate, XGate, YGate, ZGate gates = {'I': IdGate(), 'X': XGate(), 'Y': YGate(), 'Z': ZGate()} label = self.to_la...
def to_instruction(self): """Convert to Pauli circuit instruction.""" from qiskit.circuit import QuantumCircuit, QuantumRegister from qiskit.extensions.standard import IdGate, XGate, YGate, ZGate gates = {'I': IdGate(), 'X': XGate(), 'Y': YGate(), 'Z': ZGate()} label = self.to_la...
[ "Convert", "to", "Pauli", "circuit", "instruction", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L303-L314
[ "def", "to_instruction", "(", "self", ")", ":", "from", "qiskit", ".", "circuit", "import", "QuantumCircuit", ",", "QuantumRegister", "from", "qiskit", ".", "extensions", ".", "standard", "import", "IdGate", ",", "XGate", ",", "YGate", ",", "ZGate", "gates", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.update_z
Update partial or entire z. Args: z (numpy.ndarray or list): to-be-updated z indices (numpy.ndarray or list or optional): to-be-updated qubit indices Returns: Pauli: self Raises: QiskitError: when updating whole z, the number of qubits must be t...
qiskit/quantum_info/operators/pauli.py
def update_z(self, z, indices=None): """ Update partial or entire z. Args: z (numpy.ndarray or list): to-be-updated z indices (numpy.ndarray or list or optional): to-be-updated qubit indices Returns: Pauli: self Raises: QiskitErr...
def update_z(self, z, indices=None): """ Update partial or entire z. Args: z (numpy.ndarray or list): to-be-updated z indices (numpy.ndarray or list or optional): to-be-updated qubit indices Returns: Pauli: self Raises: QiskitErr...
[ "Update", "partial", "or", "entire", "z", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L316-L342
[ "def", "update_z", "(", "self", ",", "z", ",", "indices", "=", "None", ")", ":", "z", "=", "_make_np_bool", "(", "z", ")", "if", "indices", "is", "None", ":", "if", "len", "(", "self", ".", "_z", ")", "!=", "len", "(", "z", ")", ":", "raise", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.update_x
Update partial or entire x. Args: x (numpy.ndarray or list): to-be-updated x indices (numpy.ndarray or list or optional): to-be-updated qubit indices Returns: Pauli: self Raises: QiskitError: when updating whole x, the number of qubits must be t...
qiskit/quantum_info/operators/pauli.py
def update_x(self, x, indices=None): """ Update partial or entire x. Args: x (numpy.ndarray or list): to-be-updated x indices (numpy.ndarray or list or optional): to-be-updated qubit indices Returns: Pauli: self Raises: QiskitErr...
def update_x(self, x, indices=None): """ Update partial or entire x. Args: x (numpy.ndarray or list): to-be-updated x indices (numpy.ndarray or list or optional): to-be-updated qubit indices Returns: Pauli: self Raises: QiskitErr...
[ "Update", "partial", "or", "entire", "x", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L344-L370
[ "def", "update_x", "(", "self", ",", "x", ",", "indices", "=", "None", ")", ":", "x", "=", "_make_np_bool", "(", "x", ")", "if", "indices", "is", "None", ":", "if", "len", "(", "self", ".", "_x", ")", "!=", "len", "(", "x", ")", ":", "raise", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.insert_paulis
Insert or append pauli to the targeted indices. If indices is None, it means append at the end. Args: indices (list[int]): the qubit indices to be inserted paulis (Pauli): the to-be-inserted or appended pauli pauli_labels (list[str]): the to-be-inserted or appended ...
qiskit/quantum_info/operators/pauli.py
def insert_paulis(self, indices=None, paulis=None, pauli_labels=None): """ Insert or append pauli to the targeted indices. If indices is None, it means append at the end. Args: indices (list[int]): the qubit indices to be inserted paulis (Pauli): the to-be-inser...
def insert_paulis(self, indices=None, paulis=None, pauli_labels=None): """ Insert or append pauli to the targeted indices. If indices is None, it means append at the end. Args: indices (list[int]): the qubit indices to be inserted paulis (Pauli): the to-be-inser...
[ "Insert", "or", "append", "pauli", "to", "the", "targeted", "indices", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L372-L412
[ "def", "insert_paulis", "(", "self", ",", "indices", "=", "None", ",", "paulis", "=", "None", ",", "pauli_labels", "=", "None", ")", ":", "if", "pauli_labels", "is", "not", "None", ":", "if", "paulis", "is", "not", "None", ":", "raise", "QiskitError", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.append_paulis
Append pauli at the end. Args: paulis (Pauli): the to-be-inserted or appended pauli pauli_labels (list[str]): the to-be-inserted or appended pauli label Returns: Pauli: self
qiskit/quantum_info/operators/pauli.py
def append_paulis(self, paulis=None, pauli_labels=None): """ Append pauli at the end. Args: paulis (Pauli): the to-be-inserted or appended pauli pauli_labels (list[str]): the to-be-inserted or appended pauli label Returns: Pauli: self """ ...
def append_paulis(self, paulis=None, pauli_labels=None): """ Append pauli at the end. Args: paulis (Pauli): the to-be-inserted or appended pauli pauli_labels (list[str]): the to-be-inserted or appended pauli label Returns: Pauli: self """ ...
[ "Append", "pauli", "at", "the", "end", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L414-L425
[ "def", "append_paulis", "(", "self", ",", "paulis", "=", "None", ",", "pauli_labels", "=", "None", ")", ":", "return", "self", ".", "insert_paulis", "(", "None", ",", "paulis", "=", "paulis", ",", "pauli_labels", "=", "pauli_labels", ")" ]
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.delete_qubits
Delete pauli at the indices. Args: indices(list[int]): the indices of to-be-deleted paulis Returns: Pauli: self
qiskit/quantum_info/operators/pauli.py
def delete_qubits(self, indices): """ Delete pauli at the indices. Args: indices(list[int]): the indices of to-be-deleted paulis Returns: Pauli: self """ if not isinstance(indices, list): indices = [indices] self._z = np.dele...
def delete_qubits(self, indices): """ Delete pauli at the indices. Args: indices(list[int]): the indices of to-be-deleted paulis Returns: Pauli: self """ if not isinstance(indices, list): indices = [indices] self._z = np.dele...
[ "Delete", "pauli", "at", "the", "indices", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L427-L443
[ "def", "delete_qubits", "(", "self", ",", "indices", ")", ":", "if", "not", "isinstance", "(", "indices", ",", "list", ")", ":", "indices", "=", "[", "indices", "]", "self", ".", "_z", "=", "np", ".", "delete", "(", "self", ".", "_z", ",", "indices...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.random
Return a random Pauli on number of qubits. Args: num_qubits (int): the number of qubits seed (int): Optional. To set a random seed. Returns: Pauli: the random pauli
qiskit/quantum_info/operators/pauli.py
def random(cls, num_qubits, seed=None): """Return a random Pauli on number of qubits. Args: num_qubits (int): the number of qubits seed (int): Optional. To set a random seed. Returns: Pauli: the random pauli """ if seed is not None: ...
def random(cls, num_qubits, seed=None): """Return a random Pauli on number of qubits. Args: num_qubits (int): the number of qubits seed (int): Optional. To set a random seed. Returns: Pauli: the random pauli """ if seed is not None: ...
[ "Return", "a", "random", "Pauli", "on", "number", "of", "qubits", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L446-L459
[ "def", "random", "(", "cls", ",", "num_qubits", ",", "seed", "=", "None", ")", ":", "if", "seed", "is", "not", "None", ":", "np", ".", "random", ".", "seed", "(", "seed", ")", "z", "=", "np", ".", "random", ".", "randint", "(", "2", ",", "size"...
d4f58d903bc96341b816f7c35df936d6421267d1
test
Pauli.pauli_single
Generate single qubit pauli at index with pauli_label with length num_qubits. Args: num_qubits (int): the length of pauli index (int): the qubit index to insert the single qubii pauli_label (str): pauli Returns: Pauli: single qubit pauli
qiskit/quantum_info/operators/pauli.py
def pauli_single(cls, num_qubits, index, pauli_label): """ Generate single qubit pauli at index with pauli_label with length num_qubits. Args: num_qubits (int): the length of pauli index (int): the qubit index to insert the single qubii pauli_label (str): pau...
def pauli_single(cls, num_qubits, index, pauli_label): """ Generate single qubit pauli at index with pauli_label with length num_qubits. Args: num_qubits (int): the length of pauli index (int): the qubit index to insert the single qubii pauli_label (str): pau...
[ "Generate", "single", "qubit", "pauli", "at", "index", "with", "pauli_label", "with", "length", "num_qubits", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/quantum_info/operators/pauli.py#L462-L481
[ "def", "pauli_single", "(", "cls", ",", "num_qubits", ",", "index", ",", "pauli_label", ")", ":", "tmp", "=", "Pauli", ".", "from_label", "(", "pauli_label", ")", "z", "=", "np", ".", "zeros", "(", "num_qubits", ",", "dtype", "=", "np", ".", "bool", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QasmSimulatorPy._add_unitary_single
Apply an arbitrary 1-qubit unitary matrix. Args: gate (matrix_like): a single qubit gate matrix qubit (int): the qubit to apply gate to
qiskit/providers/basicaer/qasm_simulator.py
def _add_unitary_single(self, gate, qubit): """Apply an arbitrary 1-qubit unitary matrix. Args: gate (matrix_like): a single qubit gate matrix qubit (int): the qubit to apply gate to """ # Compute einsum index string for 1-qubit matrix multiplication inde...
def _add_unitary_single(self, gate, qubit): """Apply an arbitrary 1-qubit unitary matrix. Args: gate (matrix_like): a single qubit gate matrix qubit (int): the qubit to apply gate to """ # Compute einsum index string for 1-qubit matrix multiplication inde...
[ "Apply", "an", "arbitrary", "1", "-", "qubit", "unitary", "matrix", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/providers/basicaer/qasm_simulator.py#L130-L145
[ "def", "_add_unitary_single", "(", "self", ",", "gate", ",", "qubit", ")", ":", "# Compute einsum index string for 1-qubit matrix multiplication", "indexes", "=", "einsum_vecmul_index", "(", "[", "qubit", "]", ",", "self", ".", "_number_of_qubits", ")", "# Convert to co...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QasmSimulatorPy._add_unitary_two
Apply a two-qubit unitary matrix. Args: gate (matrix_like): a the two-qubit gate matrix qubit0 (int): gate qubit-0 qubit1 (int): gate qubit-1
qiskit/providers/basicaer/qasm_simulator.py
def _add_unitary_two(self, gate, qubit0, qubit1): """Apply a two-qubit unitary matrix. Args: gate (matrix_like): a the two-qubit gate matrix qubit0 (int): gate qubit-0 qubit1 (int): gate qubit-1 """ # Compute einsum index string for 1-qubit matrix mul...
def _add_unitary_two(self, gate, qubit0, qubit1): """Apply a two-qubit unitary matrix. Args: gate (matrix_like): a the two-qubit gate matrix qubit0 (int): gate qubit-0 qubit1 (int): gate qubit-1 """ # Compute einsum index string for 1-qubit matrix mul...
[ "Apply", "a", "two", "-", "qubit", "unitary", "matrix", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/providers/basicaer/qasm_simulator.py#L147-L163
[ "def", "_add_unitary_two", "(", "self", ",", "gate", ",", "qubit0", ",", "qubit1", ")", ":", "# Compute einsum index string for 1-qubit matrix multiplication", "indexes", "=", "einsum_vecmul_index", "(", "[", "qubit0", ",", "qubit1", "]", ",", "self", ".", "_number_...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QasmSimulatorPy._get_measure_outcome
Simulate the outcome of measurement of a qubit. Args: qubit (int): the qubit to measure Return: tuple: pair (outcome, probability) where outcome is '0' or '1' and probability is the probability of the returned outcome.
qiskit/providers/basicaer/qasm_simulator.py
def _get_measure_outcome(self, qubit): """Simulate the outcome of measurement of a qubit. Args: qubit (int): the qubit to measure Return: tuple: pair (outcome, probability) where outcome is '0' or '1' and probability is the probability of the returned outcom...
def _get_measure_outcome(self, qubit): """Simulate the outcome of measurement of a qubit. Args: qubit (int): the qubit to measure Return: tuple: pair (outcome, probability) where outcome is '0' or '1' and probability is the probability of the returned outcom...
[ "Simulate", "the", "outcome", "of", "measurement", "of", "a", "qubit", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/providers/basicaer/qasm_simulator.py#L165-L184
[ "def", "_get_measure_outcome", "(", "self", ",", "qubit", ")", ":", "# Axis for numpy.sum to compute probabilities", "axis", "=", "list", "(", "range", "(", "self", ".", "_number_of_qubits", ")", ")", "axis", ".", "remove", "(", "self", ".", "_number_of_qubits", ...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QasmSimulatorPy._add_sample_measure
Generate memory samples from current statevector. Args: measure_params (list): List of (qubit, cmembit) values for measure instructions to sample. num_samples (int): The number of memory samples to generate. Returns: list: A list o...
qiskit/providers/basicaer/qasm_simulator.py
def _add_sample_measure(self, measure_params, num_samples): """Generate memory samples from current statevector. Args: measure_params (list): List of (qubit, cmembit) values for measure instructions to sample. num_samples (int): The number of m...
def _add_sample_measure(self, measure_params, num_samples): """Generate memory samples from current statevector. Args: measure_params (list): List of (qubit, cmembit) values for measure instructions to sample. num_samples (int): The number of m...
[ "Generate", "memory", "samples", "from", "current", "statevector", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/providers/basicaer/qasm_simulator.py#L186-L222
[ "def", "_add_sample_measure", "(", "self", ",", "measure_params", ",", "num_samples", ")", ":", "# Get unique qubits that are actually measured", "measured_qubits", "=", "list", "(", "{", "qubit", "for", "qubit", ",", "cmembit", "in", "measure_params", "}", ")", "nu...
d4f58d903bc96341b816f7c35df936d6421267d1
test
QasmSimulatorPy._add_qasm_measure
Apply a measure instruction to a qubit. Args: qubit (int): qubit is the qubit measured. cmembit (int): is the classical memory bit to store outcome in. cregbit (int, optional): is the classical register bit to store outcome in.
qiskit/providers/basicaer/qasm_simulator.py
def _add_qasm_measure(self, qubit, cmembit, cregbit=None): """Apply a measure instruction to a qubit. Args: qubit (int): qubit is the qubit measured. cmembit (int): is the classical memory bit to store outcome in. cregbit (int, optional): is the classical register bi...
def _add_qasm_measure(self, qubit, cmembit, cregbit=None): """Apply a measure instruction to a qubit. Args: qubit (int): qubit is the qubit measured. cmembit (int): is the classical memory bit to store outcome in. cregbit (int, optional): is the classical register bi...
[ "Apply", "a", "measure", "instruction", "to", "a", "qubit", "." ]
Qiskit/qiskit-terra
python
https://github.com/Qiskit/qiskit-terra/blob/d4f58d903bc96341b816f7c35df936d6421267d1/qiskit/providers/basicaer/qasm_simulator.py#L224-L249
[ "def", "_add_qasm_measure", "(", "self", ",", "qubit", ",", "cmembit", ",", "cregbit", "=", "None", ")", ":", "# get measure outcome", "outcome", ",", "probability", "=", "self", ".", "_get_measure_outcome", "(", "qubit", ")", "# update classical state", "membit",...
d4f58d903bc96341b816f7c35df936d6421267d1