Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions examples/python_optimization/python_optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down Expand Up @@ -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:"
]
Expand Down
10 changes: 7 additions & 3 deletions impl/py/src/jeff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading