def test_raw_qureg_init():
    eq = cirq.testing.EqualsTester()
    a = qp.Qubit('a')
    b = qp.Qubit('b')
    eq.add_equality_group(qp.RawQureg([a, b]), qp.RawQureg([a, b]))
    eq.add_equality_group(qp.RawQureg([b, a]))
    eq.add_equality_group(qp.RawQureg([]))
def test_raw_qureg_getitem_len():
    a = qp.Qubit()
    b = qp.Qubit()
    q = qp.RawQureg([a, b])
    assert len(q) == 2
    assert q[0] == a
    assert q[:] == q
    assert q[0:2] == q
Example #3
0
def do_xor_const(*,
                 control: qp.Qubit.Control = True,
                 lvalue: qp.Quint,
                 mask: int):
    assert isinstance(control,
                      qp.QubitIntersection) and len(control.qubits) <= 1
    assert isinstance(lvalue, qp.Quint)
    assert isinstance(mask, int)
    targets = [q for i, q in enumerate(lvalue) if mask & (1 << i)]
    sink.global_sink.do_toggle(qp.RawQureg(targets), control)
Example #4
0
    def __enter__(self) -> 'qp.Qureg':
        if len(self.base) >= self.min_len:
            return self.wrapper(self.base)

        assert self.padded is None
        sub_name = str(self.base) if isinstance(self.base,
                                                qp.NamedQureg) else ''
        self.padded = qp.qalloc(name='{}_pad'.format(sub_name),
                                len=self.min_len - len(self.base))
        return self.wrapper(qp.RawQureg(list(self.base) + list(self.padded)))
Example #5
0
 def __getitem__(self, item):
     if isinstance(item, bool):
         return self.values[int(item)]
     if isinstance(item, int):
         return self.values[item]
     if isinstance(item, slice):
         return LookupTable(self.values[item])
     if isinstance(item, tuple):
         if all(isinstance(e, qp.Quint) for e in item):
             reg = qp.RawQureg(q for e in item[::-1] for q in e)
             return qp.LookupRValue(self, qp.Quint(reg))
     if isinstance(item, qp.Quint):
         return qp.LookupRValue(self, item)
     if isinstance(item, qp.Qubit):
         return qp.LookupRValue(self, qp.Quint(item.qureg))
     raise NotImplementedError('Strange index: {}'.format(item))
def test_raw_qureg_repr():
    cirq.testing.assert_equivalent_repr(
        qp.RawQureg([qp.Qubit()]), setup_code='import quantumpseudocode as qp')
Example #7
0
 def resolve(self, sim_state: 'qp.ClassicalSimState', allow_mutate: bool) -> bool:
     v = qp.Quint(qp.RawQureg(self.qubits)).resolve(sim_state, False)
     return self.bit and v == (1 << len(self.qubits)) - 1
Example #8
0
 def qureg(self):
     if self.index is None:
         return qp.NamedQureg(self.name, length=1)
     return qp.RawQureg([qp.Qubit(self.name, self.index)])