qojulia / QuantumCumulants.jl

Generalized mean-field equations in open quantum systems
Other
70 stars 13 forks source link

define real number parameter? #172

Closed Lightup1 closed 2 weeks ago

Lightup1 commented 1 year ago

There is a macro @cnumber. However sometimes, the expression can be further simplified when the parameters are real. Is there a way to define real number parameters?

Lightup1 commented 1 year ago

For now, I manually set conj(real_number) to real_number as a workaround for this issue. It is kind of inconvenient. For example, I need to manually define x_conj=g'/omega for x=g/omega with complex g and real omega.

Lightup1 commented 1 year ago

I do not go through all the code of QuantumCumulants.jl. It seems not complex that we can define a new type RNumber<:CNumber and define a function adjoint for this subtype. I'm not sure whether this definition will make the simplification workable directly.

david-pl commented 1 year ago

@Lightup1 the implementation you suggest would be an option. The other option, however, would be to implement something such as RNumber <: Real, which would then automatically simplify like

using SymbolicUtils
@syms p::Real
simplify(conj(p))  # p

We could additionally define an adjoint method then. The downside of this approach is that this requires some duplicated code, e.g. RealParamter <: RNumber (similar implementation to Parameter). Also, these types won't share the same supertype, but we can dispatch on const AbstractQCParameter = Union{CNumber, RNumber}.

I'm not entirely sure about all the details or which approach is best here, but I do see some appeal in having the symtype of a real parameter being <: Real since that is how SymbolicUtils does things.