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.endpoint = endpoint self.client = Client(endpoint, timeout=timeout) td = TargetDevice(isa=device.get_isa().to_dict(), specs=None) # type: ignore self.target_device = td try: self.connect() except QuilcNotRunning as e: warnings.warn( f"{e}. Compilation using quilc will not be available.")
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 if quilc_endpoint: _quilc_endpoint = quilc_endpoint elif self.session and self.session.config.quilc_url: _quilc_endpoint = self.session.config.quilc_url else: raise ValueError("Must provide a 'quilc_endpoint' or a 'session'") 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: Optional[Union[Client, HTTPCompilerClient]] = None self._device = device td = TargetDevice(isa=device.get_isa().to_dict(), specs=None) # type: ignore self.target_device = td 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." )