I proposed a solution in this PR https://github.com/sympy/sympy/pull/22887 
which stores the (lambda) function in a wrapper class subclassing from 
Atom, thus circumventing storing any non-Basic in args.
On Friday, 1 October 2021 at 00:28:14 UTC+2 asme...@gmail.com wrote:

> It is relevant to think about how we might do this in other ways,
> though, because if we ever want to make Functions themselves Basic
> objects we would need to refactor them in a similar way
> (https://github.com/sympy/sympy/issues/4787). In fact, if Functions
> were objects, we could just store the function object on the
> QuantumGate args.
>
> Aaron Meurer
>
> On Thu, Sep 30, 2021 at 4:24 PM Aaron Meurer <asme...@gmail.com> wrote:
> >
> > My understanding is that an OracleGate is just the quantum version of
> > Function. It probably should just be Function (maybe a subclass that
> > mixes Function and Gate), with users creating oracles by subclassing
> > and defining eval.
> >
> > Aaron Meurer
> >
> > On Thu, Sep 30, 2021 at 4:12 PM Chris Smith <smi...@gmail.com> wrote:
> > >
> > > https://qiskit.org/textbook/ch-gates/oracles.html
> > >
> > > On Thursday, September 30, 2021 at 3:13:15 PM UTC-5 Oscar wrote:
> > >>
> > >> I don't know what the OracleGate class is for but I'm pretty sure 
> it's not very useful and it's certainly poorly designed. I'd rather just 
> delete it than try to come up with hacks to make it work.
> > >>
> > >> If someone wants to maintain the quantum module then that's great. 
> Until then we shouldn't allow broken code like this to complicate the 
> maintained part of the codebase.
> > >>
> > >> Oscar
> > >>
> > >> On Thu, 30 Sept 2021 at 21:08, Aaron Meurer <asme...@gmail.com> 
> wrote:
> > >>>
> > >>> Although storing f in the .args of an expression would be just as
> > >>> problematic as storing a lambda, because functions are not objects. 
> So
> > >>> you might need to make a custom evaluator class similar to Lambda 
> that
> > >>> stores a given lambda on it. It's a little messy because it breaks
> > >>> with the SymPy pattern that objects should only store symbolic data.
> > >>>
> > >>> Aaron Meurer
> > >>>
> > >>> On Thu, Sep 30, 2021 at 2:02 PM Aaron Meurer <asme...@gmail.com> 
> wrote:
> > >>> >
> > >>> > So it sounds like OracleGate needs the function to not be symbolic 
> at
> > >>> > all. You can use the following to create a symbolic function that
> > >>> > evaluates as a given lambda:
> > >>> >
> > >>> > >>> f = Function('f', eval=lambda x: x == 1)
> > >>> > >>> f(1)
> > >>> > True
> > >>> > >>> f(0)
> > >>> > False
> > >>> >
> > >>> > Aaron Meurer
> > >>> >
> > >>> > On Wed, Sep 29, 2021 at 8:19 PM Chris Smith <smi...@gmail.com> 
> wrote:
> > >>> > >
> > >>> > > The problem is that this returns an Eq instead of False when it 
> is not equal:
> > >>> > > ```
> > >>> > > >>> f = lambda x: x == 1
> > >>> > > >>> F = Lambda(x, f(SymbolicEquality(x)))
> > >>> > > >>> F(1)
> > >>> > > True
> > >>> > > >>> F(x)
> > >>> > > Eq(x, 1)
> > >>> > > >>> f(x)
> > >>> > > False
> > >>> > > ```
> > >>> > >
> > >>> > > On Tuesday, September 28, 2021 at 1:42:27 AM UTC-5 Oscar wrote:
> > >>> > >>
> > >>> > >> On Tue, 28 Sept 2021 at 04:13, Chris Smith <smi...@gmail.com> 
> wrote:
> > >>> > >>>
> > >>> > >>> I would like to emulate something like this with Basic 
> objects. I am drawing a blank on how that might be done. Does anyone have 
> any ideas?
> > >>> > >>>
> > >>> > >>> >>> f=lambda x: x==1
> > >>> > >>> >>> f(1)
> > >>> > >>> True
> > >>> > >>> >>> Lambda(x, f(x))(1) # doesn't work
> > >>> > >>> False
> > >>> > >>
> > >>> > >>
> > >>> > >> Something like this:
> > >>> > >>
> > >>> > >> In [7]: cat w.py
> > >>> > >> class SymbolicEquality:
> > >>> > >> def __init__(self, sym):
> > >>> > >> self.sym = sym
> > >>> > >> def __eq__(self, other):
> > >>> > >> return Equality(self.sym, other)
> > >>> > >>
> > >>> > >> In [8]: f = lambda x: x == 1
> > >>> > >>
> > >>> > >> In [9]: y = Dummy('y')
> > >>> > >>
> > >>> > >> In [10]: F = Lambda(y, f(SymbolicEquality(y)))
> > >>> > >>
> > >>> > >> In [11]: F
> > >>> > >> Out[11]: y ↦ y = 1
> > >>> > >>
> > >>> > >> --
> > >>> > >> Oscar
> > >>> > >
> > >>> > > --
> > >>> > > You received this message because you are subscribed to the 
> Google Groups "sympy" group.
> > >>> > > To unsubscribe from this group and stop receiving emails from 
> it, send an email to sympy+un...@googlegroups.com.
> > >>> > > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/13d15197-0d82-4312-b94a-ec59df616aedn%40googlegroups.com
> .
> > >>>
> > >>> --
> > >>> You received this message because you are subscribed to the Google 
> Groups "sympy" group.
> > >>> To unsubscribe from this group and stop receiving emails from it, 
> send an email to sympy+un...@googlegroups.com.
> > >>>
> > >>> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2Bt1wkS_mEg3AruG%2BLahUfDqqszP0ZAbi5XCsW4KXA4yw%40mail.gmail.com
> .
> > >
> > > --
> > > You received this message because you are subscribed to the Google 
> Groups "sympy" group.
> > > To unsubscribe from this group and stop receiving emails from it, send 
> an email to sympy+un...@googlegroups.com.
> > > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/eae0a8a1-2742-4d06-9581-3f0804ebe06cn%40googlegroups.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/8d3eb8bf-b58d-4433-a090-2d918f9e7badn%40googlegroups.com.

Reply via email to