Exemple #1
0
 def with_line_qubits_mapped_to(self, qubits: List['cirq.Qid']) -> 'Cell':
     return ParityControlCell(
         qubits=Cell._replace_qubits(self.qubits, qubits),
         basis_change=tuple(
             op.with_qubits(*Cell._replace_qubits(op.qubits, qubits))
             for op in self._basis_change),
     )
Exemple #2
0
 def with_line_qubits_mapped_to(self, qubits: List['cirq.Qid']) -> 'Cell':
     return ArithmeticCell(identifier=self.identifier,
                           target=Cell._replace_qubits(self.target, qubits),
                           inputs=[
                               e if e is None or isinstance(e, int) else
                               Cell._replace_qubits(e, qubits)
                               for e in self.inputs
                           ])
Exemple #3
0
 def with_line_qubits_mapped_to(self, qubits: List['cirq.Qid']) -> 'Cell':
     return InputRotationCell(
         self.identifier,
         None if self.register is None else Cell._replace_qubits(
             self.register, qubits),
         self.base_operation.with_qubits(
             *Cell._replace_qubits(self.base_operation.qubits, qubits)),
         exponent_sign=self.exponent_sign)
Exemple #4
0
def test_cell_replace_utils():
    a, b, c = cirq.NamedQubit.range(3, prefix='q')
    assert Cell._replace_qubit(cirq.LineQubit(1), [a, b, c]) == b
    with pytest.raises(ValueError, match='only map from line qubits'):
        _ = Cell._replace_qubit(cirq.GridQubit(0, 0), [a, b, c])
    with pytest.raises(ValueError, match='not in range'):
        _ = Cell._replace_qubit(cirq.LineQubit(-1), [a, b, c])
    with pytest.raises(ValueError, match='not in range'):
        _ = Cell._replace_qubit(cirq.LineQubit(999), [a, b, c])
Exemple #5
0
 def with_line_qubits_mapped_to(self, qubits: List['cirq.Qid']) -> 'Cell':
     return InputCell(qubits=Cell._replace_qubits(self.qubits, qubits),
                      letter=self.letter)
Exemple #6
0
 def with_line_qubits_mapped_to(self, qubits: List['cirq.Qid']) -> 'Cell':
     return SwapCell(
         qubits=Cell._replace_qubits(self._qubits, qubits),
         controls=Cell._replace_qubits(self._controls, qubits),
     )