diff --git a/examples/python_optimization/python_optimization.ipynb b/examples/python_optimization/python_optimization.ipynb index f754820..a8574dc 100644 --- a/examples/python_optimization/python_optimization.ipynb +++ b/examples/python_optimization/python_optimization.ipynb @@ -337,19 +337,19 @@ "jeff v0\n", "\n", "[entry] func @main(int1) -> ():\n", - " in : %4397829072:int1\n", - " %4402776464:qubit = qubit.alloc \n", - " %4402736208:qubit = qubit.gate %4402776464:qubit (h)\n", - " %4402834256:int1 = int.not %4397829072:int1\n", - " %4404055888:qubit = scf.switch %4402834256:int1, %4402736208:qubit \n", + " in : :int1\n", + " :qubit = qubit.alloc \n", + " :qubit = qubit.gate :qubit (h)\n", + " :int1 = int.not :int1\n", + " :qubit = scf.switch :int1, :qubit \n", " case 0:\n", - " in : %4404309008:qubit\n", - " %4404304208:qubit = qubit.gate %4404309008:qubit (h)\n", - " out: %4404304208:qubit\n", + " in : :qubit\n", + " :qubit = qubit.gate :qubit (h)\n", + " out: :qubit\n", " default:\n", - " in : %4404302800:qubit\n", - " out: %4404302800:qubit\n", - " qubit.free %4404055888:qubit\n", + " in : :qubit\n", + " out: :qubit\n", + " qubit.free :qubit\n", " out:\n", "\n" ] @@ -399,8 +399,7 @@ "metadata": {}, "source": [ "As we can see we re-created the same program as the one we loaded originally, the only difference\n", - "is that program values have some random-looking values assigned to them. This is the Python id of\n", - "the value object, which is a local property. To obtain the nicer print-out from before with globally\n", + "is that program values do not have an id assigned to them. To obtain the nicer print-out from before with globally\n", "assigned labels for the value, we can encode the program into cap'n proto and generate a value\n", "table in the process:" ] diff --git a/impl/py/src/jeff/__init__.py b/impl/py/src/jeff/__init__.py index 955afa1..a079477 100644 --- a/impl/py/src/jeff/__init__.py +++ b/impl/py/src/jeff/__init__.py @@ -283,16 +283,20 @@ def type(self): # convenience methods @property - def id(self) -> int: + def id(self) -> int | None: if self._val_idx is not None: return self._val_idx - return id(self) + return None # Python integration def __str__(self): - return f"%{self.id}:{self.type}" + match self.id: + case None: + return f":{self.type}" + case _: + return f"%{self.id}:{self.type}" def __eq__(self, other): if not isinstance(other, JeffValue):