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
train
phase_flip
r""" Returns a PhaseFlipChannel that flips a qubit's phase with probability p if p is None, return a guaranteed phase flip in the form of a Z operation. This channel evolves a density matrix via: $$ \rho \rightarrow M_0 \rho M_0^\dagger + M_1 \rho M_1^\dagger $$ With: ...
cirq/ops/common_channels.py
def phase_flip( p: Optional[float] = None ) -> Union[common_gates.ZPowGate, PhaseFlipChannel]: r""" Returns a PhaseFlipChannel that flips a qubit's phase with probability p if p is None, return a guaranteed phase flip in the form of a Z operation. This channel evolves a density matrix via: ...
def phase_flip( p: Optional[float] = None ) -> Union[common_gates.ZPowGate, PhaseFlipChannel]: r""" Returns a PhaseFlipChannel that flips a qubit's phase with probability p if p is None, return a guaranteed phase flip in the form of a Z operation. This channel evolves a density matrix via: ...
[ "r", "Returns", "a", "PhaseFlipChannel", "that", "flips", "a", "qubit", "s", "phase", "with", "probability", "p", "if", "p", "is", "None", "return", "a", "guaranteed", "phase", "flip", "in", "the", "form", "of", "a", "Z", "operation", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/common_channels.py#L652-L690
[ "def", "phase_flip", "(", "p", ":", "Optional", "[", "float", "]", "=", "None", ")", "->", "Union", "[", "common_gates", ".", "ZPowGate", ",", "PhaseFlipChannel", "]", ":", "if", "p", "is", "None", ":", "return", "_phase_flip_Z", "(", ")", "return", "_...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
bit_flip
r""" Construct a BitFlipChannel that flips a qubit state with probability of a flip given by p. If p is None, return a guaranteed flip in the form of an X operation. This channel evolves a density matrix via $$ \rho \rightarrow M_0 \rho M_0^\dagger + M_1 \rho M_1^\dagger $$ ...
cirq/ops/common_channels.py
def bit_flip( p: Optional[float] = None ) -> Union[common_gates.XPowGate, BitFlipChannel]: r""" Construct a BitFlipChannel that flips a qubit state with probability of a flip given by p. If p is None, return a guaranteed flip in the form of an X operation. This channel evolves a density matrix ...
def bit_flip( p: Optional[float] = None ) -> Union[common_gates.XPowGate, BitFlipChannel]: r""" Construct a BitFlipChannel that flips a qubit state with probability of a flip given by p. If p is None, return a guaranteed flip in the form of an X operation. This channel evolves a density matrix ...
[ "r", "Construct", "a", "BitFlipChannel", "that", "flips", "a", "qubit", "state", "with", "probability", "of", "a", "flip", "given", "by", "p", ".", "If", "p", "is", "None", "return", "a", "guaranteed", "flip", "in", "the", "form", "of", "an", "X", "ope...
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/common_channels.py#L792-L831
[ "def", "bit_flip", "(", "p", ":", "Optional", "[", "float", "]", "=", "None", ")", "->", "Union", "[", "common_gates", ".", "XPowGate", ",", "BitFlipChannel", "]", ":", "if", "p", "is", "None", ":", "return", "pauli_gates", ".", "X", "return", "_bit_fl...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Schedule.query
Finds operations by time and qubit. Args: time: Operations must end after this time to be returned. duration: Operations must start by time+duration to be returned. qubits: If specified, only operations touching one of the included qubits will...
cirq/schedules/schedule.py
def query( self, *, # Forces keyword args. time: Timestamp, duration: Union[Duration, timedelta] = Duration(), qubits: Iterable[Qid] = None, include_query_end_time=False, include_op_end_times=False) -> List[ScheduledOperation]: ...
def query( self, *, # Forces keyword args. time: Timestamp, duration: Union[Duration, timedelta] = Duration(), qubits: Iterable[Qid] = None, include_query_end_time=False, include_op_end_times=False) -> List[ScheduledOperation]: ...
[ "Finds", "operations", "by", "time", "and", "qubit", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/schedules/schedule.py#L75-L120
[ "def", "query", "(", "self", ",", "*", ",", "# Forces keyword args.", "time", ":", "Timestamp", ",", "duration", ":", "Union", "[", "Duration", ",", "timedelta", "]", "=", "Duration", "(", ")", ",", "qubits", ":", "Iterable", "[", "Qid", "]", "=", "Non...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Schedule.operations_happening_at_same_time_as
Finds operations happening at the same time as the given operation. Args: scheduled_operation: The operation specifying the time to query. Returns: Scheduled operations that overlap with the given operation.
cirq/schedules/schedule.py
def operations_happening_at_same_time_as( self, scheduled_operation: ScheduledOperation ) -> List[ScheduledOperation]: """Finds operations happening at the same time as the given operation. Args: scheduled_operation: The operation specifying the time to query. Returns: ...
def operations_happening_at_same_time_as( self, scheduled_operation: ScheduledOperation ) -> List[ScheduledOperation]: """Finds operations happening at the same time as the given operation. Args: scheduled_operation: The operation specifying the time to query. Returns: ...
[ "Finds", "operations", "happening", "at", "the", "same", "time", "as", "the", "given", "operation", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/schedules/schedule.py#L140-L154
[ "def", "operations_happening_at_same_time_as", "(", "self", ",", "scheduled_operation", ":", "ScheduledOperation", ")", "->", "List", "[", "ScheduledOperation", "]", ":", "overlaps", "=", "self", ".", "query", "(", "time", "=", "scheduled_operation", ".", "time", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Schedule.include
Adds a scheduled operation to the schedule. Args: scheduled_operation: The operation to add. Raises: ValueError: The operation collided with something already in the schedule.
cirq/schedules/schedule.py
def include(self, scheduled_operation: ScheduledOperation): """Adds a scheduled operation to the schedule. Args: scheduled_operation: The operation to add. Raises: ValueError: The operation collided with something already in the schedule. """ ...
def include(self, scheduled_operation: ScheduledOperation): """Adds a scheduled operation to the schedule. Args: scheduled_operation: The operation to add. Raises: ValueError: The operation collided with something already in the schedule. """ ...
[ "Adds", "a", "scheduled", "operation", "to", "the", "schedule", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/schedules/schedule.py#L156-L174
[ "def", "include", "(", "self", ",", "scheduled_operation", ":", "ScheduledOperation", ")", ":", "collisions", "=", "self", ".", "query", "(", "time", "=", "scheduled_operation", ".", "time", ",", "duration", "=", "scheduled_operation", ".", "duration", ",", "q...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Schedule.exclude
Omits a scheduled operation from the schedule, if present. Args: scheduled_operation: The operation to try to remove. Returns: True if the operation was present and is now removed, False if it was already not present.
cirq/schedules/schedule.py
def exclude(self, scheduled_operation: ScheduledOperation) -> bool: """Omits a scheduled operation from the schedule, if present. Args: scheduled_operation: The operation to try to remove. Returns: True if the operation was present and is now removed, False if it ...
def exclude(self, scheduled_operation: ScheduledOperation) -> bool: """Omits a scheduled operation from the schedule, if present. Args: scheduled_operation: The operation to try to remove. Returns: True if the operation was present and is now removed, False if it ...
[ "Omits", "a", "scheduled", "operation", "from", "the", "schedule", "if", "present", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/schedules/schedule.py#L176-L190
[ "def", "exclude", "(", "self", ",", "scheduled_operation", ":", "ScheduledOperation", ")", "->", "bool", ":", "try", ":", "self", ".", "scheduled_operations", ".", "remove", "(", "scheduled_operation", ")", "return", "True", "except", "ValueError", ":", "return"...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Schedule.to_circuit
Convert the schedule to a circuit. This discards most timing information from the schedule, but does place operations that are scheduled at the same time in the same Moment.
cirq/schedules/schedule.py
def to_circuit(self) -> Circuit: """Convert the schedule to a circuit. This discards most timing information from the schedule, but does place operations that are scheduled at the same time in the same Moment. """ circuit = Circuit(device=self.device) time = None # type...
def to_circuit(self) -> Circuit: """Convert the schedule to a circuit. This discards most timing information from the schedule, but does place operations that are scheduled at the same time in the same Moment. """ circuit = Circuit(device=self.device) time = None # type...
[ "Convert", "the", "schedule", "to", "a", "circuit", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/schedules/schedule.py#L192-L208
[ "def", "to_circuit", "(", "self", ")", "->", "Circuit", ":", "circuit", "=", "Circuit", "(", "device", "=", "self", ".", "device", ")", "time", "=", "None", "# type: Optional[Timestamp]", "for", "so", "in", "self", ".", "scheduled_operations", ":", "if", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
acquaint_insides
Acquaints each of the qubits with another set specified by an acquaintance gate. Args: qubits: The list of qubits of which half are individually acquainted with another list of qubits. layers: The layers to put gates into. acquaintance_gate: The acquaintance gate that acquai...
cirq/contrib/acquaintance/gates.py
def acquaint_insides(swap_gate: ops.Gate, acquaintance_gate: ops.Operation, qubits: Sequence[ops.Qid], before: bool, layers: Layers, mapping: Dict[ops.Qid, int] ) -> None: """Acquaints each ...
def acquaint_insides(swap_gate: ops.Gate, acquaintance_gate: ops.Operation, qubits: Sequence[ops.Qid], before: bool, layers: Layers, mapping: Dict[ops.Qid, int] ) -> None: """Acquaints each ...
[ "Acquaints", "each", "of", "the", "qubits", "with", "another", "set", "specified", "by", "an", "acquaintance", "gate", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/acquaintance/gates.py#L84-L128
[ "def", "acquaint_insides", "(", "swap_gate", ":", "ops", ".", "Gate", ",", "acquaintance_gate", ":", "ops", ".", "Operation", ",", "qubits", ":", "Sequence", "[", "ops", ".", "Qid", "]", ",", "before", ":", "bool", ",", "layers", ":", "Layers", ",", "m...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
acquaint_and_shift
Acquaints and shifts a pair of lists of qubits. The first part is acquainted with every qubit individually in the second part, and vice versa. Operations are grouped into several layers: * prior_interstitial: The first layer of acquaintance gates. * prior: The combination of acquaintance gates a...
cirq/contrib/acquaintance/gates.py
def acquaint_and_shift(parts: Tuple[List[ops.Qid], List[ops.Qid]], layers: Layers, acquaintance_size: Optional[int], swap_gate: ops.Gate, mapping: Dict[ops.Qid, int]): """Acquaints and shifts a pair of lists of qubits. The f...
def acquaint_and_shift(parts: Tuple[List[ops.Qid], List[ops.Qid]], layers: Layers, acquaintance_size: Optional[int], swap_gate: ops.Gate, mapping: Dict[ops.Qid, int]): """Acquaints and shifts a pair of lists of qubits. The f...
[ "Acquaints", "and", "shifts", "a", "pair", "of", "lists", "of", "qubits", ".", "The", "first", "part", "is", "acquainted", "with", "every", "qubit", "individually", "in", "the", "second", "part", "and", "vice", "versa", ".", "Operations", "are", "grouped", ...
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/acquaintance/gates.py#L136-L234
[ "def", "acquaint_and_shift", "(", "parts", ":", "Tuple", "[", "List", "[", "ops", ".", "Qid", "]", ",", "List", "[", "ops", ".", "Qid", "]", "]", ",", "layers", ":", "Layers", ",", "acquaintance_size", ":", "Optional", "[", "int", "]", ",", "swap_gat...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
circuit_to_pdf_using_qcircuit_via_tex
Compiles the QCircuit-based latex diagram of the given circuit. Args: circuit: The circuit to produce a pdf of. filepath: Where to output the pdf. pdf_kwargs: The arguments to pass to generate_pdf. qcircuit_kwargs: The arguments to pass to circuit_to_latex_using_qcircuit...
cirq/contrib/qcircuit/qcircuit_pdf.py
def circuit_to_pdf_using_qcircuit_via_tex(circuit: circuits.Circuit, filepath: str, pdf_kwargs=None, qcircuit_kwargs=None, clean_ext=('dvi', 'ps'), ...
def circuit_to_pdf_using_qcircuit_via_tex(circuit: circuits.Circuit, filepath: str, pdf_kwargs=None, qcircuit_kwargs=None, clean_ext=('dvi', 'ps'), ...
[ "Compiles", "the", "QCircuit", "-", "based", "latex", "diagram", "of", "the", "given", "circuit", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/qcircuit/qcircuit_pdf.py#L27-L60
[ "def", "circuit_to_pdf_using_qcircuit_via_tex", "(", "circuit", ":", "circuits", ".", "Circuit", ",", "filepath", ":", "str", ",", "pdf_kwargs", "=", "None", ",", "qcircuit_kwargs", "=", "None", ",", "clean_ext", "=", "(", "'dvi'", ",", "'ps'", ")", ",", "do...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
deconstruct_single_qubit_matrix_into_angles
Breaks down a 2x2 unitary into more useful ZYZ angle parameters. Args: mat: The 2x2 unitary matrix to break down. Returns: A tuple containing the amount to phase around Z, then rotate around Y, then phase around Z (all in radians).
cirq/linalg/decompositions.py
def deconstruct_single_qubit_matrix_into_angles( mat: np.ndarray) -> Tuple[float, float, float]: """Breaks down a 2x2 unitary into more useful ZYZ angle parameters. Args: mat: The 2x2 unitary matrix to break down. Returns: A tuple containing the amount to phase around Z, then rotat...
def deconstruct_single_qubit_matrix_into_angles( mat: np.ndarray) -> Tuple[float, float, float]: """Breaks down a 2x2 unitary into more useful ZYZ angle parameters. Args: mat: The 2x2 unitary matrix to break down. Returns: A tuple containing the amount to phase around Z, then rotat...
[ "Breaks", "down", "a", "2x2", "unitary", "into", "more", "useful", "ZYZ", "angle", "parameters", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/decompositions.py#L47-L74
[ "def", "deconstruct_single_qubit_matrix_into_angles", "(", "mat", ":", "np", ".", "ndarray", ")", "->", "Tuple", "[", "float", ",", "float", ",", "float", "]", ":", "# Anti-cancel left-vs-right phase along top row.", "right_phase", "=", "cmath", ".", "phase", "(", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_group_similar
Combines similar items into groups. Args: items: The list of items to group. comparer: Determines if two items are similar. Returns: A list of groups of items.
cirq/linalg/decompositions.py
def _group_similar(items: List[T], comparer: Callable[[T, T], bool]) -> List[List[T]]: """Combines similar items into groups. Args: items: The list of items to group. comparer: Determines if two items are similar. Returns: A list of groups of items. """ groups = [] # type...
def _group_similar(items: List[T], comparer: Callable[[T, T], bool]) -> List[List[T]]: """Combines similar items into groups. Args: items: The list of items to group. comparer: Determines if two items are similar. Returns: A list of groups of items. """ groups = [] # type...
[ "Combines", "similar", "items", "into", "groups", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/decompositions.py#L77-L98
[ "def", "_group_similar", "(", "items", ":", "List", "[", "T", "]", ",", "comparer", ":", "Callable", "[", "[", "T", ",", "T", "]", ",", "bool", "]", ")", "->", "List", "[", "List", "[", "T", "]", "]", ":", "groups", "=", "[", "]", "# type: List...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_perp_eigendecompose
An eigendecomposition that ensures eigenvectors are perpendicular. numpy.linalg.eig doesn't guarantee that eigenvectors from the same eigenspace will be perpendicular. This method uses Gram-Schmidt to recover a perpendicular set. It further checks that all eigenvectors are perpendicular and raises an A...
cirq/linalg/decompositions.py
def _perp_eigendecompose(matrix: np.ndarray, rtol: float = 1e-5, atol: float = 1e-8, ) -> Tuple[np.array, List[np.ndarray]]: """An eigendecomposition that ensures eigenvectors are perpendicular. numpy.linalg.eig doesn't guarantee that e...
def _perp_eigendecompose(matrix: np.ndarray, rtol: float = 1e-5, atol: float = 1e-8, ) -> Tuple[np.array, List[np.ndarray]]: """An eigendecomposition that ensures eigenvectors are perpendicular. numpy.linalg.eig doesn't guarantee that e...
[ "An", "eigendecomposition", "that", "ensures", "eigenvectors", "are", "perpendicular", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/decompositions.py#L101-L145
[ "def", "_perp_eigendecompose", "(", "matrix", ":", "np", ".", "ndarray", ",", "rtol", ":", "float", "=", "1e-5", ",", "atol", ":", "float", "=", "1e-8", ",", ")", "->", "Tuple", "[", "np", ".", "array", ",", "List", "[", "np", ".", "ndarray", "]", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
map_eigenvalues
Applies a function to the eigenvalues of a matrix. Given M = sum_k a_k |v_k><v_k|, returns f(M) = sum_k f(a_k) |v_k><v_k|. Args: matrix: The matrix to modify with the function. func: The function to apply to the eigenvalues of the matrix. rtol: Relative threshold used when separating e...
cirq/linalg/decompositions.py
def map_eigenvalues( matrix: np.ndarray, func: Callable[[complex], complex], *, rtol: float = 1e-5, atol: float = 1e-8) -> np.ndarray: """Applies a function to the eigenvalues of a matrix. Given M = sum_k a_k |v_k><v_k|, returns f(M) = sum_k f(a_k) |v_k><v_k|. Args:...
def map_eigenvalues( matrix: np.ndarray, func: Callable[[complex], complex], *, rtol: float = 1e-5, atol: float = 1e-8) -> np.ndarray: """Applies a function to the eigenvalues of a matrix. Given M = sum_k a_k |v_k><v_k|, returns f(M) = sum_k f(a_k) |v_k><v_k|. Args:...
[ "Applies", "a", "function", "to", "the", "eigenvalues", "of", "a", "matrix", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/decompositions.py#L148-L176
[ "def", "map_eigenvalues", "(", "matrix", ":", "np", ".", "ndarray", ",", "func", ":", "Callable", "[", "[", "complex", "]", ",", "complex", "]", ",", "*", ",", "rtol", ":", "float", "=", "1e-5", ",", "atol", ":", "float", "=", "1e-8", ")", "->", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
kron_factor_4x4_to_2x2s
Splits a 4x4 matrix U = kron(A, B) into A, B, and a global factor. Requires the matrix to be the kronecker product of two 2x2 unitaries. Requires the matrix to have a non-zero determinant. Giving an incorrect matrix will cause garbage output. Args: matrix: The 4x4 unitary matrix to factor. ...
cirq/linalg/decompositions.py
def kron_factor_4x4_to_2x2s( matrix: np.ndarray, ) -> Tuple[complex, np.ndarray, np.ndarray]: """Splits a 4x4 matrix U = kron(A, B) into A, B, and a global factor. Requires the matrix to be the kronecker product of two 2x2 unitaries. Requires the matrix to have a non-zero determinant. Giving an...
def kron_factor_4x4_to_2x2s( matrix: np.ndarray, ) -> Tuple[complex, np.ndarray, np.ndarray]: """Splits a 4x4 matrix U = kron(A, B) into A, B, and a global factor. Requires the matrix to be the kronecker product of two 2x2 unitaries. Requires the matrix to have a non-zero determinant. Giving an...
[ "Splits", "a", "4x4", "matrix", "U", "=", "kron", "(", "A", "B", ")", "into", "A", "B", "and", "a", "global", "factor", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/decompositions.py#L179-L223
[ "def", "kron_factor_4x4_to_2x2s", "(", "matrix", ":", "np", ".", "ndarray", ",", ")", "->", "Tuple", "[", "complex", ",", "np", ".", "ndarray", ",", "np", ".", "ndarray", "]", ":", "# Use the entry with the largest magnitude as a reference point.", "a", ",", "b"...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
so4_to_magic_su2s
Finds 2x2 special-unitaries A, B where mat = Mag.H @ kron(A, B) @ Mag. Mag is the magic basis matrix: 1 0 0 i 0 i 1 0 0 i -1 0 (times sqrt(0.5) to normalize) 1 0 0 -i Args: mat: A real 4x4 orthogonal matrix. rtol: Per-matrix-entry relative toleran...
cirq/linalg/decompositions.py
def so4_to_magic_su2s( mat: np.ndarray, *, rtol: float = 1e-5, atol: float = 1e-8, check_preconditions: bool = True ) -> Tuple[np.ndarray, np.ndarray]: """Finds 2x2 special-unitaries A, B where mat = Mag.H @ kron(A, B) @ Mag. Mag is the magic basis matrix: 1 0 ...
def so4_to_magic_su2s( mat: np.ndarray, *, rtol: float = 1e-5, atol: float = 1e-8, check_preconditions: bool = True ) -> Tuple[np.ndarray, np.ndarray]: """Finds 2x2 special-unitaries A, B where mat = Mag.H @ kron(A, B) @ Mag. Mag is the magic basis matrix: 1 0 ...
[ "Finds", "2x2", "special", "-", "unitaries", "A", "B", "where", "mat", "=", "Mag", ".", "H", "@", "kron", "(", "A", "B", ")", "@", "Mag", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/decompositions.py#L226-L264
[ "def", "so4_to_magic_su2s", "(", "mat", ":", "np", ".", "ndarray", ",", "*", ",", "rtol", ":", "float", "=", "1e-5", ",", "atol", ":", "float", "=", "1e-8", ",", "check_preconditions", ":", "bool", "=", "True", ")", "->", "Tuple", "[", "np", ".", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
kak_canonicalize_vector
Canonicalizes an XX/YY/ZZ interaction by swap/negate/shift-ing axes. Args: x: The strength of the XX interaction. y: The strength of the YY interaction. z: The strength of the ZZ interaction. Returns: The canonicalized decomposition, with vector coefficients (x2, y2, z2) ...
cirq/linalg/decompositions.py
def kak_canonicalize_vector(x: float, y: float, z: float) -> KakDecomposition: """Canonicalizes an XX/YY/ZZ interaction by swap/negate/shift-ing axes. Args: x: The strength of the XX interaction. y: The strength of the YY interaction. z: The strength of the ZZ interaction. Returns:...
def kak_canonicalize_vector(x: float, y: float, z: float) -> KakDecomposition: """Canonicalizes an XX/YY/ZZ interaction by swap/negate/shift-ing axes. Args: x: The strength of the XX interaction. y: The strength of the YY interaction. z: The strength of the ZZ interaction. Returns:...
[ "Canonicalizes", "an", "XX", "/", "YY", "/", "ZZ", "interaction", "by", "swap", "/", "negate", "/", "shift", "-", "ing", "axes", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/decompositions.py#L366-L469
[ "def", "kak_canonicalize_vector", "(", "x", ":", "float", ",", "y", ":", "float", ",", "z", ":", "float", ")", "->", "KakDecomposition", ":", "phase", "=", "[", "complex", "(", "1", ")", "]", "# Accumulated global phase.", "left", "=", "[", "np", ".", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
kak_decomposition
Decomposes a 2-qubit unitary into 1-qubit ops and XX/YY/ZZ interactions. Args: mat: The 4x4 unitary matrix to decompose. rtol: Per-matrix-entry relative tolerance on equality. atol: Per-matrix-entry absolute tolerance on equality. Returns: A `cirq.KakDecomposition` canonicalize...
cirq/linalg/decompositions.py
def kak_decomposition( mat: np.ndarray, rtol: float = 1e-5, atol: float = 1e-8) -> KakDecomposition: """Decomposes a 2-qubit unitary into 1-qubit ops and XX/YY/ZZ interactions. Args: mat: The 4x4 unitary matrix to decompose. rtol: Per-matrix-entry relative tolerance on e...
def kak_decomposition( mat: np.ndarray, rtol: float = 1e-5, atol: float = 1e-8) -> KakDecomposition: """Decomposes a 2-qubit unitary into 1-qubit ops and XX/YY/ZZ interactions. Args: mat: The 4x4 unitary matrix to decompose. rtol: Per-matrix-entry relative tolerance on e...
[ "Decomposes", "a", "2", "-", "qubit", "unitary", "into", "1", "-", "qubit", "ops", "and", "XX", "/", "YY", "/", "ZZ", "interactions", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/decompositions.py#L472-L537
[ "def", "kak_decomposition", "(", "mat", ":", "np", ".", "ndarray", ",", "rtol", ":", "float", "=", "1e-5", ",", "atol", ":", "float", "=", "1e-8", ")", "->", "KakDecomposition", ":", "magic", "=", "np", ".", "array", "(", "[", "[", "1", ",", "0", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
update_mapping
Updates a mapping (in place) from qubits to logical indices according to a set of permutation gates. Any gates other than permutation gates are ignored. Args: mapping: The mapping to update. operations: The operations to update according to.
cirq/contrib/acquaintance/permutation.py
def update_mapping(mapping: Dict[ops.Qid, LogicalIndex], operations: ops.OP_TREE ) -> None: """Updates a mapping (in place) from qubits to logical indices according to a set of permutation gates. Any gates other than permutation gates are ignored. Args: map...
def update_mapping(mapping: Dict[ops.Qid, LogicalIndex], operations: ops.OP_TREE ) -> None: """Updates a mapping (in place) from qubits to logical indices according to a set of permutation gates. Any gates other than permutation gates are ignored. Args: map...
[ "Updates", "a", "mapping", "(", "in", "place", ")", "from", "qubits", "to", "logical", "indices", "according", "to", "a", "set", "of", "permutation", "gates", ".", "Any", "gates", "other", "than", "permutation", "gates", "are", "ignored", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/acquaintance/permutation.py#L162-L176
[ "def", "update_mapping", "(", "mapping", ":", "Dict", "[", "ops", ".", "Qid", ",", "LogicalIndex", "]", ",", "operations", ":", "ops", ".", "OP_TREE", ")", "->", "None", ":", "for", "op", "in", "ops", ".", "flatten_op_tree", "(", "operations", ")", ":"...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
PermutationGate.update_mapping
Updates a mapping (in place) from qubits to logical indices. Args: mapping: The mapping to update. keys: The qubits acted on by the gate.
cirq/contrib/acquaintance/permutation.py
def update_mapping(self, mapping: Dict[ops.Qid, LogicalIndex], keys: Sequence[ops.Qid] ) -> None: """Updates a mapping (in place) from qubits to logical indices. Args: mapping: The mapping to update. keys: The qubits acted on by the ...
def update_mapping(self, mapping: Dict[ops.Qid, LogicalIndex], keys: Sequence[ops.Qid] ) -> None: """Updates a mapping (in place) from qubits to logical indices. Args: mapping: The mapping to update. keys: The qubits acted on by the ...
[ "Updates", "a", "mapping", "(", "in", "place", ")", "from", "qubits", "to", "logical", "indices", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/acquaintance/permutation.py#L50-L63
[ "def", "update_mapping", "(", "self", ",", "mapping", ":", "Dict", "[", "ops", ".", "Qid", ",", "LogicalIndex", "]", ",", "keys", ":", "Sequence", "[", "ops", ".", "Qid", "]", ")", "->", "None", ":", "permutation", "=", "self", ".", "permutation", "(...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.write
Adds text to the given location. Args: x: The column in which to write the text. y: The row in which to write the text. text: The text to write at location (x, y). transposed_text: Optional text to write instead, if the text diagram is transposed.
cirq/circuits/text_diagram_drawer.py
def write(self, x: int, y: int, text: str, transposed_text: 'Optional[str]' = None): """Adds text to the given location. Args: x: The column in which to write the text. y: The row in which to write the text. tex...
def write(self, x: int, y: int, text: str, transposed_text: 'Optional[str]' = None): """Adds text to the given location. Args: x: The column in which to write the text. y: The row in which to write the text. tex...
[ "Adds", "text", "to", "the", "given", "location", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L69-L87
[ "def", "write", "(", "self", ",", "x", ":", "int", ",", "y", ":", "int", ",", "text", ":", "str", ",", "transposed_text", ":", "'Optional[str]'", "=", "None", ")", ":", "entry", "=", "self", ".", "entries", ".", "get", "(", "(", "x", ",", "y", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.content_present
Determines if a line or printed text is at the given location.
cirq/circuits/text_diagram_drawer.py
def content_present(self, x: int, y: int) -> bool: """Determines if a line or printed text is at the given location.""" # Text? if (x, y) in self.entries: return True # Vertical line? if any(v.x == x and v.y1 < y < v.y2 for v in self.vertical_lines): ret...
def content_present(self, x: int, y: int) -> bool: """Determines if a line or printed text is at the given location.""" # Text? if (x, y) in self.entries: return True # Vertical line? if any(v.x == x and v.y1 < y < v.y2 for v in self.vertical_lines): ret...
[ "Determines", "if", "a", "line", "or", "printed", "text", "is", "at", "the", "given", "location", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L89-L105
[ "def", "content_present", "(", "self", ",", "x", ":", "int", ",", "y", ":", "int", ")", "->", "bool", ":", "# Text?", "if", "(", "x", ",", "y", ")", "in", "self", ".", "entries", ":", "return", "True", "# Vertical line?", "if", "any", "(", "v", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.grid_line
Adds a vertical or horizontal line from (x1, y1) to (x2, y2). Horizontal line is selected on equality in the second coordinate and vertical line is selected on equality in the first coordinate. Raises: ValueError: If line is neither horizontal nor vertical.
cirq/circuits/text_diagram_drawer.py
def grid_line(self, x1: int, y1: int, x2: int, y2: int, emphasize: bool = False): """Adds a vertical or horizontal line from (x1, y1) to (x2, y2). Horizontal line is selected on equality in the second coordinate and vertical line is selected on equality in the first coordinate...
def grid_line(self, x1: int, y1: int, x2: int, y2: int, emphasize: bool = False): """Adds a vertical or horizontal line from (x1, y1) to (x2, y2). Horizontal line is selected on equality in the second coordinate and vertical line is selected on equality in the first coordinate...
[ "Adds", "a", "vertical", "or", "horizontal", "line", "from", "(", "x1", "y1", ")", "to", "(", "x2", "y2", ")", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L107-L122
[ "def", "grid_line", "(", "self", ",", "x1", ":", "int", ",", "y1", ":", "int", ",", "x2", ":", "int", ",", "y2", ":", "int", ",", "emphasize", ":", "bool", "=", "False", ")", ":", "if", "x1", "==", "x2", ":", "self", ".", "vertical_line", "(", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.vertical_line
Adds a line from (x, y1) to (x, y2).
cirq/circuits/text_diagram_drawer.py
def vertical_line(self, x: Union[int, float], y1: Union[int, float], y2: Union[int, float], emphasize: bool = False ) -> None: """Adds a line from (x, y1) to (x, y2).""" y1, y2 = sorted([y1, y2]...
def vertical_line(self, x: Union[int, float], y1: Union[int, float], y2: Union[int, float], emphasize: bool = False ) -> None: """Adds a line from (x, y1) to (x, y2).""" y1, y2 = sorted([y1, y2]...
[ "Adds", "a", "line", "from", "(", "x", "y1", ")", "to", "(", "x", "y2", ")", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L124-L132
[ "def", "vertical_line", "(", "self", ",", "x", ":", "Union", "[", "int", ",", "float", "]", ",", "y1", ":", "Union", "[", "int", ",", "float", "]", ",", "y2", ":", "Union", "[", "int", ",", "float", "]", ",", "emphasize", ":", "bool", "=", "Fal...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.horizontal_line
Adds a line from (x1, y) to (x2, y).
cirq/circuits/text_diagram_drawer.py
def horizontal_line(self, y: Union[int, float], x1: Union[int, float], x2: Union[int, float], emphasize: bool = False ) -> None: """Adds a line from (x1, y) to (x2, y).""" x1, x2 = sor...
def horizontal_line(self, y: Union[int, float], x1: Union[int, float], x2: Union[int, float], emphasize: bool = False ) -> None: """Adds a line from (x1, y) to (x2, y).""" x1, x2 = sor...
[ "Adds", "a", "line", "from", "(", "x1", "y", ")", "to", "(", "x2", "y", ")", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L134-L142
[ "def", "horizontal_line", "(", "self", ",", "y", ":", "Union", "[", "int", ",", "float", "]", ",", "x1", ":", "Union", "[", "int", ",", "float", "]", ",", "x2", ":", "Union", "[", "int", ",", "float", "]", ",", "emphasize", ":", "bool", "=", "F...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.transpose
Returns the same diagram, but mirrored across its diagonal.
cirq/circuits/text_diagram_drawer.py
def transpose(self) -> 'TextDiagramDrawer': """Returns the same diagram, but mirrored across its diagonal.""" out = TextDiagramDrawer() out.entries = {(y, x): _DiagramText(v.transposed_text, v.text) for (x, y), v in self.entries.items()} out.vertical_lines = [_Vert...
def transpose(self) -> 'TextDiagramDrawer': """Returns the same diagram, but mirrored across its diagonal.""" out = TextDiagramDrawer() out.entries = {(y, x): _DiagramText(v.transposed_text, v.text) for (x, y), v in self.entries.items()} out.vertical_lines = [_Vert...
[ "Returns", "the", "same", "diagram", "but", "mirrored", "across", "its", "diagonal", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L144-L155
[ "def", "transpose", "(", "self", ")", "->", "'TextDiagramDrawer'", ":", "out", "=", "TextDiagramDrawer", "(", ")", "out", ".", "entries", "=", "{", "(", "y", ",", "x", ")", ":", "_DiagramText", "(", "v", ".", "transposed_text", ",", "v", ".", "text", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.width
Determines how many entry columns are in the diagram.
cirq/circuits/text_diagram_drawer.py
def width(self) -> int: """Determines how many entry columns are in the diagram.""" max_x = -1.0 for x, _ in self.entries.keys(): max_x = max(max_x, x) for v in self.vertical_lines: max_x = max(max_x, v.x) for h in self.horizontal_lines: max_x ...
def width(self) -> int: """Determines how many entry columns are in the diagram.""" max_x = -1.0 for x, _ in self.entries.keys(): max_x = max(max_x, x) for v in self.vertical_lines: max_x = max(max_x, v.x) for h in self.horizontal_lines: max_x ...
[ "Determines", "how", "many", "entry", "columns", "are", "in", "the", "diagram", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L157-L166
[ "def", "width", "(", "self", ")", "->", "int", ":", "max_x", "=", "-", "1.0", "for", "x", ",", "_", "in", "self", ".", "entries", ".", "keys", "(", ")", ":", "max_x", "=", "max", "(", "max_x", ",", "x", ")", "for", "v", "in", "self", ".", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.height
Determines how many entry rows are in the diagram.
cirq/circuits/text_diagram_drawer.py
def height(self) -> int: """Determines how many entry rows are in the diagram.""" max_y = -1.0 for _, y in self.entries.keys(): max_y = max(max_y, y) for h in self.horizontal_lines: max_y = max(max_y, h.y) for v in self.vertical_lines: max_y = ...
def height(self) -> int: """Determines how many entry rows are in the diagram.""" max_y = -1.0 for _, y in self.entries.keys(): max_y = max(max_y, y) for h in self.horizontal_lines: max_y = max(max_y, h.y) for v in self.vertical_lines: max_y = ...
[ "Determines", "how", "many", "entry", "rows", "are", "in", "the", "diagram", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L168-L177
[ "def", "height", "(", "self", ")", "->", "int", ":", "max_y", "=", "-", "1.0", "for", "_", ",", "y", "in", "self", ".", "entries", ".", "keys", "(", ")", ":", "max_y", "=", "max", "(", "max_y", ",", "y", ")", "for", "h", "in", "self", ".", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.force_horizontal_padding_after
Change the padding after the given column.
cirq/circuits/text_diagram_drawer.py
def force_horizontal_padding_after( self, index: int, padding: Union[int, float]) -> None: """Change the padding after the given column.""" self.horizontal_padding[index] = padding
def force_horizontal_padding_after( self, index: int, padding: Union[int, float]) -> None: """Change the padding after the given column.""" self.horizontal_padding[index] = padding
[ "Change", "the", "padding", "after", "the", "given", "column", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L179-L182
[ "def", "force_horizontal_padding_after", "(", "self", ",", "index", ":", "int", ",", "padding", ":", "Union", "[", "int", ",", "float", "]", ")", "->", "None", ":", "self", ".", "horizontal_padding", "[", "index", "]", "=", "padding" ]
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.force_vertical_padding_after
Change the padding after the given row.
cirq/circuits/text_diagram_drawer.py
def force_vertical_padding_after( self, index: int, padding: Union[int, float]) -> None: """Change the padding after the given row.""" self.vertical_padding[index] = padding
def force_vertical_padding_after( self, index: int, padding: Union[int, float]) -> None: """Change the padding after the given row.""" self.vertical_padding[index] = padding
[ "Change", "the", "padding", "after", "the", "given", "row", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L184-L187
[ "def", "force_vertical_padding_after", "(", "self", ",", "index", ":", "int", ",", "padding", ":", "Union", "[", "int", ",", "float", "]", ")", "->", "None", ":", "self", ".", "vertical_padding", "[", "index", "]", "=", "padding" ]
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer._transform_coordinates
Helper method to transformer either row or column coordinates.
cirq/circuits/text_diagram_drawer.py
def _transform_coordinates( self, func: Callable[[Union[int, float], Union[int, float]], Tuple[Union[int, float], Union[int, float]]] ) -> None: """Helper method to transformer either row or column coordinates.""" def func_x(x: Union[int, float]) -...
def _transform_coordinates( self, func: Callable[[Union[int, float], Union[int, float]], Tuple[Union[int, float], Union[int, float]]] ) -> None: """Helper method to transformer either row or column coordinates.""" def func_x(x: Union[int, float]) -...
[ "Helper", "method", "to", "transformer", "either", "row", "or", "column", "coordinates", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L189-L219
[ "def", "_transform_coordinates", "(", "self", ",", "func", ":", "Callable", "[", "[", "Union", "[", "int", ",", "float", "]", ",", "Union", "[", "int", ",", "float", "]", "]", ",", "Tuple", "[", "Union", "[", "int", ",", "float", "]", ",", "Union",...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.insert_empty_columns
Insert a number of columns after the given column.
cirq/circuits/text_diagram_drawer.py
def insert_empty_columns(self, x: int, amount: int = 1) -> None: """Insert a number of columns after the given column.""" def transform_columns( column: Union[int, float], row: Union[int, float] ) -> Tuple[Union[int, float], Union[int, float]]: return ...
def insert_empty_columns(self, x: int, amount: int = 1) -> None: """Insert a number of columns after the given column.""" def transform_columns( column: Union[int, float], row: Union[int, float] ) -> Tuple[Union[int, float], Union[int, float]]: return ...
[ "Insert", "a", "number", "of", "columns", "after", "the", "given", "column", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L221-L228
[ "def", "insert_empty_columns", "(", "self", ",", "x", ":", "int", ",", "amount", ":", "int", "=", "1", ")", "->", "None", ":", "def", "transform_columns", "(", "column", ":", "Union", "[", "int", ",", "float", "]", ",", "row", ":", "Union", "[", "i...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.insert_empty_rows
Insert a number of rows after the given row.
cirq/circuits/text_diagram_drawer.py
def insert_empty_rows(self, y: int, amount: int = 1) -> None: """Insert a number of rows after the given row.""" def transform_rows( column: Union[int, float], row: Union[int, float] ) -> Tuple[Union[int, float], Union[int, float]]: return column, row ...
def insert_empty_rows(self, y: int, amount: int = 1) -> None: """Insert a number of rows after the given row.""" def transform_rows( column: Union[int, float], row: Union[int, float] ) -> Tuple[Union[int, float], Union[int, float]]: return column, row ...
[ "Insert", "a", "number", "of", "rows", "after", "the", "given", "row", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L230-L237
[ "def", "insert_empty_rows", "(", "self", ",", "y", ":", "int", ",", "amount", ":", "int", "=", "1", ")", "->", "None", ":", "def", "transform_rows", "(", "column", ":", "Union", "[", "int", ",", "float", "]", ",", "row", ":", "Union", "[", "int", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
TextDiagramDrawer.render
Outputs text containing the diagram.
cirq/circuits/text_diagram_drawer.py
def render(self, horizontal_spacing: int = 1, vertical_spacing: int = 1, crossing_char: str = None, use_unicode_characters: bool = True) -> str: """Outputs text containing the diagram.""" block_diagram = BlockDiagramDrawer() w = self....
def render(self, horizontal_spacing: int = 1, vertical_spacing: int = 1, crossing_char: str = None, use_unicode_characters: bool = True) -> str: """Outputs text containing the diagram.""" block_diagram = BlockDiagramDrawer() w = self....
[ "Outputs", "text", "containing", "the", "diagram", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/circuits/text_diagram_drawer.py#L239-L307
[ "def", "render", "(", "self", ",", "horizontal_spacing", ":", "int", "=", "1", ",", "vertical_spacing", ":", "int", "=", "1", ",", "crossing_char", ":", "str", "=", "None", ",", "use_unicode_characters", ":", "bool", "=", "True", ")", "->", "str", ":", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
all_near_zero
Checks if the tensor's elements are all near zero. Args: a: Tensor of elements that could all be near zero. atol: Absolute tolerance.
cirq/linalg/tolerance.py
def all_near_zero(a: Union[float, complex, Iterable[float], np.ndarray], *, atol: float = 1e-8) -> bool: """Checks if the tensor's elements are all near zero. Args: a: Tensor of elements that could all be near zero. atol: Absolute tolerance. """ retur...
def all_near_zero(a: Union[float, complex, Iterable[float], np.ndarray], *, atol: float = 1e-8) -> bool: """Checks if the tensor's elements are all near zero. Args: a: Tensor of elements that could all be near zero. atol: Absolute tolerance. """ retur...
[ "Checks", "if", "the", "tensor", "s", "elements", "are", "all", "near", "zero", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/tolerance.py#L22-L31
[ "def", "all_near_zero", "(", "a", ":", "Union", "[", "float", ",", "complex", ",", "Iterable", "[", "float", "]", ",", "np", ".", "ndarray", "]", ",", "*", ",", "atol", ":", "float", "=", "1e-8", ")", "->", "bool", ":", "return", "np", ".", "all"...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
all_near_zero_mod
Checks if the tensor's elements are all near multiples of the period. Args: a: Tensor of elements that could all be near multiples of the period. period: The period, e.g. 2 pi when working in radians. atol: Absolute tolerance.
cirq/linalg/tolerance.py
def all_near_zero_mod(a: Union[float, complex, Iterable[float], np.ndarray], period: float, *, atol: float = 1e-8) -> bool: """Checks if the tensor's elements are all near multiples of the period. Args: a: Tensor of elements that could a...
def all_near_zero_mod(a: Union[float, complex, Iterable[float], np.ndarray], period: float, *, atol: float = 1e-8) -> bool: """Checks if the tensor's elements are all near multiples of the period. Args: a: Tensor of elements that could a...
[ "Checks", "if", "the", "tensor", "s", "elements", "are", "all", "near", "multiples", "of", "the", "period", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/tolerance.py#L34-L46
[ "def", "all_near_zero_mod", "(", "a", ":", "Union", "[", "float", ",", "complex", ",", "Iterable", "[", "float", "]", ",", "np", ".", "ndarray", "]", ",", "period", ":", "float", ",", "*", ",", "atol", ":", "float", "=", "1e-8", ")", "->", "bool", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_git_fetch_for_comparison
Fetches two branches including their common ancestor. Limits the depth of the fetch to avoid unnecessary work. Scales up the depth exponentially and tries again when the initial guess is not deep enough. Args: remote: The location of the remote repository, in a format that the git ...
dev_tools/git_env_tools.py
def _git_fetch_for_comparison(remote: str, actual_branch: str, compare_branch: str, verbose: bool) -> prepared_env.PreparedEnv: """Fetches two branches including their common ancestor. Limits the depth of the fetch to avo...
def _git_fetch_for_comparison(remote: str, actual_branch: str, compare_branch: str, verbose: bool) -> prepared_env.PreparedEnv: """Fetches two branches including their common ancestor. Limits the depth of the fetch to avo...
[ "Fetches", "two", "branches", "including", "their", "common", "ancestor", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/dev_tools/git_env_tools.py#L28-L85
[ "def", "_git_fetch_for_comparison", "(", "remote", ":", "str", ",", "actual_branch", ":", "str", ",", "compare_branch", ":", "str", ",", "verbose", ":", "bool", ")", "->", "prepared_env", ".", "PreparedEnv", ":", "actual_id", "=", "''", "base_id", "=", "''",...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
fetch_github_pull_request
Uses content from github to create a dir for testing and comparisons. Args: destination_directory: The location to fetch the contents into. repository: The github repository that the commit lives under. pull_request_number: The id of the pull request to clone. If None, then the ...
dev_tools/git_env_tools.py
def fetch_github_pull_request(destination_directory: str, repository: github_repository.GithubRepository, pull_request_number: int, verbose: bool ) -> prepared_env.PreparedEnv: """Uses content fro...
def fetch_github_pull_request(destination_directory: str, repository: github_repository.GithubRepository, pull_request_number: int, verbose: bool ) -> prepared_env.PreparedEnv: """Uses content fro...
[ "Uses", "content", "from", "github", "to", "create", "a", "dir", "for", "testing", "and", "comparisons", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/dev_tools/git_env_tools.py#L88-L139
[ "def", "fetch_github_pull_request", "(", "destination_directory", ":", "str", ",", "repository", ":", "github_repository", ".", "GithubRepository", ",", "pull_request_number", ":", "int", ",", "verbose", ":", "bool", ")", "->", "prepared_env", ".", "PreparedEnv", ":...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
fetch_local_files
Uses local files to create a directory for testing and comparisons. Args: destination_directory: The directory where the copied files should go. verbose: When set, more progress output is produced. Returns: Commit ids corresponding to content to test/compare.
dev_tools/git_env_tools.py
def fetch_local_files(destination_directory: str, verbose: bool) -> prepared_env.PreparedEnv: """Uses local files to create a directory for testing and comparisons. Args: destination_directory: The directory where the copied files should go. verbose: When set, more progres...
def fetch_local_files(destination_directory: str, verbose: bool) -> prepared_env.PreparedEnv: """Uses local files to create a directory for testing and comparisons. Args: destination_directory: The directory where the copied files should go. verbose: When set, more progres...
[ "Uses", "local", "files", "to", "create", "a", "directory", "for", "testing", "and", "comparisons", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/dev_tools/git_env_tools.py#L142-L214
[ "def", "fetch_local_files", "(", "destination_directory", ":", "str", ",", "verbose", ":", "bool", ")", "->", "prepared_env", ".", "PreparedEnv", ":", "staging_dir", "=", "destination_directory", "+", "'-staging'", "try", ":", "shutil", ".", "copytree", "(", "ge...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
circuit_to_tensorflow_runnable
Returns a compute function and feed_dict for a `cirq.Circuit`'s output. `result.compute()` will return a `tensorflow.Tensor` with `tensorflow.placeholder` objects to be filled in by `result.feed_dict`, at which point it will evaluate to the output state vector of the circuit. You can apply further ope...
cirq/contrib/tpu/circuit_to_tensorflow.py
def circuit_to_tensorflow_runnable( circuit: circuits.Circuit, initial_state: Union[int, np.ndarray] = 0, ) -> ComputeFuncAndFeedDict: """Returns a compute function and feed_dict for a `cirq.Circuit`'s output. `result.compute()` will return a `tensorflow.Tensor` with `tensorflow.pla...
def circuit_to_tensorflow_runnable( circuit: circuits.Circuit, initial_state: Union[int, np.ndarray] = 0, ) -> ComputeFuncAndFeedDict: """Returns a compute function and feed_dict for a `cirq.Circuit`'s output. `result.compute()` will return a `tensorflow.Tensor` with `tensorflow.pla...
[ "Returns", "a", "compute", "function", "and", "feed_dict", "for", "a", "cirq", ".", "Circuit", "s", "output", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/tpu/circuit_to_tensorflow.py#L41-L118
[ "def", "circuit_to_tensorflow_runnable", "(", "circuit", ":", "circuits", ".", "Circuit", ",", "initial_state", ":", "Union", "[", "int", ",", "np", ".", "ndarray", "]", "=", "0", ",", ")", "->", "ComputeFuncAndFeedDict", ":", "if", "not", "circuit", ".", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_circuit_as_layers
Transforms a circuit into a series of GroupMatrix+CZ layers. Args: circuit: The circuit to transform. grouping: How the circuit's qubits are combined into groups. Returns: A list of layers. Each layer has a matrix to apply to each group of qubits, and a list of CZs to apply to ...
cirq/contrib/tpu/circuit_to_tensorflow.py
def _circuit_as_layers(circuit: circuits.Circuit, grouping: _QubitGrouping) -> List[_TransformsThenCzs]: """Transforms a circuit into a series of GroupMatrix+CZ layers. Args: circuit: The circuit to transform. grouping: How the circuit's qubits are combined into groups. ...
def _circuit_as_layers(circuit: circuits.Circuit, grouping: _QubitGrouping) -> List[_TransformsThenCzs]: """Transforms a circuit into a series of GroupMatrix+CZ layers. Args: circuit: The circuit to transform. grouping: How the circuit's qubits are combined into groups. ...
[ "Transforms", "a", "circuit", "into", "a", "series", "of", "GroupMatrix", "+", "CZ", "layers", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/tpu/circuit_to_tensorflow.py#L213-L283
[ "def", "_circuit_as_layers", "(", "circuit", ":", "circuits", ".", "Circuit", ",", "grouping", ":", "_QubitGrouping", ")", "->", "List", "[", "_TransformsThenCzs", "]", ":", "frontier", "=", "{", "q", ":", "0", "for", "q", "in", "circuit", ".", "all_qubits...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_deref
Equivalent to `tensor[index, ...]`. This is a workaround for XLA requiring constant tensor indices. It works by producing a node representing hardcoded instructions like the following: if index == 0: return tensor[0] if index == 1: return tensor[1] if index == 2: return tensor[2] ....
cirq/contrib/tpu/circuit_to_tensorflow.py
def _deref(tensor: tf.Tensor, index: tf.Tensor) -> tf.Tensor: """Equivalent to `tensor[index, ...]`. This is a workaround for XLA requiring constant tensor indices. It works by producing a node representing hardcoded instructions like the following: if index == 0: return tensor[0] if index =...
def _deref(tensor: tf.Tensor, index: tf.Tensor) -> tf.Tensor: """Equivalent to `tensor[index, ...]`. This is a workaround for XLA requiring constant tensor indices. It works by producing a node representing hardcoded instructions like the following: if index == 0: return tensor[0] if index =...
[ "Equivalent", "to", "tensor", "[", "index", "...", "]", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/tpu/circuit_to_tensorflow.py#L286-L306
[ "def", "_deref", "(", "tensor", ":", "tf", ".", "Tensor", ",", "index", ":", "tf", ".", "Tensor", ")", "->", "tf", ".", "Tensor", ":", "assert", "tensor", ".", "shape", "[", "0", "]", ">", "0", "return", "_deref_helper", "(", "lambda", "i", ":", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_multi_deref
Equivalent to `[t[index, ...] for t in tensors]`. See `_deref` for more details.
cirq/contrib/tpu/circuit_to_tensorflow.py
def _multi_deref(tensors: List[tf.Tensor], index: tf.Tensor) -> List[tf.Tensor]: """Equivalent to `[t[index, ...] for t in tensors]`. See `_deref` for more details. """ assert tensors assert tensors[0].shape[0] > 0 return _deref_helper(lambda i: [tensor[i, ...] for tensor in tensors], ...
def _multi_deref(tensors: List[tf.Tensor], index: tf.Tensor) -> List[tf.Tensor]: """Equivalent to `[t[index, ...] for t in tensors]`. See `_deref` for more details. """ assert tensors assert tensors[0].shape[0] > 0 return _deref_helper(lambda i: [tensor[i, ...] for tensor in tensors], ...
[ "Equivalent", "to", "[", "t", "[", "index", "...", "]", "for", "t", "in", "tensors", "]", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/tpu/circuit_to_tensorflow.py#L309-L319
[ "def", "_multi_deref", "(", "tensors", ":", "List", "[", "tf", ".", "Tensor", "]", ",", "index", ":", "tf", ".", "Tensor", ")", "->", "List", "[", "tf", ".", "Tensor", "]", ":", "assert", "tensors", "assert", "tensors", "[", "0", "]", ".", "shape",...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Sampler.run
Samples from the given Circuit or Schedule. Args: program: The circuit or schedule to simulate. param_resolver: Parameters to run with the program. repetitions: The number of repetitions to simulate. Returns: TrialResult for a run.
cirq/sim/sampler.py
def run( self, program: Union[circuits.Circuit, schedules.Schedule], param_resolver: 'study.ParamResolverOrSimilarType' = None, repetitions: int = 1, ) -> study.TrialResult: """Samples from the given Circuit or Schedule. Args: program: The...
def run( self, program: Union[circuits.Circuit, schedules.Schedule], param_resolver: 'study.ParamResolverOrSimilarType' = None, repetitions: int = 1, ) -> study.TrialResult: """Samples from the given Circuit or Schedule. Args: program: The...
[ "Samples", "from", "the", "given", "Circuit", "or", "Schedule", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/sim/sampler.py#L25-L42
[ "def", "run", "(", "self", ",", "program", ":", "Union", "[", "circuits", ".", "Circuit", ",", "schedules", ".", "Schedule", "]", ",", "param_resolver", ":", "'study.ParamResolverOrSimilarType'", "=", "None", ",", "repetitions", ":", "int", "=", "1", ",", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Sampler.run_sweep
Samples from the given Circuit or Schedule. In contrast to run, this allows for sweeping over different parameter values. Args: program: The circuit or schedule to simulate. params: Parameters to run with the program. repetitions: The number of repetitions t...
cirq/sim/sampler.py
def run_sweep( self, program: Union[circuits.Circuit, schedules.Schedule], params: study.Sweepable, repetitions: int = 1, ) -> List[study.TrialResult]: """Samples from the given Circuit or Schedule. In contrast to run, this allows for sweeping over di...
def run_sweep( self, program: Union[circuits.Circuit, schedules.Schedule], params: study.Sweepable, repetitions: int = 1, ) -> List[study.TrialResult]: """Samples from the given Circuit or Schedule. In contrast to run, this allows for sweeping over di...
[ "Samples", "from", "the", "given", "Circuit", "or", "Schedule", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/sim/sampler.py#L45-L64
[ "def", "run_sweep", "(", "self", ",", "program", ":", "Union", "[", "circuits", ".", "Circuit", ",", "schedules", ".", "Schedule", "]", ",", "params", ":", "study", ".", "Sweepable", ",", "repetitions", ":", "int", "=", "1", ",", ")", "->", "List", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
measure
Returns a single MeasurementGate applied to all the given qubits. The qubits are measured in the computational basis. Args: *qubits: The qubits that the measurement gate should measure. key: The string key of the measurement. If this is None, it defaults to a comma-separated list o...
cirq/ops/common_gates.py
def measure(*qubits: raw_types.Qid, key: Optional[str] = None, invert_mask: Tuple[bool, ...] = () ) -> gate_operation.GateOperation: """Returns a single MeasurementGate applied to all the given qubits. The qubits are measured in the computational basis. Args: *q...
def measure(*qubits: raw_types.Qid, key: Optional[str] = None, invert_mask: Tuple[bool, ...] = () ) -> gate_operation.GateOperation: """Returns a single MeasurementGate applied to all the given qubits. The qubits are measured in the computational basis. Args: *q...
[ "Returns", "a", "single", "MeasurementGate", "applied", "to", "all", "the", "given", "qubits", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/common_gates.py#L509-L543
[ "def", "measure", "(", "*", "qubits", ":", "raw_types", ".", "Qid", ",", "key", ":", "Optional", "[", "str", "]", "=", "None", ",", "invert_mask", ":", "Tuple", "[", "bool", ",", "...", "]", "=", "(", ")", ")", "->", "gate_operation", ".", "GateOpe...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
measure_each
Returns a list of operations individually measuring the given qubits. The qubits are measured in the computational basis. Args: *qubits: The qubits to measure. key_func: Determines the key of the measurements of each qubit. Takes the qubit and returns the key for that qubit. Defaul...
cirq/ops/common_gates.py
def measure_each(*qubits: raw_types.Qid, key_func: Callable[[raw_types.Qid], str] = str ) -> List[gate_operation.GateOperation]: """Returns a list of operations individually measuring the given qubits. The qubits are measured in the computational basis. Args: *qub...
def measure_each(*qubits: raw_types.Qid, key_func: Callable[[raw_types.Qid], str] = str ) -> List[gate_operation.GateOperation]: """Returns a list of operations individually measuring the given qubits. The qubits are measured in the computational basis. Args: *qub...
[ "Returns", "a", "list", "of", "operations", "individually", "measuring", "the", "given", "qubits", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/common_gates.py#L546-L561
[ "def", "measure_each", "(", "*", "qubits", ":", "raw_types", ".", "Qid", ",", "key_func", ":", "Callable", "[", "[", "raw_types", ".", "Qid", "]", ",", "str", "]", "=", "str", ")", "->", "List", "[", "gate_operation", ".", "GateOperation", "]", ":", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Rx
Returns a gate with the matrix e^{-i X rads / 2}.
cirq/ops/common_gates.py
def Rx(rads: Union[float, sympy.Basic]) -> XPowGate: """Returns a gate with the matrix e^{-i X rads / 2}.""" pi = sympy.pi if protocols.is_parameterized(rads) else np.pi return XPowGate(exponent=rads / pi, global_shift=-0.5)
def Rx(rads: Union[float, sympy.Basic]) -> XPowGate: """Returns a gate with the matrix e^{-i X rads / 2}.""" pi = sympy.pi if protocols.is_parameterized(rads) else np.pi return XPowGate(exponent=rads / pi, global_shift=-0.5)
[ "Returns", "a", "gate", "with", "the", "matrix", "e^", "{", "-", "i", "X", "rads", "/", "2", "}", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/common_gates.py#L1132-L1135
[ "def", "Rx", "(", "rads", ":", "Union", "[", "float", ",", "sympy", ".", "Basic", "]", ")", "->", "XPowGate", ":", "pi", "=", "sympy", ".", "pi", "if", "protocols", ".", "is_parameterized", "(", "rads", ")", "else", "np", ".", "pi", "return", "XPow...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Ry
Returns a gate with the matrix e^{-i Y rads / 2}.
cirq/ops/common_gates.py
def Ry(rads: Union[float, sympy.Basic]) -> YPowGate: """Returns a gate with the matrix e^{-i Y rads / 2}.""" pi = sympy.pi if protocols.is_parameterized(rads) else np.pi return YPowGate(exponent=rads / pi, global_shift=-0.5)
def Ry(rads: Union[float, sympy.Basic]) -> YPowGate: """Returns a gate with the matrix e^{-i Y rads / 2}.""" pi = sympy.pi if protocols.is_parameterized(rads) else np.pi return YPowGate(exponent=rads / pi, global_shift=-0.5)
[ "Returns", "a", "gate", "with", "the", "matrix", "e^", "{", "-", "i", "Y", "rads", "/", "2", "}", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/common_gates.py#L1138-L1141
[ "def", "Ry", "(", "rads", ":", "Union", "[", "float", ",", "sympy", ".", "Basic", "]", ")", "->", "YPowGate", ":", "pi", "=", "sympy", ".", "pi", "if", "protocols", ".", "is_parameterized", "(", "rads", ")", "else", "np", ".", "pi", "return", "YPow...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Rz
Returns a gate with the matrix e^{-i Z rads / 2}.
cirq/ops/common_gates.py
def Rz(rads: Union[float, sympy.Basic]) -> ZPowGate: """Returns a gate with the matrix e^{-i Z rads / 2}.""" pi = sympy.pi if protocols.is_parameterized(rads) else np.pi return ZPowGate(exponent=rads / pi, global_shift=-0.5)
def Rz(rads: Union[float, sympy.Basic]) -> ZPowGate: """Returns a gate with the matrix e^{-i Z rads / 2}.""" pi = sympy.pi if protocols.is_parameterized(rads) else np.pi return ZPowGate(exponent=rads / pi, global_shift=-0.5)
[ "Returns", "a", "gate", "with", "the", "matrix", "e^", "{", "-", "i", "Z", "rads", "/", "2", "}", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/common_gates.py#L1144-L1147
[ "def", "Rz", "(", "rads", ":", "Union", "[", "float", ",", "sympy", ".", "Basic", "]", ")", "->", "ZPowGate", ":", "pi", "=", "sympy", ".", "pi", "if", "protocols", ".", "is_parameterized", "(", "rads", ")", "else", "np", ".", "pi", "return", "ZPow...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
SwapPowGate._decompose_
See base class.
cirq/ops/common_gates.py
def _decompose_(self, qubits): """See base class.""" a, b = qubits yield CNOT(a, b) yield CNOT(b, a) ** self._exponent yield CNOT(a, b)
def _decompose_(self, qubits): """See base class.""" a, b = qubits yield CNOT(a, b) yield CNOT(b, a) ** self._exponent yield CNOT(a, b)
[ "See", "base", "class", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/common_gates.py#L948-L953
[ "def", "_decompose_", "(", "self", ",", "qubits", ")", ":", "a", ",", "b", "=", "qubits", "yield", "CNOT", "(", "a", ",", "b", ")", "yield", "CNOT", "(", "b", ",", "a", ")", "**", "self", ".", "_exponent", "yield", "CNOT", "(", "a", ",", "b", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Gate.validate_args
Checks if this gate can be applied to the given qubits. By default checks if input is of type Qid and qubit count. Child classes can override. Args: qubits: The collection of qubits to potentially apply the gate to. Throws: ValueError: The gate can't be applied...
cirq/ops/raw_types.py
def validate_args(self, qubits: Sequence[Qid]) -> None: """Checks if this gate can be applied to the given qubits. By default checks if input is of type Qid and qubit count. Child classes can override. Args: qubits: The collection of qubits to potentially apply the gate to....
def validate_args(self, qubits: Sequence[Qid]) -> None: """Checks if this gate can be applied to the given qubits. By default checks if input is of type Qid and qubit count. Child classes can override. Args: qubits: The collection of qubits to potentially apply the gate to....
[ "Checks", "if", "this", "gate", "can", "be", "applied", "to", "the", "given", "qubits", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/raw_types.py#L107-L135
[ "def", "validate_args", "(", "self", ",", "qubits", ":", "Sequence", "[", "Qid", "]", ")", "->", "None", ":", "if", "len", "(", "qubits", ")", "==", "0", ":", "raise", "ValueError", "(", "\"Applied a gate to an empty set of qubits. Gate: {}\"", ".", "format", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Gate.on
Returns an application of this gate to the given qubits. Args: *qubits: The collection of qubits to potentially apply the gate to.
cirq/ops/raw_types.py
def on(self, *qubits: Qid) -> 'gate_operation.GateOperation': """Returns an application of this gate to the given qubits. Args: *qubits: The collection of qubits to potentially apply the gate to. """ # Avoids circular import. from cirq.ops import gate_operation ...
def on(self, *qubits: Qid) -> 'gate_operation.GateOperation': """Returns an application of this gate to the given qubits. Args: *qubits: The collection of qubits to potentially apply the gate to. """ # Avoids circular import. from cirq.ops import gate_operation ...
[ "Returns", "an", "application", "of", "this", "gate", "to", "the", "given", "qubits", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/raw_types.py#L137-L145
[ "def", "on", "(", "self", ",", "*", "qubits", ":", "Qid", ")", "->", "'gate_operation.GateOperation'", ":", "# Avoids circular import.", "from", "cirq", ".", "ops", "import", "gate_operation", "return", "gate_operation", ".", "GateOperation", "(", "self", ",", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Gate.controlled_by
Returns a controlled version of this gate. Args: control_qubits: Optional qubits to control the gate by.
cirq/ops/raw_types.py
def controlled_by(self, *control_qubits: Qid) -> 'Gate': """Returns a controlled version of this gate. Args: control_qubits: Optional qubits to control the gate by. """ # Avoids circular import. from cirq.ops import ControlledGate return ControlledGate(self, ...
def controlled_by(self, *control_qubits: Qid) -> 'Gate': """Returns a controlled version of this gate. Args: control_qubits: Optional qubits to control the gate by. """ # Avoids circular import. from cirq.ops import ControlledGate return ControlledGate(self, ...
[ "Returns", "a", "controlled", "version", "of", "this", "gate", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/raw_types.py#L213-L223
[ "def", "controlled_by", "(", "self", ",", "*", "control_qubits", ":", "Qid", ")", "->", "'Gate'", ":", "# Avoids circular import.", "from", "cirq", ".", "ops", "import", "ControlledGate", "return", "ControlledGate", "(", "self", ",", "control_qubits", ",", "len"...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Operation.transform_qubits
Returns the same operation, but with different qubits. Args: func: The function to use to turn each current qubit into a desired new qubit. Returns: The receiving operation but with qubits transformed by the given function.
cirq/ops/raw_types.py
def transform_qubits(self: TSelf_Operation, func: Callable[[Qid], Qid]) -> TSelf_Operation: """Returns the same operation, but with different qubits. Args: func: The function to use to turn each current qubit into a desired new qubit. Return...
def transform_qubits(self: TSelf_Operation, func: Callable[[Qid], Qid]) -> TSelf_Operation: """Returns the same operation, but with different qubits. Args: func: The function to use to turn each current qubit into a desired new qubit. Return...
[ "Returns", "the", "same", "operation", "but", "with", "different", "qubits", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/raw_types.py#L249-L261
[ "def", "transform_qubits", "(", "self", ":", "TSelf_Operation", ",", "func", ":", "Callable", "[", "[", "Qid", "]", ",", "Qid", "]", ")", "->", "TSelf_Operation", ":", "return", "self", ".", "with_qubits", "(", "*", "(", "func", "(", "q", ")", "for", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Operation.controlled_by
Returns a controlled version of this operation. Args: control_qubits: Qubits to control the operation by. Required.
cirq/ops/raw_types.py
def controlled_by(self, *control_qubits: Qid) -> 'Operation': """Returns a controlled version of this operation. Args: control_qubits: Qubits to control the operation by. Required. """ # Avoids circular import. from cirq.ops import ControlledOperation if cont...
def controlled_by(self, *control_qubits: Qid) -> 'Operation': """Returns a controlled version of this operation. Args: control_qubits: Qubits to control the operation by. Required. """ # Avoids circular import. from cirq.ops import ControlledOperation if cont...
[ "Returns", "a", "controlled", "version", "of", "this", "operation", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/raw_types.py#L263-L276
[ "def", "controlled_by", "(", "self", ",", "*", "control_qubits", ":", "Qid", ")", "->", "'Operation'", ":", "# Avoids circular import.", "from", "cirq", ".", "ops", "import", "ControlledOperation", "if", "control_qubits", "is", "None", "or", "len", "(", "control...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
WaveFunctionDisplay.value_derived_from_wavefunction
The value of the display, derived from the full wavefunction. Args: state: The wavefunction. qubit_map: A dictionary from qubit to qubit index in the ordering used to define the wavefunction.
cirq/ops/display.py
def value_derived_from_wavefunction(self, state: np.ndarray, qubit_map: Dict[raw_types.Qid, int] ) -> Any: """The value of the display, derived from the full wavefunction. Args: ...
def value_derived_from_wavefunction(self, state: np.ndarray, qubit_map: Dict[raw_types.Qid, int] ) -> Any: """The value of the display, derived from the full wavefunction. Args: ...
[ "The", "value", "of", "the", "display", "derived", "from", "the", "full", "wavefunction", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/display.py#L91-L101
[ "def", "value_derived_from_wavefunction", "(", "self", ",", "state", ":", "np", ".", "ndarray", ",", "qubit_map", ":", "Dict", "[", "raw_types", ".", "Qid", ",", "int", "]", ")", "->", "Any", ":" ]
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Check.perform_check
Evaluates the status check and returns a pass/fail with message. Args: env: Describes a prepared python 3 environment in which to run. verbose: When set, more progress output is produced. Returns: A tuple containing a pass/fail boolean and then a details message.
dev_tools/check.py
def perform_check(self, env: env_tools.PreparedEnv, verbose: bool) -> Tuple[bool, str]: """Evaluates the status check and returns a pass/fail with message. Args: env: Describes a prepared python 3 environment in which to run. verbose: ...
def perform_check(self, env: env_tools.PreparedEnv, verbose: bool) -> Tuple[bool, str]: """Evaluates the status check and returns a pass/fail with message. Args: env: Describes a prepared python 3 environment in which to run. verbose: ...
[ "Evaluates", "the", "status", "check", "and", "returns", "a", "pass", "/", "fail", "with", "message", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/dev_tools/check.py#L61-L72
[ "def", "perform_check", "(", "self", ",", "env", ":", "env_tools", ".", "PreparedEnv", ",", "verbose", ":", "bool", ")", "->", "Tuple", "[", "bool", ",", "str", "]", ":" ]
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Check.run
Evaluates this check. Args: env: The prepared python environment to run the check in. verbose: When set, more progress output is produced. previous_failures: Checks that have already run and failed. Returns: A CheckResult instance.
dev_tools/check.py
def run(self, env: env_tools.PreparedEnv, verbose: bool, previous_failures: Set['Check']) -> CheckResult: """Evaluates this check. Args: env: The prepared python environment to run the check in. verbose: When set, more progress output is produ...
def run(self, env: env_tools.PreparedEnv, verbose: bool, previous_failures: Set['Check']) -> CheckResult: """Evaluates this check. Args: env: The prepared python environment to run the check in. verbose: When set, more progress output is produ...
[ "Evaluates", "this", "check", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/dev_tools/check.py#L77-L115
[ "def", "run", "(", "self", ",", "env", ":", "env_tools", ".", "PreparedEnv", ",", "verbose", ":", "bool", ",", "previous_failures", ":", "Set", "[", "'Check'", "]", ")", "->", "CheckResult", ":", "# Skip if a dependency failed.", "if", "previous_failures", "."...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Check.pick_env_and_run_and_report
Evaluates this check in python 3 or 2.7, and reports to github. If the prepared environments are not linked to a github repository, with a known access token, reporting to github is skipped. Args: env: A prepared python 3 environment. env_py2: A prepared python 2.7 envi...
dev_tools/check.py
def pick_env_and_run_and_report(self, env: env_tools.PreparedEnv, env_py2: Optional[env_tools.PreparedEnv], verbose: bool, previous_failures: Set['Check'] ...
def pick_env_and_run_and_report(self, env: env_tools.PreparedEnv, env_py2: Optional[env_tools.PreparedEnv], verbose: bool, previous_failures: Set['Check'] ...
[ "Evaluates", "this", "check", "in", "python", "3", "or", "2", ".", "7", "and", "reports", "to", "github", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/dev_tools/check.py#L117-L154
[ "def", "pick_env_and_run_and_report", "(", "self", ",", "env", ":", "env_tools", ".", "PreparedEnv", ",", "env_py2", ":", "Optional", "[", "env_tools", ".", "PreparedEnv", "]", ",", "verbose", ":", "bool", ",", "previous_failures", ":", "Set", "[", "'Check'", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
to_resolvers
Convert a Sweepable to a list of ParamResolvers.
cirq/study/sweepable.py
def to_resolvers(sweepable: Sweepable) -> List[ParamResolver]: """Convert a Sweepable to a list of ParamResolvers.""" if isinstance(sweepable, ParamResolver): return [sweepable] elif isinstance(sweepable, Sweep): return list(sweepable) elif isinstance(sweepable, collections.Iterable): ...
def to_resolvers(sweepable: Sweepable) -> List[ParamResolver]: """Convert a Sweepable to a list of ParamResolvers.""" if isinstance(sweepable, ParamResolver): return [sweepable] elif isinstance(sweepable, Sweep): return list(sweepable) elif isinstance(sweepable, collections.Iterable): ...
[ "Convert", "a", "Sweepable", "to", "a", "list", "of", "ParamResolvers", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/study/sweepable.py#L29-L40
[ "def", "to_resolvers", "(", "sweepable", ":", "Sweepable", ")", "->", "List", "[", "ParamResolver", "]", ":", "if", "isinstance", "(", "sweepable", ",", "ParamResolver", ")", ":", "return", "[", "sweepable", "]", "elif", "isinstance", "(", "sweepable", ",", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
is_parameterized
Returns whether the object is parameterized with any Symbols. A value is parameterized when it has an `_is_parameterized_` method and that method returns a truthy value, or if the value is an instance of sympy.Basic. Returns: True if the gate has any unresolved Symbols and False otherw...
cirq/protocols/resolve_parameters.py
def is_parameterized(val: Any) -> bool: """Returns whether the object is parameterized with any Symbols. A value is parameterized when it has an `_is_parameterized_` method and that method returns a truthy value, or if the value is an instance of sympy.Basic. Returns: True if the gate has ...
def is_parameterized(val: Any) -> bool: """Returns whether the object is parameterized with any Symbols. A value is parameterized when it has an `_is_parameterized_` method and that method returns a truthy value, or if the value is an instance of sympy.Basic. Returns: True if the gate has ...
[ "Returns", "whether", "the", "object", "is", "parameterized", "with", "any", "Symbols", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/protocols/resolve_parameters.py#L40-L62
[ "def", "is_parameterized", "(", "val", ":", "Any", ")", "->", "bool", ":", "if", "isinstance", "(", "val", ",", "sympy", ".", "Basic", ")", ":", "return", "True", "getter", "=", "getattr", "(", "val", ",", "'_is_parameterized_'", ",", "None", ")", "res...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
resolve_parameters
Resolves symbol parameters in the effect using the param resolver. This function will use the `_resolve_parameters_` magic method of `val` to resolve any Symbols with concrete values from the given parameter resolver. Args: val: The object to resolve (e.g. the gate, operation, etc) par...
cirq/protocols/resolve_parameters.py
def resolve_parameters( val: Any, param_resolver: 'cirq.ParamResolverOrSimilarType') -> Any: """Resolves symbol parameters in the effect using the param resolver. This function will use the `_resolve_parameters_` magic method of `val` to resolve any Symbols with concrete values from the giv...
def resolve_parameters( val: Any, param_resolver: 'cirq.ParamResolverOrSimilarType') -> Any: """Resolves symbol parameters in the effect using the param resolver. This function will use the `_resolve_parameters_` magic method of `val` to resolve any Symbols with concrete values from the giv...
[ "Resolves", "symbol", "parameters", "in", "the", "effect", "using", "the", "param", "resolver", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/protocols/resolve_parameters.py#L65-L99
[ "def", "resolve_parameters", "(", "val", ":", "Any", ",", "param_resolver", ":", "'cirq.ParamResolverOrSimilarType'", ")", "->", "Any", ":", "if", "not", "param_resolver", ":", "return", "val", "# Ensure its a dictionary wrapped in a ParamResolver.", "from", "cirq", "im...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
circuit_to_latex_using_qcircuit
Returns a QCircuit-based latex diagram of the given circuit. Args: circuit: The circuit to represent in latex. qubit_order: Determines the order of qubit wires in the diagram. Returns: Latex code for the diagram.
cirq/contrib/qcircuit/qcircuit_diagram.py
def circuit_to_latex_using_qcircuit( circuit: circuits.Circuit, qubit_order: ops.QubitOrderOrList = ops.QubitOrder.DEFAULT) -> str: """Returns a QCircuit-based latex diagram of the given circuit. Args: circuit: The circuit to represent in latex. qubit_order: Determines the order...
def circuit_to_latex_using_qcircuit( circuit: circuits.Circuit, qubit_order: ops.QubitOrderOrList = ops.QubitOrder.DEFAULT) -> str: """Returns a QCircuit-based latex diagram of the given circuit. Args: circuit: The circuit to represent in latex. qubit_order: Determines the order...
[ "Returns", "a", "QCircuit", "-", "based", "latex", "diagram", "of", "the", "given", "circuit", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/contrib/qcircuit/qcircuit_diagram.py#L62-L78
[ "def", "circuit_to_latex_using_qcircuit", "(", "circuit", ":", "circuits", ".", "Circuit", ",", "qubit_order", ":", "ops", ".", "QubitOrderOrList", "=", "ops", ".", "QubitOrder", ".", "DEFAULT", ")", "->", "str", ":", "diagram", "=", "circuit", ".", "to_text_d...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
kron
Computes the kronecker product of a sequence of matrices. A *args version of lambda args: functools.reduce(np.kron, args). Args: *matrices: The matrices and controls to combine with the kronecker product. Returns: The resulting matrix.
cirq/linalg/combinators.py
def kron(*matrices: np.ndarray) -> np.ndarray: """Computes the kronecker product of a sequence of matrices. A *args version of lambda args: functools.reduce(np.kron, args). Args: *matrices: The matrices and controls to combine with the kronecker product. Returns: The resul...
def kron(*matrices: np.ndarray) -> np.ndarray: """Computes the kronecker product of a sequence of matrices. A *args version of lambda args: functools.reduce(np.kron, args). Args: *matrices: The matrices and controls to combine with the kronecker product. Returns: The resul...
[ "Computes", "the", "kronecker", "product", "of", "a", "sequence", "of", "matrices", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/combinators.py#L23-L38
[ "def", "kron", "(", "*", "matrices", ":", "np", ".", "ndarray", ")", "->", "np", ".", "ndarray", ":", "product", "=", "np", ".", "eye", "(", "1", ")", "for", "m", "in", "matrices", ":", "product", "=", "np", ".", "kron", "(", "product", ",", "m...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
kron_with_controls
Computes the kronecker product of a sequence of matrices and controls. Use linalg.CONTROL_TAG to represent controls. Any entry of the output matrix corresponding to a situation where the control is not satisfied will be overwritten by identity matrix elements. The control logic works by imbuing NaN wi...
cirq/linalg/combinators.py
def kron_with_controls(*matrices: np.ndarray) -> np.ndarray: """Computes the kronecker product of a sequence of matrices and controls. Use linalg.CONTROL_TAG to represent controls. Any entry of the output matrix corresponding to a situation where the control is not satisfied will be overwritten by iden...
def kron_with_controls(*matrices: np.ndarray) -> np.ndarray: """Computes the kronecker product of a sequence of matrices and controls. Use linalg.CONTROL_TAG to represent controls. Any entry of the output matrix corresponding to a situation where the control is not satisfied will be overwritten by iden...
[ "Computes", "the", "kronecker", "product", "of", "a", "sequence", "of", "matrices", "and", "controls", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/combinators.py#L44-L77
[ "def", "kron_with_controls", "(", "*", "matrices", ":", "np", ".", "ndarray", ")", "->", "np", ".", "ndarray", ":", "product", "=", "kron", "(", "*", "matrices", ")", "# The NaN from CONTROL_TAG spreads to everywhere identity belongs.", "for", "i", "in", "range", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
dot
Computes the dot/matrix product of a sequence of values. A *args version of np.linalg.multi_dot. Args: *values: The values to combine with the dot/matrix product. Returns: The resulting value or matrix.
cirq/linalg/combinators.py
def dot(*values: Union[float, complex, np.ndarray] ) -> Union[float, complex, np.ndarray]: """Computes the dot/matrix product of a sequence of values. A *args version of np.linalg.multi_dot. Args: *values: The values to combine with the dot/matrix product. Returns: The resulti...
def dot(*values: Union[float, complex, np.ndarray] ) -> Union[float, complex, np.ndarray]: """Computes the dot/matrix product of a sequence of values. A *args version of np.linalg.multi_dot. Args: *values: The values to combine with the dot/matrix product. Returns: The resulti...
[ "Computes", "the", "dot", "/", "matrix", "product", "of", "a", "sequence", "of", "values", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/combinators.py#L80-L96
[ "def", "dot", "(", "*", "values", ":", "Union", "[", "float", ",", "complex", ",", "np", ".", "ndarray", "]", ")", "->", "Union", "[", "float", ",", "complex", ",", "np", ".", "ndarray", "]", ":", "if", "len", "(", "values", ")", "==", "1", ":"...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
block_diag
Concatenates blocks into a block diagonal matrix. Args: *blocks: Square matrices to place along the diagonal of the result. Returns: A block diagonal matrix with the given blocks along its diagonal. Raises: ValueError: A block isn't square.
cirq/linalg/combinators.py
def block_diag(*blocks: np.ndarray) -> np.ndarray: """Concatenates blocks into a block diagonal matrix. Args: *blocks: Square matrices to place along the diagonal of the result. Returns: A block diagonal matrix with the given blocks along its diagonal. Raises: ValueError: A bl...
def block_diag(*blocks: np.ndarray) -> np.ndarray: """Concatenates blocks into a block diagonal matrix. Args: *blocks: Square matrices to place along the diagonal of the result. Returns: A block diagonal matrix with the given blocks along its diagonal. Raises: ValueError: A bl...
[ "Concatenates", "blocks", "into", "a", "block", "diagonal", "matrix", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/combinators.py#L104-L133
[ "def", "block_diag", "(", "*", "blocks", ":", "np", ".", "ndarray", ")", "->", "np", ".", "ndarray", ":", "for", "b", "in", "blocks", ":", "if", "b", ".", "shape", "[", "0", "]", "!=", "b", ".", "shape", "[", "1", "]", ":", "raise", "ValueError...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
index_2d
Finds the first index of a target item within a list of lists. Args: seqs: The list of lists to search. target: The item to find. Raises: ValueError: Item is not present.
cirq/google/line/placement/anneal.py
def index_2d(seqs: List[List[Any]], target: Any) -> Tuple[int, int]: """Finds the first index of a target item within a list of lists. Args: seqs: The list of lists to search. target: The item to find. Raises: ValueError: Item is not present. """ for i in range(len(seqs)): ...
def index_2d(seqs: List[List[Any]], target: Any) -> Tuple[int, int]: """Finds the first index of a target item within a list of lists. Args: seqs: The list of lists to search. target: The item to find. Raises: ValueError: Item is not present. """ for i in range(len(seqs)): ...
[ "Finds", "the", "first", "index", "of", "a", "target", "item", "within", "a", "list", "of", "lists", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L387-L401
[ "def", "index_2d", "(", "seqs", ":", "List", "[", "List", "[", "Any", "]", "]", ",", "target", ":", "Any", ")", "->", "Tuple", "[", "int", ",", "int", "]", ":", "for", "i", "in", "range", "(", "len", "(", "seqs", ")", ")", ":", "for", "j", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearch.search
Issues new linear sequence search. Each call to this method starts new search. Args: trace_func: Optional callable which will be called for each simulated annealing step with arguments: solution candidate (list of linear sequences on the chip), current temperature (fl...
cirq/google/line/placement/anneal.py
def search( self, trace_func: Callable[ [List[LineSequence], float, float, float, bool], None] = None) -> List[LineSequence]: """Issues new linear sequence search. Each call to this method starts new search. Args: trace_func: Op...
def search( self, trace_func: Callable[ [List[LineSequence], float, float, float, bool], None] = None) -> List[LineSequence]: """Issues new linear sequence search. Each call to this method starts new search. Args: trace_func: Op...
[ "Issues", "new", "linear", "sequence", "search", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L54-L86
[ "def", "search", "(", "self", ",", "trace_func", ":", "Callable", "[", "[", "List", "[", "LineSequence", "]", ",", "float", ",", "float", ",", "float", ",", "bool", "]", ",", "None", "]", "=", "None", ")", "->", "List", "[", "LineSequence", "]", ":...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearch._quadratic_sum_cost
Cost function that sums squares of lengths of sequences. Args: state: Search state, not mutated. Returns: Cost which is minus the normalized quadratic sum of each linear sequence section in the state. This promotes single, long linear sequence solutions and conv...
cirq/google/line/placement/anneal.py
def _quadratic_sum_cost(self, state: _STATE) -> float: """Cost function that sums squares of lengths of sequences. Args: state: Search state, not mutated. Returns: Cost which is minus the normalized quadratic sum of each linear sequence section in the state. This ...
def _quadratic_sum_cost(self, state: _STATE) -> float: """Cost function that sums squares of lengths of sequences. Args: state: Search state, not mutated. Returns: Cost which is minus the normalized quadratic sum of each linear sequence section in the state. This ...
[ "Cost", "function", "that", "sums", "squares", "of", "lengths", "of", "sequences", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L88-L106
[ "def", "_quadratic_sum_cost", "(", "self", ",", "state", ":", "_STATE", ")", "->", "float", ":", "cost", "=", "0.0", "total_len", "=", "float", "(", "len", "(", "self", ".", "_c", ")", ")", "seqs", ",", "_", "=", "state", "for", "seq", "in", "seqs"...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearch._force_edges_active_move
Move function which repeats _force_edge_active_move a few times. Args: state: Search state, not mutated. Returns: New search state which consists of incremental changes of the original state.
cirq/google/line/placement/anneal.py
def _force_edges_active_move(self, state: _STATE) -> _STATE: """Move function which repeats _force_edge_active_move a few times. Args: state: Search state, not mutated. Returns: New search state which consists of incremental changes of the original state. ...
def _force_edges_active_move(self, state: _STATE) -> _STATE: """Move function which repeats _force_edge_active_move a few times. Args: state: Search state, not mutated. Returns: New search state which consists of incremental changes of the original state. ...
[ "Move", "function", "which", "repeats", "_force_edge_active_move", "a", "few", "times", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L108-L120
[ "def", "_force_edges_active_move", "(", "self", ",", "state", ":", "_STATE", ")", "->", "_STATE", ":", "for", "_", "in", "range", "(", "self", ".", "_rand", ".", "randint", "(", "1", ",", "4", ")", ")", ":", "state", "=", "self", ".", "_force_edge_ac...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearch._force_edge_active_move
Move which forces a random edge to appear on some sequence. This move chooses random edge from the edges which do not belong to any sequence and modifies state in such a way, that this chosen edge appears on some sequence of the search state. Args: state: Search state, not mu...
cirq/google/line/placement/anneal.py
def _force_edge_active_move(self, state: _STATE) -> _STATE: """Move which forces a random edge to appear on some sequence. This move chooses random edge from the edges which do not belong to any sequence and modifies state in such a way, that this chosen edge appears on some sequence of...
def _force_edge_active_move(self, state: _STATE) -> _STATE: """Move which forces a random edge to appear on some sequence. This move chooses random edge from the edges which do not belong to any sequence and modifies state in such a way, that this chosen edge appears on some sequence of...
[ "Move", "which", "forces", "a", "random", "edge", "to", "appear", "on", "some", "sequence", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L122-L152
[ "def", "_force_edge_active_move", "(", "self", ",", "state", ":", "_STATE", ")", "->", "_STATE", ":", "seqs", ",", "edges", "=", "state", "unused_edges", "=", "edges", ".", "copy", "(", ")", "# List edges which do not belong to any linear sequence.", "for", "seq",...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearch._force_edge_active
Move which forces given edge to appear on some sequence. Args: seqs: List of linear sequences covering chip. edge: Edge to be activated. sample_bool: Callable returning random bool. Returns: New list of linear sequences with given edge on some of the s...
cirq/google/line/placement/anneal.py
def _force_edge_active(self, seqs: List[List[GridQubit]], edge: EDGE, sample_bool: Callable[[], bool] ) -> List[List[GridQubit]]: """Move which forces given edge to appear on some sequence. Args: seqs: List of linear sequences covering chi...
def _force_edge_active(self, seqs: List[List[GridQubit]], edge: EDGE, sample_bool: Callable[[], bool] ) -> List[List[GridQubit]]: """Move which forces given edge to appear on some sequence. Args: seqs: List of linear sequences covering chi...
[ "Move", "which", "forces", "given", "edge", "to", "appear", "on", "some", "sequence", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L154-L245
[ "def", "_force_edge_active", "(", "self", ",", "seqs", ":", "List", "[", "List", "[", "GridQubit", "]", "]", ",", "edge", ":", "EDGE", ",", "sample_bool", ":", "Callable", "[", "[", "]", ",", "bool", "]", ")", "->", "List", "[", "List", "[", "GridQ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearch._create_initial_solution
Creates initial solution based on the chip description. Initial solution is constructed in a greedy way. Returns: Valid search state.
cirq/google/line/placement/anneal.py
def _create_initial_solution(self) -> _STATE: """Creates initial solution based on the chip description. Initial solution is constructed in a greedy way. Returns: Valid search state. """ def extract_sequences() -> List[List[GridQubit]]: """Creates list of...
def _create_initial_solution(self) -> _STATE: """Creates initial solution based on the chip description. Initial solution is constructed in a greedy way. Returns: Valid search state. """ def extract_sequences() -> List[List[GridQubit]]: """Creates list of...
[ "Creates", "initial", "solution", "based", "on", "the", "chip", "description", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L247-L297
[ "def", "_create_initial_solution", "(", "self", ")", "->", "_STATE", ":", "def", "extract_sequences", "(", ")", "->", "List", "[", "List", "[", "GridQubit", "]", "]", ":", "\"\"\"Creates list of sequcenes for initial state.\n\n Returns:\n List of lis...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearch._normalize_edge
Gives unique representative of the edge. Two edges are equivalent if they form an edge between the same nodes. This method returns representative of this edge which can be compared using equality operator later. Args: edge: Edge to normalize. Returns: Norma...
cirq/google/line/placement/anneal.py
def _normalize_edge(self, edge: EDGE) -> EDGE: """Gives unique representative of the edge. Two edges are equivalent if they form an edge between the same nodes. This method returns representative of this edge which can be compared using equality operator later. Args: ...
def _normalize_edge(self, edge: EDGE) -> EDGE: """Gives unique representative of the edge. Two edges are equivalent if they form an edge between the same nodes. This method returns representative of this edge which can be compared using equality operator later. Args: ...
[ "Gives", "unique", "representative", "of", "the", "edge", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L299-L318
[ "def", "_normalize_edge", "(", "self", ",", "edge", ":", "EDGE", ")", "->", "EDGE", ":", "def", "lower", "(", "n", ":", "GridQubit", ",", "m", ":", "GridQubit", ")", "->", "bool", ":", "return", "n", ".", "row", "<", "m", ".", "row", "or", "(", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearch._choose_random_edge
Picks random edge from the set of edges. Args: edges: Set of edges to pick from. Returns: Random edge from the supplied set, or None for empty set.
cirq/google/line/placement/anneal.py
def _choose_random_edge(self, edges: Set[EDGE]) -> Optional[EDGE]: """Picks random edge from the set of edges. Args: edges: Set of edges to pick from. Returns: Random edge from the supplied set, or None for empty set. """ if edges: index = self._...
def _choose_random_edge(self, edges: Set[EDGE]) -> Optional[EDGE]: """Picks random edge from the set of edges. Args: edges: Set of edges to pick from. Returns: Random edge from the supplied set, or None for empty set. """ if edges: index = self._...
[ "Picks", "random", "edge", "from", "the", "set", "of", "edges", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L320-L335
[ "def", "_choose_random_edge", "(", "self", ",", "edges", ":", "Set", "[", "EDGE", "]", ")", "->", "Optional", "[", "EDGE", "]", ":", "if", "edges", ":", "index", "=", "self", ".", "_rand", ".", "randint", "(", "len", "(", "edges", ")", ")", "for", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
AnnealSequenceSearchStrategy.place_line
Runs line sequence search. Args: device: Chip description. length: Required line length. Returns: List of linear sequences on the chip found by simulated annealing method.
cirq/google/line/placement/anneal.py
def place_line(self, device: 'cirq.google.XmonDevice', length: int) -> GridQubitLineTuple: """Runs line sequence search. Args: device: Chip description. length: Required line length. Returns: List of linear sequences on ...
def place_line(self, device: 'cirq.google.XmonDevice', length: int) -> GridQubitLineTuple: """Runs line sequence search. Args: device: Chip description. length: Required line length. Returns: List of linear sequences on ...
[ "Runs", "line", "sequence", "search", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/line/placement/anneal.py#L370-L384
[ "def", "place_line", "(", "self", ",", "device", ":", "'cirq.google.XmonDevice'", ",", "length", ":", "int", ")", "->", "GridQubitLineTuple", ":", "seqs", "=", "AnnealSequenceSearch", "(", "device", ",", "self", ".", "seed", ")", ".", "search", "(", "self", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
CCZPowGate._decompose_
An adjacency-respecting decomposition. 0: ───p───@──────────────@───────@──────────@────────── │ │ │ │ 1: ───p───X───@───p^-1───X───@───X──────@───X──────@─── │ │ │ │ 2: ───p───────X───p──────────...
cirq/ops/three_qubit_gates.py
def _decompose_(self, qubits): """An adjacency-respecting decomposition. 0: ───p───@──────────────@───────@──────────@────────── │ │ │ │ 1: ───p───X───@───p^-1───X───@───X──────@───X──────@─── │ │ │ ...
def _decompose_(self, qubits): """An adjacency-respecting decomposition. 0: ───p───@──────────────@───────@──────────@────────── │ │ │ │ 1: ───p───X───@───p^-1───X───@───X──────@───X──────@─── │ │ │ ...
[ "An", "adjacency", "-", "respecting", "decomposition", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/three_qubit_gates.py#L65-L101
[ "def", "_decompose_", "(", "self", ",", "qubits", ")", ":", "if", "protocols", ".", "is_parameterized", "(", "self", ")", ":", "return", "NotImplemented", "a", ",", "b", ",", "c", "=", "qubits", "# Hacky magic: avoid the non-adjacent edge.", "if", "hasattr", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
CSwapGate._decompose_inside_control
A decomposition assuming the control separates the targets. target1: ─@─X───────T──────@────────@─────────X───@─────X^-0.5─ │ │ │ │ │ │ control: ─X─@─X─────@─T^-1─X─@─T────X─@─X^0.5─@─@─X─@────────── │ │ │ │ ...
cirq/ops/three_qubit_gates.py
def _decompose_inside_control(self, target1: raw_types.Qid, control: raw_types.Qid, target2: raw_types.Qid ) -> op_tree.OP_TREE: """A decomposition assuming the control separat...
def _decompose_inside_control(self, target1: raw_types.Qid, control: raw_types.Qid, target2: raw_types.Qid ) -> op_tree.OP_TREE: """A decomposition assuming the control separat...
[ "A", "decomposition", "assuming", "the", "control", "separates", "the", "targets", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/three_qubit_gates.py#L272-L309
[ "def", "_decompose_inside_control", "(", "self", ",", "target1", ":", "raw_types", ".", "Qid", ",", "control", ":", "raw_types", ".", "Qid", ",", "target2", ":", "raw_types", ".", "Qid", ")", "->", "op_tree", ".", "OP_TREE", ":", "a", ",", "b", ",", "c...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
CSwapGate._decompose_outside_control
A decomposition assuming one of the targets is in the middle. control: ───T──────@────────@───@────────────@──────────────── │ │ │ │ near: ─X─T──────X─@─T^-1─X─@─X────@─X^0.5─X─@─X^0.5──────── │ │ │ │ │ ...
cirq/ops/three_qubit_gates.py
def _decompose_outside_control(self, control: raw_types.Qid, near_target: raw_types.Qid, far_target: raw_types.Qid ) -> op_tree.OP_TREE: """A decomposition assuming one of ...
def _decompose_outside_control(self, control: raw_types.Qid, near_target: raw_types.Qid, far_target: raw_types.Qid ) -> op_tree.OP_TREE: """A decomposition assuming one of ...
[ "A", "decomposition", "assuming", "one", "of", "the", "targets", "is", "in", "the", "middle", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/ops/three_qubit_gates.py#L320-L352
[ "def", "_decompose_outside_control", "(", "self", ",", "control", ":", "raw_types", ".", "Qid", ",", "near_target", ":", "raw_types", ".", "Qid", ",", "far_target", ":", "raw_types", ".", "Qid", ")", "->", "op_tree", ".", "OP_TREE", ":", "a", ",", "b", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
mixture
Return a sequence of tuples representing a probabilistic combination. A mixture is described by an iterable of tuples of the form (probability of object, object) The probability components of the tuples must sum to 1.0 and be between 0 and 1 (inclusive). Args: val: The value whose mi...
cirq/protocols/mixture.py
def mixture( val: Any, default: Any = RaiseTypeErrorIfNotProvided) -> Sequence[Tuple[float, Any]]: """Return a sequence of tuples representing a probabilistic combination. A mixture is described by an iterable of tuples of the form (probability of object, object) The probability component...
def mixture( val: Any, default: Any = RaiseTypeErrorIfNotProvided) -> Sequence[Tuple[float, Any]]: """Return a sequence of tuples representing a probabilistic combination. A mixture is described by an iterable of tuples of the form (probability of object, object) The probability component...
[ "Return", "a", "sequence", "of", "tuples", "representing", "a", "probabilistic", "combination", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/protocols/mixture.py#L62-L97
[ "def", "mixture", "(", "val", ":", "Any", ",", "default", ":", "Any", "=", "RaiseTypeErrorIfNotProvided", ")", "->", "Sequence", "[", "Tuple", "[", "float", ",", "Any", "]", "]", ":", "getter", "=", "getattr", "(", "val", ",", "'_mixture_'", ",", "None...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
has_mixture
Returns whether the value has a mixture representation. Returns: If `val` has a `_has_mixture_` method and its result is not NotImplemented, that result is returned. Otherwise, if the value has a `_mixture_` method return True if that has a non-default value. Returns False if neithe...
cirq/protocols/mixture.py
def has_mixture(val: Any) -> bool: """Returns whether the value has a mixture representation. Returns: If `val` has a `_has_mixture_` method and its result is not NotImplemented, that result is returned. Otherwise, if the value has a `_mixture_` method return True if that has a non-defa...
def has_mixture(val: Any) -> bool: """Returns whether the value has a mixture representation. Returns: If `val` has a `_has_mixture_` method and its result is not NotImplemented, that result is returned. Otherwise, if the value has a `_mixture_` method return True if that has a non-defa...
[ "Returns", "whether", "the", "value", "has", "a", "mixture", "representation", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/protocols/mixture.py#L100-L115
[ "def", "has_mixture", "(", "val", ":", "Any", ")", "->", "bool", ":", "getter", "=", "getattr", "(", "val", ",", "'_has_mixture_'", ",", "None", ")", "result", "=", "NotImplemented", "if", "getter", "is", "None", "else", "getter", "(", ")", "if", "resu...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
mixture_channel
Return a sequence of tuples for a channel that is a mixture of unitaries. In contrast to `mixture` this method falls back to `unitary` if `_mixture_` is not implemented. A mixture channel is described by an iterable of tuples of the form (probability of unitary, unitary) The probability comp...
cirq/protocols/mixture.py
def mixture_channel( val: Any, default: Any = RaiseTypeErrorIfNotProvided) -> Sequence[ Tuple[float, np.ndarray]]: """Return a sequence of tuples for a channel that is a mixture of unitaries. In contrast to `mixture` this method falls back to `unitary` if `_mixture_` is not implemented. A ...
def mixture_channel( val: Any, default: Any = RaiseTypeErrorIfNotProvided) -> Sequence[ Tuple[float, np.ndarray]]: """Return a sequence of tuples for a channel that is a mixture of unitaries. In contrast to `mixture` this method falls back to `unitary` if `_mixture_` is not implemented. A ...
[ "Return", "a", "sequence", "of", "tuples", "for", "a", "channel", "that", "is", "a", "mixture", "of", "unitaries", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/protocols/mixture.py#L118-L162
[ "def", "mixture_channel", "(", "val", ":", "Any", ",", "default", ":", "Any", "=", "RaiseTypeErrorIfNotProvided", ")", "->", "Sequence", "[", "Tuple", "[", "float", ",", "np", ".", "ndarray", "]", "]", ":", "mixture_getter", "=", "getattr", "(", "val", "...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
has_mixture_channel
Returns whether the value has a mixture channel representation. In contrast to `has_mixture` this method falls back to checking whether the value has a unitary representation via `has_channel`. Returns: If `val` has a `_has_mixture_` method and its result is not NotImplemented, that result...
cirq/protocols/mixture.py
def has_mixture_channel(val: Any) -> bool: """Returns whether the value has a mixture channel representation. In contrast to `has_mixture` this method falls back to checking whether the value has a unitary representation via `has_channel`. Returns: If `val` has a `_has_mixture_` method and its...
def has_mixture_channel(val: Any) -> bool: """Returns whether the value has a mixture channel representation. In contrast to `has_mixture` this method falls back to checking whether the value has a unitary representation via `has_channel`. Returns: If `val` has a `_has_mixture_` method and its...
[ "Returns", "whether", "the", "value", "has", "a", "mixture", "channel", "representation", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/protocols/mixture.py#L165-L189
[ "def", "has_mixture_channel", "(", "val", ":", "Any", ")", "->", "bool", ":", "mixture_getter", "=", "getattr", "(", "val", ",", "'_has_mixture_'", ",", "None", ")", "result", "=", "NotImplemented", "if", "mixture_getter", "is", "None", "else", "mixture_getter...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
validate_mixture
Validates that the mixture's tuple are valid probabilities.
cirq/protocols/mixture.py
def validate_mixture(supports_mixture: SupportsMixture): """Validates that the mixture's tuple are valid probabilities.""" mixture_tuple = mixture(supports_mixture, None) if mixture_tuple is None: raise TypeError('{}_mixture did not have a _mixture_ method'.format( supports_mixture)) ...
def validate_mixture(supports_mixture: SupportsMixture): """Validates that the mixture's tuple are valid probabilities.""" mixture_tuple = mixture(supports_mixture, None) if mixture_tuple is None: raise TypeError('{}_mixture did not have a _mixture_ method'.format( supports_mixture)) ...
[ "Validates", "that", "the", "mixture", "s", "tuple", "are", "valid", "probabilities", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/protocols/mixture.py#L192-L210
[ "def", "validate_mixture", "(", "supports_mixture", ":", "SupportsMixture", ")", ":", "mixture_tuple", "=", "mixture", "(", "supports_mixture", ",", "None", ")", "if", "mixture_tuple", "is", "None", ":", "raise", "TypeError", "(", "'{}_mixture did not have a _mixture_...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
SimulatesIntermediateWaveFunction.compute_displays
Computes displays in the supplied Circuit or Schedule. Args: program: The circuit or schedule to simulate. param_resolver: Parameters to run with the program. qubit_order: Determines the canonical ordering of the qubits used to define the order of amplitudes ...
cirq/sim/wave_function_simulator.py
def compute_displays( self, program: Union[circuits.Circuit, schedules.Schedule], param_resolver: study.ParamResolver = study.ParamResolver({}), qubit_order: ops.QubitOrderOrList = ops.QubitOrder.DEFAULT, initial_state: Union[int, np.ndarray] = 0, ) -> study.ComputeDisplaysRe...
def compute_displays( self, program: Union[circuits.Circuit, schedules.Schedule], param_resolver: study.ParamResolver = study.ParamResolver({}), qubit_order: ops.QubitOrderOrList = ops.QubitOrder.DEFAULT, initial_state: Union[int, np.ndarray] = 0, ) -> study.ComputeDisplaysRe...
[ "Computes", "displays", "in", "the", "supplied", "Circuit", "or", "Schedule", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/sim/wave_function_simulator.py#L70-L94
[ "def", "compute_displays", "(", "self", ",", "program", ":", "Union", "[", "circuits", ".", "Circuit", ",", "schedules", ".", "Schedule", "]", ",", "param_resolver", ":", "study", ".", "ParamResolver", "=", "study", ".", "ParamResolver", "(", "{", "}", ")"...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
ensure_pool
Decorator that ensures a pool is available for a stepper.
cirq/google/sim/xmon_stepper.py
def ensure_pool(func): """Decorator that ensures a pool is available for a stepper.""" def func_wrapper(*args, **kwargs): if len(args) == 0 or not isinstance(args[0], Stepper): raise Exception('@ensure_pool can only be used on Stepper methods.') if args[0]._pool is None: ...
def ensure_pool(func): """Decorator that ensures a pool is available for a stepper.""" def func_wrapper(*args, **kwargs): if len(args) == 0 or not isinstance(args[0], Stepper): raise Exception('@ensure_pool can only be used on Stepper methods.') if args[0]._pool is None: ...
[ "Decorator", "that", "ensures", "a", "pool", "is", "available", "for", "a", "stepper", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L36-L46
[ "def", "ensure_pool", "(", "func", ")", ":", "def", "func_wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "len", "(", "args", ")", "==", "0", "or", "not", "isinstance", "(", "args", "[", "0", "]", ",", "Stepper", ")", ":", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_single_qubit_accumulate_into_scratch
Accumulates single qubit phase gates into the scratch shards.
cirq/google/sim/xmon_stepper.py
def _single_qubit_accumulate_into_scratch(args: Dict[str, Any]): """Accumulates single qubit phase gates into the scratch shards.""" index = args['indices'][0] shard_num = args['shard_num'] half_turns = args['half_turns'] num_shard_qubits = args['num_shard_qubits'] scratch = _scratch_shard(args)...
def _single_qubit_accumulate_into_scratch(args: Dict[str, Any]): """Accumulates single qubit phase gates into the scratch shards.""" index = args['indices'][0] shard_num = args['shard_num'] half_turns = args['half_turns'] num_shard_qubits = args['num_shard_qubits'] scratch = _scratch_shard(args)...
[ "Accumulates", "single", "qubit", "phase", "gates", "into", "the", "scratch", "shards", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L432-L447
[ "def", "_single_qubit_accumulate_into_scratch", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", ":", "index", "=", "args", "[", "'indices'", "]", "[", "0", "]", "shard_num", "=", "args", "[", "'shard_num'", "]", "half_turns", "=", "args", "["...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_one_projector
Returns a projector onto the |1> subspace of the index-th qubit.
cirq/google/sim/xmon_stepper.py
def _one_projector(args: Dict[str, Any], index: int) -> Union[int, np.ndarray]: """Returns a projector onto the |1> subspace of the index-th qubit.""" num_shard_qubits = args['num_shard_qubits'] shard_num = args['shard_num'] if index >= num_shard_qubits: return _kth_bit(shard_num, index - num_sh...
def _one_projector(args: Dict[str, Any], index: int) -> Union[int, np.ndarray]: """Returns a projector onto the |1> subspace of the index-th qubit.""" num_shard_qubits = args['num_shard_qubits'] shard_num = args['shard_num'] if index >= num_shard_qubits: return _kth_bit(shard_num, index - num_sh...
[ "Returns", "a", "projector", "onto", "the", "|1", ">", "subspace", "of", "the", "index", "-", "th", "qubit", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L450-L456
[ "def", "_one_projector", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ",", "index", ":", "int", ")", "->", "Union", "[", "int", ",", "np", ".", "ndarray", "]", ":", "num_shard_qubits", "=", "args", "[", "'num_shard_qubits'", "]", "shard_num",...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_two_qubit_accumulate_into_scratch
Accumulates two qubit phase gates into the scratch shards.
cirq/google/sim/xmon_stepper.py
def _two_qubit_accumulate_into_scratch(args: Dict[str, Any]): """Accumulates two qubit phase gates into the scratch shards.""" index0, index1 = args['indices'] half_turns = args['half_turns'] scratch = _scratch_shard(args) projector = _one_projector(args, index0) * _one_projector(args, index1) ...
def _two_qubit_accumulate_into_scratch(args: Dict[str, Any]): """Accumulates two qubit phase gates into the scratch shards.""" index0, index1 = args['indices'] half_turns = args['half_turns'] scratch = _scratch_shard(args) projector = _one_projector(args, index0) * _one_projector(args, index1) ...
[ "Accumulates", "two", "qubit", "phase", "gates", "into", "the", "scratch", "shards", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L459-L468
[ "def", "_two_qubit_accumulate_into_scratch", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", ":", "index0", ",", "index1", "=", "args", "[", "'indices'", "]", "half_turns", "=", "args", "[", "'half_turns'", "]", "scratch", "=", "_scratch_shard", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_apply_scratch_as_phase
Takes scratch shards and applies them as exponentiated phase to state.
cirq/google/sim/xmon_stepper.py
def _apply_scratch_as_phase(args: Dict[str, Any]): """Takes scratch shards and applies them as exponentiated phase to state. """ state = _state_shard(args) state *= np.exp(I_PI_OVER_2 * _scratch_shard(args))
def _apply_scratch_as_phase(args: Dict[str, Any]): """Takes scratch shards and applies them as exponentiated phase to state. """ state = _state_shard(args) state *= np.exp(I_PI_OVER_2 * _scratch_shard(args))
[ "Takes", "scratch", "shards", "and", "applies", "them", "as", "exponentiated", "phase", "to", "state", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L471-L475
[ "def", "_apply_scratch_as_phase", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", ":", "state", "=", "_state_shard", "(", "args", ")", "state", "*=", "np", ".", "exp", "(", "I_PI_OVER_2", "*", "_scratch_shard", "(", "args", ")", ")" ]
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_w_within_shard
Applies a W gate when the gate acts only within a shard.
cirq/google/sim/xmon_stepper.py
def _w_within_shard(args: Dict[str, Any]): """Applies a W gate when the gate acts only within a shard.""" index = args['index'] half_turns = args['half_turns'] axis_half_turns = args['axis_half_turns'] state = _state_shard(args) pm_vect = _pm_vects(args)[index] num_shard_qubits = args['num_s...
def _w_within_shard(args: Dict[str, Any]): """Applies a W gate when the gate acts only within a shard.""" index = args['index'] half_turns = args['half_turns'] axis_half_turns = args['axis_half_turns'] state = _state_shard(args) pm_vect = _pm_vects(args)[index] num_shard_qubits = args['num_s...
[ "Applies", "a", "W", "gate", "when", "the", "gate", "acts", "only", "within", "a", "shard", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L478-L499
[ "def", "_w_within_shard", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", ":", "index", "=", "args", "[", "'index'", "]", "half_turns", "=", "args", "[", "'half_turns'", "]", "axis_half_turns", "=", "args", "[", "'axis_half_turns'", "]", "sta...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_w_between_shards
Applies a W gate when the gate acts between shards.
cirq/google/sim/xmon_stepper.py
def _w_between_shards(args: Dict[str, Any]): """Applies a W gate when the gate acts between shards.""" shard_num = args['shard_num'] state = _state_shard(args) num_shard_qubits = args['num_shard_qubits'] index = args['index'] half_turns = args['half_turns'] axis_half_turns = args['axis_half...
def _w_between_shards(args: Dict[str, Any]): """Applies a W gate when the gate acts between shards.""" shard_num = args['shard_num'] state = _state_shard(args) num_shard_qubits = args['num_shard_qubits'] index = args['index'] half_turns = args['half_turns'] axis_half_turns = args['axis_half...
[ "Applies", "a", "W", "gate", "when", "the", "gate", "acts", "between", "shards", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L502-L525
[ "def", "_w_between_shards", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", ":", "shard_num", "=", "args", "[", "'shard_num'", "]", "state", "=", "_state_shard", "(", "args", ")", "num_shard_qubits", "=", "args", "[", "'num_shard_qubits'", "]",...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_copy_scratch_to_state
Copes scratch shards to state shards.
cirq/google/sim/xmon_stepper.py
def _copy_scratch_to_state(args: Dict[str, Any]): """Copes scratch shards to state shards.""" np.copyto(_state_shard(args), _scratch_shard(args))
def _copy_scratch_to_state(args: Dict[str, Any]): """Copes scratch shards to state shards.""" np.copyto(_state_shard(args), _scratch_shard(args))
[ "Copes", "scratch", "shards", "to", "state", "shards", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L528-L530
[ "def", "_copy_scratch_to_state", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", ":", "np", ".", "copyto", "(", "_state_shard", "(", "args", ")", ",", "_scratch_shard", "(", "args", ")", ")" ]
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_one_prob_per_shard
Returns the probability of getting a one measurement on a state shard.
cirq/google/sim/xmon_stepper.py
def _one_prob_per_shard(args: Dict[str, Any]) -> float: """Returns the probability of getting a one measurement on a state shard. """ index = args['index'] state = _state_shard(args) * _one_projector(args, index) norm = np.linalg.norm(state) return norm * norm
def _one_prob_per_shard(args: Dict[str, Any]) -> float: """Returns the probability of getting a one measurement on a state shard. """ index = args['index'] state = _state_shard(args) * _one_projector(args, index) norm = np.linalg.norm(state) return norm * norm
[ "Returns", "the", "probability", "of", "getting", "a", "one", "measurement", "on", "a", "state", "shard", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L533-L540
[ "def", "_one_prob_per_shard", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", "->", "float", ":", "index", "=", "args", "[", "'index'", "]", "state", "=", "_state_shard", "(", "args", ")", "*", "_one_projector", "(", "args", ",", "index", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_norm_squared
Returns the norm for each state shard.
cirq/google/sim/xmon_stepper.py
def _norm_squared(args: Dict[str, Any]) -> float: """Returns the norm for each state shard.""" state = _state_shard(args) return np.sum(np.abs(state) ** 2)
def _norm_squared(args: Dict[str, Any]) -> float: """Returns the norm for each state shard.""" state = _state_shard(args) return np.sum(np.abs(state) ** 2)
[ "Returns", "the", "norm", "for", "each", "state", "shard", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L543-L546
[ "def", "_norm_squared", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", "->", "float", ":", "state", "=", "_state_shard", "(", "args", ")", "return", "np", ".", "sum", "(", "np", ".", "abs", "(", "state", ")", "**", "2", ")" ]
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_renorm
Renormalizes the state using the norm arg.
cirq/google/sim/xmon_stepper.py
def _renorm(args: Dict[str, Any]): """Renormalizes the state using the norm arg.""" state = _state_shard(args) # If our gate is so bad that we have norm of zero, we have bigger problems. state /= np.sqrt(args['norm_squared'])
def _renorm(args: Dict[str, Any]): """Renormalizes the state using the norm arg.""" state = _state_shard(args) # If our gate is so bad that we have norm of zero, we have bigger problems. state /= np.sqrt(args['norm_squared'])
[ "Renormalizes", "the", "state", "using", "the", "norm", "arg", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L549-L553
[ "def", "_renorm", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", ":", "state", "=", "_state_shard", "(", "args", ")", "# If our gate is so bad that we have norm of zero, we have bigger problems.", "state", "/=", "np", ".", "sqrt", "(", "args", "[", ...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
_collapse_state
Projects state shards onto the appropriate post measurement state. This function makes no assumptions about the interpretation of quantum theory. Args: args: The args from shard_num_args.
cirq/google/sim/xmon_stepper.py
def _collapse_state(args: Dict[str, Any]): """Projects state shards onto the appropriate post measurement state. This function makes no assumptions about the interpretation of quantum theory. Args: args: The args from shard_num_args. """ index = args['index'] result = args['result'...
def _collapse_state(args: Dict[str, Any]): """Projects state shards onto the appropriate post measurement state. This function makes no assumptions about the interpretation of quantum theory. Args: args: The args from shard_num_args. """ index = args['index'] result = args['result'...
[ "Projects", "state", "shards", "onto", "the", "appropriate", "post", "measurement", "state", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L556-L573
[ "def", "_collapse_state", "(", "args", ":", "Dict", "[", "str", ",", "Any", "]", ")", ":", "index", "=", "args", "[", "'index'", "]", "result", "=", "args", "[", "'result'", "]", "prob_one", "=", "args", "[", "'prob_one'", "]", "state", "=", "_state_...
0827da80dd7880e5b923eb69407e980ed9bc0bd2
train
Stepper.init_z_vects
Initializes bitwise vectors which is precomputed in shared memory. There are two types of vectors here, a zero one vectors and a pm (plus/minus) vectors. The pm vectors have rows that are Pauli Z operators acting on the all ones vector. The column-th row corresponds to the Pauli Z actin...
cirq/google/sim/xmon_stepper.py
def init_z_vects(self): """Initializes bitwise vectors which is precomputed in shared memory. There are two types of vectors here, a zero one vectors and a pm (plus/minus) vectors. The pm vectors have rows that are Pauli Z operators acting on the all ones vector. The column-th row corre...
def init_z_vects(self): """Initializes bitwise vectors which is precomputed in shared memory. There are two types of vectors here, a zero one vectors and a pm (plus/minus) vectors. The pm vectors have rows that are Pauli Z operators acting on the all ones vector. The column-th row corre...
[ "Initializes", "bitwise", "vectors", "which", "is", "precomputed", "in", "shared", "memory", "." ]
quantumlib/Cirq
python
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/google/sim/xmon_stepper.py#L136-L171
[ "def", "init_z_vects", "(", "self", ")", ":", "shard_size", "=", "2", "**", "self", ".", "_num_shard_qubits", "a", ",", "b", "=", "np", ".", "indices", "(", "(", "shard_size", ",", "self", ".", "_num_shard_qubits", ")", ")", "a", ">>=", "b", "a", "&=...
0827da80dd7880e5b923eb69407e980ed9bc0bd2