Skip to content

Commit

Permalink
fixed a bug in the treatment of symbolic global phases
Browse files Browse the repository at this point in the history
  • Loading branch information
positr0nium committed Jun 19, 2024
1 parent 2b5e499 commit ec012e1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/qrisp/circuit/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def __init__(
if isinstance(par, (float, int, np.floating, np.int32)):
pass
elif isinstance(par, Expr):
self.abstract_params = self.abstract_params.union(par.free_symbols)
if len(par.free_symbols):
self.abstract_params = self.abstract_params.union(par.free_symbols)
else:
par = float(par)
else:
raise Exception(
f"Tried to create operation with parameters of type {type(par)}"
Expand Down Expand Up @@ -438,7 +441,7 @@ def c_if(self, num_control=1, ctrl_state=-1):
# for more information
class U3Gate(Operation):
def __init__(self, theta, phi, lam, name="u3", global_phase=0):
self.global_phase = global_phase

# Initialize Operation instance
super().__init__(
name=name,
Expand All @@ -449,7 +452,11 @@ def __init__(self, theta, phi, lam, name="u3", global_phase=0):
)

if isinstance(global_phase, Expr):
self.abstract_params = self.abstract_params.union(global_phase.free_symbols)
if len(global_phase.free_symbols):
self.abstract_params = self.abstract_params.union(global_phase.free_symbols)
else:
global_phase = float(global_phase)
self.global_phase = global_phase

# Set parameters
self.theta = self.params[0]
Expand Down

0 comments on commit ec012e1

Please sign in to comment.