def quil_to_native_quil(self, program: Program, *, protoquil: Optional[bool] = None) -> Program: self._connect_quilc() request = NativeQuilRequest(quil=program.out(), target_device=self.target_device) response = self.quilc_client.call( "quil_to_native_quil", request, protoquil=protoquil ).asdict() nq_program = parse_program(response["quil"]) nq_program.native_quil_metadata = response["metadata"] nq_program.num_shots = program.num_shots return nq_program
def quil_to_native_quil(self, program: Program) -> Program: self.connect() request = NativeQuilRequest(quil=program.out(), target_device=self.target_device) response = self.client.call('quil_to_native_quil', request).asdict() # type: Dict nq_program = parse_program(response['quil']) nq_program.native_quil_metadata = response['metadata'] nq_program.num_shots = program.num_shots return nq_program
def compiled_quil(self): """ If the Quil program associated with the Job was compiled (e.g., to translate it to the QPU's natural gateset) return this compiled program. :rtype: Optional[Program] """ prog = self._get_metadata("compiled_quil") if prog is not None: return parse_program(prog)
def compiled_quil(self): """ If the Quil program associated with the Job was compiled (e.g., to translate it to the QPU's natural gateset) return this compiled program. :rtype: Optional[Program] """ prog = self._raw.get("program", {}).get("compiled-quil", None) if prog is not None: return parse_program(prog) else: # if we failed too early to even get a "compiled-quil" field, # then alert the user to that problem instead if self._raw['status'] == 'ERROR': return self.result()
def getRandomNum(num): q = QVMConnection() s = "".join(["H " + str(i) + "\n" for i in range(num)]) s += "".join( ["MEASURE " + str(i) + " [" + str(i) + "]\n" for i in range(num)]) #print(s) p = parse_program(s) res = None try: res = str( q.wavefunction(p).amplitudes)[1:-1].split(" ").index("1.+0.j") except: print(q.wavefunction(p).amplitudes) return -1 return res
def compile(self, quil_program): """ Sends a Quil program to the Forest compiler and returns the resulting compiled Program. :param Program quil_program: Quil program to be compiled. :returns: The compiled Program object. :rtype: Program """ payload = self._compile_payload(quil_program) if self.use_queue: response = post_json(self.session, self.async_endpoint + "/job", { "machine": "QUILC", "program": payload }) job = self.wait_for_job(get_job_id(response)) return job.compiled_quil() else: response = post_json(self.session, self.sync_endpoint + "/quilc", payload) return parse_program(response.json()['compiled-quil'])
def compile(self, quil_program, isa=None): """ Sends a Quil program to the Forest compiler and returns the resulting compiled Program. :param Program quil_program: Quil program to be compiled. :param ISA isa: An optional ISA to target. This takes precedence over the ``device`` or ``isa_source`` arguments to this object's constructor. If this is not specified, you must have provided one of the aforementioned constructor arguments. :returns: The compiled Program object. :rtype: Program """ payload = self._compile_payload(quil_program, isa) if self.use_queue: response = post_json(self.session, self.async_endpoint + "/job", {"machine": "QUILC", "program": payload}) job = self.wait_for_job(get_job_id(response)) return job.compiled_quil() else: response = post_json(self.session, self.sync_endpoint + "/quilc", payload) return parse_program(response.json()['compiled-quil'])
def quil_to_native_quil(self, program: Program, *, protoquil: Optional[bool] = None) -> Program: """ Compile an arbitrary quil program according to the ISA of ``self.quantum_processor``. :param program: Arbitrary quil to compile :param protoquil: Whether to restrict to protoquil (``None`` means defer to server) :return: Native quil and compiler metadata """ self._connect() compiler_isa = self.quantum_processor.to_compiler_isa() request = CompileToNativeQuilRequest( program=program.out(calibrations=False), target_quantum_processor=compiler_isa_to_target_quantum_processor( compiler_isa), protoquil=protoquil, ) response = self._compiler_client.compile_to_native_quil(request) nq_program = parse_program(response.native_program) nq_program.native_quil_metadata = ( None if response.metadata is None else NativeQuilMetadata( final_rewiring=response.metadata.final_rewiring, gate_depth=response.metadata.gate_depth, gate_volume=response.metadata.gate_volume, multiqubit_gate_depth=response.metadata.multiqubit_gate_depth, program_duration=response.metadata.program_duration, program_fidelity=response.metadata.program_fidelity, topological_swaps=response.metadata.topological_swaps, qpu_runtime_estimation=response.metadata. qpu_runtime_estimation, )) nq_program.num_shots = program.num_shots nq_program._calibrations = program.calibrations nq_program._memory = program._memory.copy() return nq_program
def _fetch_calibration_program(self) -> Program: with self._qcs_client() as qcs_client: # type: httpx.Client response = get_quilt_calibrations( client=qcs_client, quantum_processor_id=self.quantum_processor_id).parsed return parse_program(response.quilt)