Exemplo n.º 1
0
 def get_state(self, circuit, fit_to_constraints=True):
     """Calculate the statevector for a circuit.
     :param circuit: circuit to calculate
     :return: complex numpy array of statevector
     """
     c = circuit.copy()
     if fit_to_constraints:
         Transform.RebaseToQuil().apply(c)
     p = tk_to_pyquil(c)
     wf = self._sim.wavefunction(p)
     return wf.amplitudes
Exemplo n.º 2
0
 def get_operator_expectation_value(self,
                                    state_circuit,
                                    operator,
                                    shots=1000):
     c = state_circuit.copy()
     Transform.RebaseToQuil().apply(c)
     prog = tk_to_pyquil(c)
     pauli_sum = PauliSum([
         _gen_PauliTerm(term, coeff)
         for term, coeff in operator.terms.items()
     ])
     return self._sim.expectation(prog, pauli_sum)
Exemplo n.º 3
0
    def run(self,
            circuit: Circuit,
            shots: int,
            fit_to_constraints: bool = True) -> np.ndarray:
        """Run a circuit on the Rigetti QVM or a QCS device.

        :param circuit: The circuit to run
        :param shots: Number of shots (repeats) to run
        :param fit_to_constraints: Compile the circuit to meet the constraints of the backend, defaults to True
        :return: Table of shot results, each row is a shot, columns are ordered by qubit ordering. Values are 0 or 1, corresponding to qubit basis states.
        """
        c = circuit.copy()
        if fit_to_constraints:
            phys_c = route(c, self._architecture)
            phys_c.decompose_SWAP_to_CX()
            Transform.OptimisePostRouting().apply(phys_c)
            Transform.RebaseToQuil().apply(c)
        p = tk_to_pyquil(c)
        p.wrap_in_numshots_loop(shots)
        ex = self._qc.compiler.native_quil_to_executable(p)
        return np.asarray(self._qc.run(ex))
Exemplo n.º 4
0
 def get_pauli_expectation_value(self, state_circuit, pauli, shots=1000):
     c = state_circuit.copy()
     Transform.RebaseToQuil().apply(c)
     prog = tk_to_pyquil(c)
     pauli_term = _gen_PauliTerm(pauli)
     return self._sim.expectation(prog, [pauli_term])