K i[%RdZddlmZmZmZmZmZmZmZddl m Z ddl m Z m Z mZddlmZmZmZmZmZmZmZddgZeeeefeeeefeeeefee eeeeefeeeeiZej5Dcic]\}}|| c}}ZdZd Zd Zd Zd Z d Z!ycc}}w)a A module for mapping operators to their corresponding eigenstates and vice versa It contains a global dictionary with eigenstate-operator pairings. If a new state-operator pair is created, this dictionary should be updated as well. It also contains functions operators_to_state and state_to_operators for mapping between the two. These can handle both classes and instances of operators and states. See the individual function descriptions for details. TODO List: - Update the dictionary with a complete list of state-operator pairs )XOpYOpZOpXKetPxOpPxKet PositionKet3D)Operator) StateBaseBraBaseKet)JxOpJyOpJzOpJ2OpJxKetJyKetJzKetoperators_to_statestate_to_operatorsc $t|ttfst|ts t dt|tr|D].}t|trt|tr%t dt |}|t vr4 |Dcgc] }| }}tt |t|fi|}|S|Dcgc] }t|}}t |} | t vrtt | |fi|}|Sd}|S|t vr |} tt || fi|}|St|t vrtt t||fi|Sycc}w#t$r t |}Y|SwxYwcc}w#t$r t |}Y|SwxYw)a. Returns the eigenstate of the given operator or set of operators A global function for mapping operator classes to their associated states. It takes either an Operator or a set of operators and returns the state associated with these. This function can handle both instances of a given operator or just the class itself (i.e. both XOp() and XOp) There are multiple use cases to consider: 1) A class or set of classes is passed: First, we try to instantiate default instances for these operators. If this fails, then the class is simply returned. If we succeed in instantiating default instances, then we try to call state._operators_to_state on the operator instances. If this fails, the class is returned. Otherwise, the instance returned by _operators_to_state is returned. 2) An instance or set of instances is passed: In this case, state._operators_to_state is called on the instances passed. If this fails, a state class is returned. If the method returns an instance, that instance is returned. In both cases, if the operator class or set does not exist in the state_mapping dictionary, None is returned. Parameters ========== arg: Operator or set The class or instance of the operator or set of operators to be mapped to a state Examples ======== >>> from sympy.physics.quantum.cartesian import XOp, PxOp >>> from sympy.physics.quantum.operatorset import operators_to_state >>> from sympy.physics.quantum.operator import Operator >>> operators_to_state(XOp) |x> >>> operators_to_state(XOp()) |x> >>> operators_to_state(PxOp) |px> >>> operators_to_state(PxOp()) |px> >>> operators_to_state(Operator) |psi> >>> operators_to_state(Operator()) |psi> z%Argument is not an Operator or a set!zSet is not all Operators!N) isinstancer set issubclassNotImplementedError frozenset op_mapping _get_statetype) operatorsoptionssopsop op_instancesretotmpclasses op_instances g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/physics/quantum/operatorset.pyrr/sl y8S/ 2jH6U!"IJJ)S! GAq(+ H-)*EFF G  " *  &/233 3 C#l2COwOJ$'(q47(C(nG*$ G!4cEWEJJ  " ,'k  I!6 OwOJ )_ *ji99PP P9 4& & oJ & )' , +J ,s< E EEE4 E9EE10E19FFc t|tst|ts td|tvr4t |} t |tt|fi|}t|St|tvr1t |ttt|fi|}t|St|trK|jtvr5t |tt|j}t|St|trW|jtvrAt |} t |tt|j}t|Sd}t|S#ttf$rt|}Yt|SwxYw#ttf$r$t|j}Yt|SwxYw)a` Returns the operator or set of operators corresponding to the given eigenstate A global function for mapping state classes to their associated operators or sets of operators. It takes either a state class or instance. This function can handle both instances of a given state or just the class itself (i.e. both XKet() and XKet) There are multiple use cases to consider: 1) A state class is passed: In this case, we first try instantiating a default instance of the class. If this succeeds, then we try to call state._state_to_operators on that instance. If the creation of the default instance or if the calling of _state_to_operators fails, then either an operator class or set of operator classes is returned. Otherwise, the appropriate operator instances are returned. 2) A state instance is returned: Here, state._state_to_operators is called for the instance. If this fails, then a class or set of operator classes is returned. Otherwise, the instances are returned. In either case, if the state's class does not exist in state_mapping, None is returned. Parameters ========== arg: StateBase class or instance (or subclasses) The class or instance of the state to be mapped to an operator or set of operators Examples ======== >>> from sympy.physics.quantum.cartesian import XKet, PxKet, XBra, PxBra >>> from sympy.physics.quantum.operatorset import state_to_operators >>> from sympy.physics.quantum.state import Ket, Bra >>> state_to_operators(XKet) X >>> state_to_operators(XKet()) X >>> state_to_operators(PxKet) Px >>> state_to_operators(PxKet()) Px >>> state_to_operators(PxBra) Px >>> state_to_operators(XBra) X >>> state_to_operators(Ket) O >>> state_to_operators(Bra) O zArgument is not a state!N) rr rr state_mapping _make_default_get_ops _make_set TypeErrorrr dual_class)stater! state_instr&s r+rrsv ui (Jui,H!"<== "5)  ':$]5%9:G>EGC( S>! e %u tE{!;<I@GI S> E7 #(8(8(:m(Ku u/?/?/A!BCE S> E7 #(8(8(:m(K"5)  4:$]53C3C3E%FGIC S> S>%$Y/ '&C" S>% '$Y/ 4 0 0 23C S>  4s$E97*F!9FF!&GGc: |}|S#t$r|}Y|SwxYwN)r1)exprr&s r+r.r.s0f J  Js  c d |j|fi|}|S#t$rt|}Y|SwxYwr6)_operators_to_staterr.) state_classr#r!r&s r+rrsE)-k--c=W= J )K( J)s //c  |j|fi|}t|trt|dk(r|dS|S#t$r<t|ttt frt d|D}n t |}YiwxYw)Nc32K|]}t|ywr6)r.).0xs r+ z_get_ops.. s=Q a(=sr)_state_to_operatorsrrrtuplerr.len)r4 op_classesr!r&s r+r/r/s,,j,,ZC7C#sCA 1v J , j3y"9 :=*==C +C ,s:AA?>A?cRt|tttfr t |S|Sr6)rrBlistrr)r#s r+r0r0s!#tY/03x N)"__doc__sympy.physics.quantum.cartesianrrrrrrr sympy.physics.quantum.operatorr sympy.physics.quantum.stater r r sympy.physics.quantum.spinrrrrrrr__all__rr-itemsrrrr.rr/r0)kvs00r+rQs <<<3??/// D$<0D$<0D$<0xCc?!;   -224 5tq!ad 5 aHUp "O6s? B#