Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def native_quil_to_executable(self, nq_program: Program) -> PyQuilExecutableResponse:
return PyQuilExecutableResponse(
program=nq_program.out(),
attributes=_extract_attribute_dictionary_from_program(nq_program),
)
:param executable: An executable. See the above note for acceptable types.
"""
if self.requires_executable:
if isinstance(executable, PyQuilExecutableResponse):
executable = _extract_program_from_pyquil_executable_response(executable)
else:
raise TypeError(
"`executable` argument must be a `PyQuilExecutableResponse`. Make "
"sure you have explicitly compiled your program via `qc.compile` "
"or `qc.compiler.native_quil_to_executable(...)` for more "
"fine-grained control. This explicit step is required for running "
"on a QPU."
)
else:
if isinstance(executable, PyQuilExecutableResponse):
executable = _extract_program_from_pyquil_executable_response(executable)
elif isinstance(executable, Program):
pass
else:
raise TypeError(
"`executable` argument must be a `PyQuilExecutableResponse` or a "
"`Program`. You provided {}".format(type(executable))
)
return super().load(executable)
def load(self, executable):
if isinstance(executable, PyQuilExecutableResponse):
program = _extract_program_from_pyquil_executable_response(executable)
else:
program = executable
# initialize program counter
self.program = program
self.program_counter = 0
self._memory_results = None
# clear RAM, although it's not strictly clear if this should happen here
self.ram = {}
# if we're clearing RAM, we ought to clear the WF too
self.wf_simulator.reset()
# grab the gate definitions for future use
self._extract_defined_gates()
def load(self, executable):
"""
Initialize a QAM and load a program to be executed with a call to :py:func:`run`.
If ``QVM.requires_executable`` is set to ``True``, this function will only load
:py:class:`PyQuilExecutableResponse` executables. This more closely follows the behavior
of :py:class:`QPU`. However, the quantum simulator doesn't *actually* need a compiled
binary executable, so if this flag is set to ``False`` we also accept :py:class:`Program`
objects.
:param executable: An executable. See the above note for acceptable types.
"""
if self.requires_executable:
if isinstance(executable, PyQuilExecutableResponse):
executable = _extract_program_from_pyquil_executable_response(executable)
else:
raise TypeError(
"`executable` argument must be a `PyQuilExecutableResponse`. Make "
"sure you have explicitly compiled your program via `qc.compile` "
"or `qc.compiler.native_quil_to_executable(...)` for more "
"fine-grained control. This explicit step is required for running "
"on a QPU."
)
else:
if isinstance(executable, PyQuilExecutableResponse):
executable = _extract_program_from_pyquil_executable_response(executable)
elif isinstance(executable, Program):
pass
else:
raise TypeError(