コード例 #1
0
 def get_devices(self):
     # any qpu device can also be used as a qvm for rigetti, so we include both
     names = [
         *[
             n for qc_n in pq.list_quantum_computers(qpus=False, qvms=False)
             for n in [f"{qc_n}-qvm", f"{qc_n}-noisy-qvm"]
         ],
         *[n for n in pq.list_quantum_computers(qpus=False, qvms=True)],
         *RIGETTI_EXTRA_QVMS,
     ]
     return {name: RigettiQVM(name) for name in names}
コード例 #2
0
def test_list_qc():
    qc_names = list_quantum_computers()
    assert qc_names == [
        '8Q-Agave', '8Q-Agave-qvm', '8Q-Agave-noisy-qvm', '19Q-Acorn',
        '19Q-Acorn-qvm', '19Q-Acorn-noisy-qvm', '9q-generic-qvm',
        '9q-generic-noisy-qvm'
    ]
コード例 #3
0
 def get_devices(self):
     devices = {}
     for n in pq.list_quantum_computers(qpus=True, qvms=False):
         try:
             devices[n] = RigettiQPU(n)
         except (RuntimeError, pq.api._errors.UserMessageError):
             pass
     return devices
コード例 #4
0
    def check_device(self, device):
        """
        Verify if a device is valid.
        Parameters
        ----------
        device:
            a pyquil.api.QuantumComputer, a string which picks one out, or a dictionary that can pass to get_qc.
        Returns
        -------
        None

        """
        if device is None:
            return
        if isinstance(device, str):
            d = device
            if '-qvm' in d.lower():
                d = d[:-4]
            if '-noisy' in d.lower():
                d = d[:-6]
            if d in pyquil.list_quantum_computers():
                return
            else:
                try:
                    get_qc(d)
                    return
                except:
                    try:
                        get_qc(d, as_qvm=True)
                        return
                    except:
                        raise TequilaException(
                            'could not obtain device from string; received {}'.
                            format(device))

        elif isinstance(device, dict):
            try:
                get_qc(**device)
                return
            except:
                raise TequilaException(
                    'could not initialize device from dict; received {}'.
                    format(device))
        elif isinstance(device, pyquil.api.QuantumComputer):
            return

        else:
            raise TequilaException(
                'Uninterpretable object {} of type {} passed to check_device!'.
                format(device, type(device)))
コード例 #5
0
def test_list_qc():
    qc_names = list_quantum_computers(qpus=False)
    # TODO: update with deployed qpus
    assert qc_names == ['9q-square-qvm', '9q-square-noisy-qvm']
コード例 #6
0
def test_list_qc():
    qc_names = list_quantum_computers(qpus=False)
    assert qc_names == ["9q-square-qvm", "9q-square-noisy-qvm"]
コード例 #7
0
"""
Unit tests for the QPU device.
"""
import logging

import pytest
import pyquil
import pennylane as qml
from pennylane import numpy as np
from conftest import BaseTest


log = logging.getLogger(__name__)

VALID_QPU_LATTICES = [qc for qc in pyquil.list_quantum_computers() if "qvm" not in qc]


class TestQPUIntegration(BaseTest):
    """Test the wavefunction simulator works correctly from the PennyLane frontend."""

    # pylint: disable=no-self-use

    def test_load_qpu_device(self):
        """Test that the QPU device loads correctly"""
        device = [qpu for qpu in VALID_QPU_LATTICES if '-2Q' in qpu][0]
        dev = qml.device("forest.qpu", device=device, load_qc=False)
        self.assertEqual(dev.num_wires, 2)
        self.assertEqual(dev.shots, 1024)
        self.assertEqual(dev.short_name, "forest.qpu")

    def test_load_virtual_qpu_device(self):
コード例 #8
0
import pytest

import pennylane as qml
from pennylane import numpy as np

from conftest import BaseTest
from conftest import I, Z, H, U, U2, test_operation_map

import pennylane_forest as plf

import pyquil

log = logging.getLogger(__name__)

VALID_QPU_LATTICES = [
    qc for qc in pyquil.list_quantum_computers() if "qvm" not in qc
]


class TestQVMBasic(BaseTest):
    """Unit tests for the QVM simulator."""

    # pylint: disable=protected-access

    def test_identity_expectation(self, shots, qvm, compiler):
        """Test that identity expectation value (i.e. the trace) is 1"""
        theta = 0.432
        phi = 0.123

        dev = plf.QVMDevice(device="2q-qvm", shots=shots)
        dev.apply("RX", wires=[0], par=[theta])
コード例 #9
0
p += pq.gates.MEASURE(0, ro[0])
p += pq.gates.MEASURE(1, ro[1])

##################################################
# Print program
##################################################
print('Quantum Program in PyQuil (complete):')
print(p)
print('\n')

##################################################
# Run the program on a local simulator
##################################################

# List available backends to run the circuit
av_backends = pq.list_quantum_computers()
av_backends_sim = []
for backend in av_backends:
    if backend[-3:] == 'qvm':
        av_backends_sim.append(backend)
print('Available backends for simulating the circuit:',
      *av_backends_sim,
      '2q-qvm',
      '3q-qvm',
      'nq-qvm for n = 2, 3, 4, ...',
      sep='\n   ')
print('\n')

# Request a 2 qubit QVM (quantum virtual machine)
print('Using backend 2q-qvm and creating quantum circuit.')
print('\n')
コード例 #10
0
def test_list_qc():
    qc_names = list_quantum_computers()
    # TODO: update with deployed qpus
    assert qc_names == ['9q-generic-qvm', '9q-generic-noisy-qvm']
コード例 #11
0
import re

import pytest
import pyquil
import pennylane as qml
from pennylane import numpy as np
import pennylane_forest as plf
from conftest import BaseTest, QVM_SHOTS

from flaky import flaky

log = logging.getLogger(__name__)

pattern = "Aspen-.-[1-5]Q-."
VALID_QPU_LATTICES = [
    qc for qc in pyquil.list_quantum_computers()
    if "qvm" not in qc and re.match(pattern, qc)
]


class TestQPUIntegration(BaseTest):
    """Test the wavefunction simulator works correctly from the PennyLane frontend."""

    # pylint: disable=no-self-use

    def test_load_qpu_device(self):
        """Test that the QPU device loads correctly"""
        device = [qpu for qpu in VALID_QPU_LATTICES if "-2Q" in qpu][0]
        dev = qml.device("forest.qpu", device=device, load_qc=False)
        self.assertEqual(dev.num_wires, 2)
        self.assertEqual(dev.shots, 1024)
コード例 #12
0
    return prog


def summrise_results(bitstrings) -> dict:
    d = {}
    for l in bitstrings:
        if d.get(l) is None:
            d[l] = 1
        else:
            d[l] = d[l] + 1

    return d


if __name__ == '__main__':

    x_bits = "1011"
    f = lambda rep: str(int(rep == x_bits))

    prog = make_circuit(4, f)
    print(list_quantum_computers(qpus=False))
    qvm = get_qc('9q-square-qvm')
    qvm.compiler.client.rpc_timeout = 60

    results = qvm.run_and_measure(prog, 1024)
    bitstrings = np.vstack([results[i] for i in qvm.qubits()]).T
    bitstrings = [''.join(map(str, l)) for l in bitstrings]
    #writefile = open("../data/startPyquil9.csv","w")
    print(summrise_results(bitstrings))  #,file=writefile)
    #writefile.close()