Example #1
0
    def __init__(self,
                 endpoint: str,
                 device: AbstractDevice,
                 timeout: float = 10) -> None:
        """
        Client to communicate with the Compiler Server.

        :param endpoint: TCP or IPC endpoint of the Compiler Server
        :param device: PyQuil Device object to use as compilation target
        """

        if not endpoint.startswith('tcp://'):
            raise ValueError(
                f"PyQuil versions >= 2.4 can only talk to quilc "
                f"versions >= 1.4 over network RPCQ.  You've supplied the "
                f"endpoint '{endpoint}', but this doesn't look like a network "
                f"ZeroMQ address, which has the form 'tcp://domain:port'. "
                f"You might try clearing (or correcting) your COMPILER_URL "
                f"environment variable and removing (or correcting) the "
                f"compiler_server_address line from your .forest_config file.")

        self.client = Client(endpoint, timeout=timeout)
        self.target_device = TargetDevice(isa=device.get_isa().to_dict(),
                                          specs=device.get_specs().to_dict())

        try:
            self.connect()
        except QuilcNotRunning as e:
            warnings.warn(
                f'{e}. Compilation using quilc will not be available.')
Example #2
0
    def __init__(self,
                 endpoint: str,
                 device: AbstractDevice,
                 timeout: int = 10,
                 name: Optional[str] = None) -> None:
        """
        Client to communicate with the Compiler Server.

        :param endpoint: TCP or IPC endpoint of the Compiler Server
        :param device: PyQuil Device object to use as compilation target
        :param timeout: Number of seconds to wait for a response from the client.
        :param name: Name of the lattice being targeted
        """

        if not endpoint.startswith('tcp://'):
            raise ValueError(
                f"PyQuil versions >= 2.4 can only talk to quilc "
                f"versions >= 1.4 over network RPCQ.  You've supplied the "
                f"endpoint '{endpoint}', but this doesn't look like a network "
                f"ZeroMQ address, which has the form 'tcp://domain:port'. "
                f"You might try clearing (or correcting) your COMPILER_URL "
                f"environment variable and removing (or correcting) the "
                f"compiler_server_address line from your .forest_config file.")

        self.client = Client(endpoint, timeout=timeout)
        self.target_device = TargetDevice(isa=device.get_isa().to_dict(),
                                          specs=device.get_specs().to_dict())
        self.name = name
Example #3
0
    def __init__(self, endpoint: str, device: AbstractDevice) -> None:
        """
        Client to communicate with the Compiler Server.

        :param endpoint: TCP or IPC endpoint of the Compiler Server
        :param device: PyQuil Device object to use as compilation target
        """
        self.client = Client(endpoint)
        self.target_device = TargetDevice(isa=device.get_isa().to_dict(),
                                          specs=device.get_specs().to_dict())
Example #4
0
    def __init__(self, endpoint: str, device: AbstractDevice, timeout: int = 10) -> None:
        """
        Client to communicate with the Compiler Server.

        :param endpoint: TCP or IPC endpoint of the Compiler Server
        :param device: PyQuil Device object to use as compilation target
        :param timeout: Number of seconds to wait for a response from the client.
        """

        self.client = Client(endpoint, timeout=timeout)
        self.target_device = TargetDevice(isa=device.get_isa().to_dict(),
                                          specs=device.get_specs().to_dict())
Example #5
0
    def __init__(self, endpoint: str, device: AbstractDevice) -> None:
        """
        Client to communicate with a locally executing quilc instance.

        :param endpoint: HTTP endpoint of the quilc instance.
        :param device: PyQuil Device object to use as the compilation target.
        """
        self.endpoint = endpoint
        self.isa = device.get_isa()
        self.specs = device.get_specs()

        self._connection = ForestConnection(sync_endpoint=endpoint)
        self.session = self._connection.session  # backwards compatibility
Example #6
0
    def __init__(self,
                 quilc_endpoint: str,
                 qpu_compiler_endpoint: Optional[str],
                 device: AbstractDevice,
                 timeout: int = 10,
                 name: Optional[str] = None) -> None:
        """
        Client to communicate with the Compiler Server.

        :param quilc_endpoint: TCP or IPC endpoint of the Quil Compiler (quilc)
        :param qpu_compiler_endpoint: TCP or IPC endpoint of the QPU Compiler
        :param device: PyQuil Device object to use as compilation target
        :param timeout: Number of seconds to wait for a response from the client.
        :param name: Name of the lattice being targeted
        """

        if not quilc_endpoint.startswith('tcp://'):
            raise ValueError(
                f"PyQuil versions >= 2.4 can only talk to quilc "
                f"versions >= 1.4 over network RPCQ.  You've supplied the "
                f"endpoint '{quilc_endpoint}', but this doesn't look like a network "
                f"ZeroMQ address, which has the form 'tcp://domain:port'. "
                f"You might try clearing (or correcting) your COMPILER_URL "
                f"environment variable and removing (or correcting) the "
                f"compiler_server_address line from your .forest_config file.")

        self.quilc_client = Client(quilc_endpoint, timeout=timeout)
        if qpu_compiler_endpoint is not None:
            self.qpu_compiler_client = Client(qpu_compiler_endpoint,
                                              timeout=timeout)
        else:
            self.qpu_compiler_client = None
            warnings.warn(
                "It looks like you are initializing a QPUCompiler object without a "
                "qpu_compiler_address. If you didn't do this manually, then "
                "you probably don't have a qpu_compiler_address entry in your "
                "~/.forest_config file, meaning that you are not engaged to the QPU."
            )
        self.target_device = TargetDevice(isa=device.get_isa().to_dict(),
                                          specs=device.get_specs().to_dict())
        self.name = name

        try:
            self.connect()
        except QuilcNotRunning as e:
            warnings.warn(
                f'{e}. Compilation using quilc will not be available.')
        except QPUCompilerNotRunning as e:
            warnings.warn(
                f'{e}. Compilation using the QPU compiler will not be available.'
            )
Example #7
0
    def __init__(
        self,
        quilc_endpoint: Optional[str],
        qpu_compiler_endpoint: Optional[str],
        device: AbstractDevice,
        timeout: int = 10,
        name: Optional[str] = None,
        *,
        session: Optional[ForestSession] = None,
    ) -> None:
        """
        Client to communicate with the Compiler Server.

        :param quilc_endpoint: TCP or IPC endpoint of the Quil Compiler (quilc).
        :param qpu_compiler_endpoint: TCP or IPC endpoint of the QPU Compiler.
        :param device: PyQuil Device object to use as compilation target.
        :param timeout: Number of seconds to wait for a response from the client.
        :param name: Name of the lattice being targeted.
        :param session: ForestSession object, which manages engagement and configuration.
        """

        if not (session or (quilc_endpoint and qpu_compiler_endpoint)):
            raise ValueError(
                "QPUCompiler requires either `session` or both of `quilc_endpoint` and "
                "`qpu_compiler_endpoint`.")

        self.session = session
        self.timeout = timeout

        _quilc_endpoint = quilc_endpoint or self.session.config.quilc_url

        if not _quilc_endpoint.startswith("tcp://"):
            raise ValueError(
                f"PyQuil versions >= 2.4 can only talk to quilc "
                f"versions >= 1.4 over network RPCQ.  You've supplied the "
                f"endpoint '{quilc_endpoint}', but this doesn't look like a network "
                f"ZeroMQ address, which has the form 'tcp://domain:port'. "
                f"You might try clearing (or correcting) your COMPILER_URL "
                f"environment variable and removing (or correcting) the "
                f"compiler_server_address line from your .forest_config file.")

        self.quilc_client = Client(_quilc_endpoint, timeout=timeout)

        self.qpu_compiler_endpoint = qpu_compiler_endpoint
        self._qpu_compiler_client = None

        self._device = device
        self.target_device = TargetDevice(isa=device.get_isa().to_dict(),
                                          specs=None)
        self.name = name

        try:
            self.connect()
        except QuilcNotRunning as e:
            warnings.warn(
                f"{e}. Compilation using quilc will not be available.")
        except QPUCompilerNotRunning as e:
            warnings.warn(
                f"{e}. Compilation using the QPU compiler will not be available."
            )