Пример #1
0
    def test_lookup_rotation(self, reg_size, gate_cnt):
        self.log.debug('Testing Lookup Rotation with positive eigenvalues')

        a = QuantumRegister(reg_size, name='a')
        lrot = LookupRotation(negative_evals=False)
        lrot_circuit = lrot.construct_circuit('', a)
        circuit_cnt = lrot_circuit.data.__len__()
        assert (circuit_cnt == gate_cnt)

        self.log.debug('Lookup rotation register size: {}'.format(reg_size))
        self.log.debug('Lookup rotation gate count:    {}'.format(circuit_cnt))
Пример #2
0
    def test_lookup_rotation(self, reg_size, ref_rot):
        self.log.debug('Testing Lookup Rotation with positive eigenvalues')

        ref_sv_ampl = ref_rot**2
        ref_size = reg_size + 3  # add work, msq and anc qubits
        ref_dim = 2**ref_size
        ref_sv = np.zeros(ref_dim, dtype=complex)
        ref_sv[int(ref_dim / 2) + 1] = ref_sv_ampl + 0j
        ref_sv[1] = np.sqrt(1 - ref_sv_ampl**2) + 0j
        state = basis_state('1', reg_size)
        a = QuantumRegister(reg_size, name='a')
        init_circuit = QuantumCircuit(a)
        init_circuit.initialize(state, a)
        lrot = LookupRotation(negative_evals=False)
        lrot_circuit = init_circuit + lrot.construct_circuit('', a)
        lrot_sv = sim_statevec(lrot_circuit)
        fidelity = state_fidelity(lrot_sv, ref_sv)
        np.testing.assert_approx_equal(fidelity, 1, significant=5)

        self.log.debug('Lookup rotation register size: {}'.format(reg_size))
        self.log.debug('Lookup rotation fidelity:      {}'.format(fidelity))
    def test_lookup_rotation(self, reg_size, ref_rot):
        """ lookup rotation test """
        self.log.debug('Testing Lookup Rotation with positive eigenvalues')

        ref_sv_ampl = ref_rot**2
        ref_size = reg_size + 3  # add work, msq and anc qubits
        ref_dim = 2**ref_size
        ref_sv = np.zeros(ref_dim, dtype=complex)
        ref_sv[int(ref_dim / 2) + 1] = ref_sv_ampl + 0j
        ref_sv[1] = np.sqrt(1 - ref_sv_ampl**2) + 0j
        state = Statevector.from_label('0' * (reg_size - 1) + '1').data
        q_a = QuantumRegister(reg_size, name='a')
        init_circuit = QuantumCircuit(q_a)
        init_circuit.initialize(state, q_a)
        lrot = LookupRotation(negative_evals=False)
        lrot_circuit = init_circuit + lrot.construct_circuit('', q_a)
        lrot_sv = _sim_statevec(lrot_circuit)
        fidelity = state_fidelity(lrot_sv, ref_sv)
        np.testing.assert_approx_equal(fidelity, 1, significant=5)

        self.log.debug('Lookup rotation register size: %s', reg_size)
        self.log.debug('Lookup rotation fidelity:      %s', fidelity)