Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:param expression: an Expression
"""
if isinstance(expression, BinaryExp):
left = self._resolve_memory_references(expression.op1)
right = self._resolve_memory_references(expression.op2)
return expression.fn(left, right)
elif isinstance(expression, Function):
return expression.fn(self._resolve_memory_references(expression.expression))
elif isinstance(expression, Parameter):
raise ValueError(f"Unexpected Parameter in gate expression: {expression}")
elif isinstance(expression, float) or isinstance(expression, int):
return expression
elif isinstance(expression, MemoryReference):
return self._variables_shim.get(
ParameterAref(name=expression.name, index=expression.offset), 0
)
else:
raise ValueError(f"Unexpected expression in gate parameter: {expression}")
def write_memory(self, *, region_name: str, offset: int = 0, value=None):
"""
Writes a value into a memory region on the QAM at a specified offset.
:param region_name: Name of the declared memory region on the QAM.
:param offset: Integer offset into the memory region to write to.
:param value: Value to store at the indicated location.
"""
assert self.status in ["loaded", "done"]
aref = ParameterAref(name=region_name, index=offset)
self._variables_shim[aref] = value
return self