You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As Andrew Berkeley pointed out in a meeting yesterday, it might be nice to allow named parameters. I'm not sure of the best interface for this, but here's some slightly rambly thoughts.
Defining the parametric circuit already uses syntactic sugar; that can be extended through __getattr__:
But the circuit definition does not forbid a mix of positional and named operations! If support named parameters is a popular idea, I might suggest not supporting the notation above, nor the extant
MyRotOperation([3*np.pi/2, np.pi/2, np.pi], q[2])
Rather than expect an array of parameters and allow the application of the operator in the same call, we could force the user to curry the parameters separately:
#positional onlyMyRotOperation(3*np.pi/2, np.pi/2, np.pi)(q[2])
#named onlyMyRotOperation(dz0=3*np.pi/2, dy=np.pi/2, dz1=np.pi)(q[2])
#mixed named and positionalMyRotOperation(3*np.pi/2, np.pi/2, dz1=np.pi)(q[2])
Now, if we do want to forbid the mix of named and positional arguments, we could take an optional parameter:
# list of paramsrot_circuit=ParametricCircuit(1) #default: params=listrot_circuit=ParametricCircuit(1, params=list) #explicitwithrot_circuit.contextas (p, q, c):
ops.RZ(p[0], q[0])
ops.RY(p[1], q[0])
ops.RZ(p[2], q[0])
...
MyRotOperation([3*np.pi/2, np.pi/2, np.pi], q[2])
#dict of paramscircuit=ParametricCircuit(1, params=dict)
withrot_circuit.contextas (p, q, c):
ops.RZ(p.dz0, q[0])
ops.RY(p.dy, q[0])
ops.RZ(p.dz1, q[0])
...
MyRotOperation({'dz0': 3*np.pi/2, 'dy': np.pi/2, 'dz1': np.pi}, q[2])
The text was updated successfully, but these errors were encountered:
From 3_parametric_circuits.py
As Andrew Berkeley pointed out in a meeting yesterday, it might be nice to allow named parameters. I'm not sure of the best interface for this, but here's some slightly rambly thoughts.
Defining the parametric circuit already uses syntactic sugar; that can be extended through
__getattr__
:Applying the operator then suffers a bit -- named parameters must follow positional arguments. We can work around this by providing a
dict
:But the circuit definition does not forbid a mix of positional and named operations! If support named parameters is a popular idea, I might suggest not supporting the notation above, nor the extant
Rather than expect an array of parameters and allow the application of the operator in the same call, we could force the user to curry the parameters separately:
Now, if we do want to forbid the mix of named and positional arguments, we could take an optional parameter:
The text was updated successfully, but these errors were encountered: