scaluq.default.f64 ================== .. py:module:: scaluq.default.f64 .. autoapi-nested-parse:: module for f64 precision Subpackages ----------- .. toctree:: :maxdepth: 1 /autoapi/scaluq/default/f64/gate/index Classes ------- .. autoapisummary:: scaluq.default.f64.Gate scaluq.default.f64.ParamGate scaluq.default.f64.StateVector scaluq.default.f64.StateVectorBatched scaluq.default.f64.DensityMatrix scaluq.default.f64.SparseMatrixGate scaluq.default.f64.DenseMatrixGate scaluq.default.f64.Operator scaluq.default.f64.OperatorBatched scaluq.default.f64.IGate scaluq.default.f64.GlobalPhaseGate scaluq.default.f64.XGate scaluq.default.f64.YGate scaluq.default.f64.ZGate scaluq.default.f64.HGate scaluq.default.f64.SGate scaluq.default.f64.SdagGate scaluq.default.f64.TGate scaluq.default.f64.TdagGate scaluq.default.f64.SqrtXGate scaluq.default.f64.SqrtXdagGate scaluq.default.f64.SqrtYGate scaluq.default.f64.SqrtYdagGate scaluq.default.f64.P0Gate scaluq.default.f64.P1Gate scaluq.default.f64.RXGate scaluq.default.f64.RYGate scaluq.default.f64.RZGate scaluq.default.f64.U1Gate scaluq.default.f64.U2Gate scaluq.default.f64.U3Gate scaluq.default.f64.SwapGate scaluq.default.f64.EcrGate scaluq.default.f64.MeasurementGate scaluq.default.f64.PauliGate scaluq.default.f64.PauliRotationGate scaluq.default.f64.ParamRXGate scaluq.default.f64.ParamRYGate scaluq.default.f64.ParamRZGate scaluq.default.f64.ParamPauliRotationGate scaluq.default.f64.ParamProbabilisticGate scaluq.default.f64.Circuit scaluq.default.f64.PauliOperator Functions --------- .. autoapisummary:: scaluq.default.f64.merge_gate Package Contents ---------------- .. py:class:: Gate(arg) General class of QuantumGate. Notes Downcast to required to use gate-specific functions. .. py:method:: gate_type() Get gate type as `GateType` enum. .. rubric:: Examples >>> g = H(0) >>> print(g.gate_type()) GateType.H .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. rubric:: Examples >>> gate = CX(0, 1) >>> gate.target_qubit_list() [1] .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. rubric:: Examples >>> gate = CX(0, 1) >>> gate.control_qubit_list() [0] .. py:method:: control_value_list() Get control values as `list[int]`. .. rubric:: Examples >>> gate = CX(0, 1) >>> gate.control_value_list() [1] .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. rubric:: Examples >>> gate = CX(0, 1) >>> gate.operand_qubit_list() [0, 1] .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. rubric:: Examples >>> gate = H(0, controls=[1, 2], control_values=[1, 0]) >>> print(bin(gate.target_qubit_mask())) 0b1 .. py:method:: control_qubit_mask() Get control qubits as mask. .. rubric:: Examples >>> gate = H(0, controls=[1, 2], control_values=[1, 0]) >>> print(bin(gate.control_qubit_mask())) 0b110 .. py:method:: control_value_mask() Get control values as mask. .. rubric:: Examples >>> gate = H(0, controls=[1, 2], control_values=[1, 0]) >>> print(bin(gate.control_value_mask())) 0b10 .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. rubric:: Examples >>> gate = H(0, controls=[1, 2], control_values=[1, 0]) >>> print(bin(gate.operand_qubit_mask())) 0b111 .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. rubric:: Examples >>> s = S(0) >>> print(s.get_inverse()) Gate Type: Sdag Target Qubits: {0} Control Qubits: {} Control Value: {} .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. rubric:: Examples >>> gate = H(0, controls=[1, 2], control_values=[1, 0]) >>> print(gate.get_matrix()) [[ 0.70710678+0.j 0.70710678+0.j] [ 0.70710678+0.j -0.70710678+0.j]] .. py:method:: to_string() Get string representation of the gate. .. rubric:: Examples >>> g = H(0) >>> print(g.to_string()) Gate Type: H Target Qubits: {0} Control Qubits: {} Control Value: {} .. py:method:: to_json() Get JSON representation of the gate. .. rubric:: Examples >>> g = H(0) >>> print(g.to_json()) {"control":[],"control_value":[],"target":[0],"type":"H"} .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. rubric:: Examples >>> state = StateVector(2) >>> state.set_computational_basis(0) >>> H(0).update_quantum_state(state) >>> print(state) Qubit Count : 2 Dimension : 4 State vector : 00 : (0.707107,0) 01 : (0.707107,0) 10 : (0,0) 11 : (0,0) .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. rubric:: Examples >>> states = StateVectorBatched(2, 1) >>> states.set_computational_basis(0) >>> H(0).update_quantum_state(states) >>> print(states) Qubit Count : 1 Dimension : 2 -------------------- Batch_id : 0 State vector : 0 : (0.707107,0) 1 : (0.707107,0) -------------------- Batch_id : 1 State vector : 0 : (0.707107,0) 1 : (0.707107,0) .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. rubric:: Examples >>> state = StateVector(2) >>> state.set_computational_basis(0) >>> H(0).update_quantum_state(state) >>> print(state) Qubit Count : 2 Dimension : 4 State vector : 00 : (0.707107,0) 01 : (0.707107,0) 10 : (0,0) 11 : (0,0) .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. rubric:: Examples >>> states = StateVectorBatched(2, 1) >>> states.set_computational_basis(0) >>> H(0).update_quantum_state(states) >>> print(states) Qubit Count : 1 Dimension : 2 -------------------- Batch_id : 0 State vector : 0 : (0.707107,0) 1 : (0.707107,0) -------------------- Batch_id : 1 State vector : 0 : (0.707107,0) 1 : (0.707107,0) .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: phase() Get `phase` property. The phase is represented as $\gamma$. .. py:class:: ParamGate(arg) General class of parametric quantum gate. .. rubric:: Notes Downcast to required to use gate-specific functions. .. py:method:: param_gate_type() Get parametric gate type as `ParamGateType` enum. .. py:method:: param_coef() Get coefficient of parameter. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits is not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits is not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse parametric-gate as `ParamGate` type. If not exists, return None. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) Apply gate to `states` with holding the parameters. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: get_matrix(param) Get matrix representation of the gate with holding the parameter. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:class:: StateVector(n_qubits) Vector representation of quantum state. Qubit index is start from 0. If the i-th value of the vector is $a_i$, the state is $\sum_i a_i \ket{i}$. Given `n_qubits: int`, construct with bases $\ket{0\dots 0}$ holding `n_qubits` number of qubits. .. rubric:: Examples >>> state1 = StateVector(2) >>> print(state1) Qubit Count : 2 Dimension : 4 State vector : 00 : (1,0) 01 : (0,0) 10 : (0,0) 11 : (0,0) .. py:method:: Haar_random_state(n_qubits, seed = None) :staticmethod: Construct :class:`StateVector` with Haar random state. :param n_qubits: number of qubits :type n_qubits: int :param seed: random seed If not specified, the value from random device is used. :type seed: int | None, optional .. rubric:: Examples >>> state = StateVector.Haar_random_state(2) >>> print(state.get_amplitudes()) # doctest: +SKIP [(-0.3188299516496241+0.6723250989136779j), (-0.253461343768224-0.22430415678425403j), (0.24998142919420457+0.33096908710840045j), (0.2991187916479724+0.2650813322096342j)] >>> print(StateVector.Haar_random_state(2).get_amplitudes()) # If seed is not specified, generated vector differs. # doctest: +SKIP [(-0.49336775961196616-0.3319437726884906j), (-0.36069529482031787+0.31413708595210815j), (-0.3654176892043237-0.10307602590749808j), (-0.18175679804035652+0.49033467421609994j)] >>> print(StateVector.Haar_random_state(2, 0).get_amplitudes()) # doctest: +SKIP [(0.030776817573663098-0.7321137912473642j), (0.5679070655936114-0.14551095055034327j), (-0.0932995615041323-0.07123201881040941j), (0.15213024630399696-0.2871374092016799j)] >>> print(StateVector.Haar_random_state(2, 0).get_amplitudes()) # If same seed is specified, same vector is generated. # doctest: +SKIP [(0.030776817573663098-0.7321137912473642j), (0.5679070655936114-0.14551095055034327j), (-0.0932995615041323-0.07123201881040941j), (0.15213024630399696-0.2871374092016799j)] .. py:method:: uninitialized_state(n_qubits) :staticmethod: Construct :class:`StateVector` without initializing. :param n_qubits: number of qubits :type n_qubits: int .. py:method:: set_Haar_random_state(seed = None) Set Haar random state. :param seed: random seed If not specified, the value from random device is used. :type seed: int | None, optional .. rubric:: Examples >>> state = StateVector(2) >>> state.set_Haar_random_state() >>> print(state.get_amplitudes()) # doctest: +SKIP [(-0.3188299516496241+0.6723250989136779j), (-0.253461343768224-0.22430415678425403j), (0.24998142919420457+0.33096908710840045j), (0.2991187916479724+0.2650813322096342j)] .. py:method:: set_amplitude_at(index, value) Manually set amplitude at one index. :param index: index of state vector This is read as binary.k-th bit of index represents k-th qubit. :type index: int :param value: amplitude value to set at index :type value: complex .. rubric:: Examples >>> state = StateVector(2) >>> state.get_amplitudes() [(1+0j), 0j, 0j, 0j] >>> state.set_amplitude_at(2, 3+1j) >>> state.get_amplitudes() [(1+0j), 0j, (3+1j), 0j] .. rubric:: Notes If you want to set amplitudes at all indices, you should use :meth:`.load`. .. py:method:: get_amplitude_at(index) Get amplitude at one index. :param index: index of state vector This is read as binary. k-th bit of index represents k-th qubit. :type index: int :returns: Amplitude at specified index :rtype: complex .. rubric:: Examples >>> state = StateVector(2) >>> state.load([1+2j, 3+4j, 5+6j, 7+8j]) >>> state.get_amplitude_at(0) (1+2j) >>> state.get_amplitude_at(1) (3+4j) >>> state.get_amplitude_at(2) (5+6j) >>> state.get_amplitude_at(3) (7+8j) .. rubric:: Notes If you want to get amplitudes at all indices, you should use :meth:`.get_amplitudes`. .. py:method:: set_zero_state() Initialize with computational basis $\ket{00\dots0}$. .. rubric:: Examples >>> state = StateVector.Haar_random_state(2) >>> state.get_amplitudes() # doctest: +SKIP [(-0.05726462181150916+0.3525270165415515j), (0.1133709060491142+0.3074930854078303j), (0.03542174692996924+0.18488950377672345j), (0.8530024105558827+0.04459332470844164j)] >>> state.set_zero_state() >>> state.get_amplitudes() [(1+0j), 0j, 0j, 0j] .. py:method:: set_zero_norm_state() Initialize with $0$ (null vector). .. rubric:: Examples >>> state = StateVector(2) >>> state.get_amplitudes() [(1+0j), 0j, 0j, 0j] >>> state.set_zero_norm_state() >>> state.get_amplitudes() [0j, 0j, 0j, 0j] .. py:method:: set_computational_basis(basis) Initialize with computational basis $\ket{\mathrm{basis}}$. :param basis: basis as integer format ($0 \leq \mathrm{basis} \leq 2^{\mathrm{n\_qubits}}-1$) :type basis: int .. rubric:: Examples >>> state = StateVector(2) >>> state.set_computational_basis(0) # |00> >>> state.get_amplitudes() [(1+0j), 0j, 0j, 0j] >>> state.set_computational_basis(1) # |01> >>> state.get_amplitudes() [0j, (1+0j), 0j, 0j] >>> state.set_computational_basis(2) # |10> >>> state.get_amplitudes() [0j, 0j, (1+0j), 0j] >>> state.set_computational_basis(3) # |11> >>> state.get_amplitudes() [0j, 0j, 0j, (1+0j)] .. py:method:: get_amplitudes() Get all amplitudes as `list[complex]`. :returns: amplitudes of list with len $2^{\mathrm{n\_qubits}}$ :rtype: list[complex] .. rubric:: Examples >>> state = StateVector(2) >>> state.get_amplitudes() [(1+0j), 0j, 0j, 0j] .. py:method:: n_qubits() Get num of qubits. :returns: num of qubits :rtype: int .. rubric:: Examples >>> state = StateVector(2) >>> state.n_qubits() 2 .. py:method:: dim() Get dimension of the vector ($=2^\mathrm{n\_qubits}$). :returns: dimension of the vector :rtype: int .. rubric:: Examples >>> state = StateVector(2) >>> state.dim() 4 .. py:method:: get_squared_norm() Get squared norm of the state. $\braket{\psi|\psi}$. :returns: squared norm of the state :rtype: float .. rubric:: Examples >>> v = [1+2j, 3+4j, 5+6j, 7+8j] >>> state = StateVector(2) >>> state.load(v) >>> state.get_squared_norm() 204.0 >>> sum([abs(a)**2 for a in v]) 204.0 .. py:method:: normalize() Normalize state. Let $\braket{\psi|\psi} = 1$ by multiplying constant. .. rubric:: Examples >>> v = [1+2j, 3+4j, 5+6j, 7+8j] >>> state = StateVector(2) >>> state.load(v) >>> norm = state.get_squared_norm()**.5 >>> state.normalize() >>> state.get_amplitudes() [(0.07001400420140048+0.14002800840280097j), (0.21004201260420147+0.28005601680560194j), (0.3500700210070024+0.42008402520840293j), (0.4900980294098034+0.5601120336112039j)] >>> [a / norm for a in v] [(0.07001400420140048+0.14002800840280097j), (0.21004201260420147+0.28005601680560194j), (0.3500700210070024+0.42008402520840293j), (0.4900980294098034+0.5601120336112039j)] .. py:method:: get_zero_probability(index) Get the probability to observe $\ket{0}$ at specified index. **State must be normalized.** :param index: qubit index to be observed :type index: int :returns: probability to observe $\ket{0}$ :rtype: float .. rubric:: Examples >>> v = [1 / 6**.5, 2j / 6**.5 * 1j, -1 / 6**.5, -2j / 6**.5] >>> state = StateVector(2) >>> state.load(v) >>> state.get_zero_probability(0) 0.3333333333333334 >>> state.get_zero_probability(1) 0.8333333333333336 >>> abs(v[0])**2+abs(v[2])**2 0.3333333333333334 >>> abs(v[0])**2+abs(v[1])**2 0.8333333333333336 .. py:method:: get_marginal_probability(measured_values) Get the marginal probability to observe as given. **State must be normalized.** :param measured_values: list with len n_qubits. `0`, `1` or :attr:`.UNMEASURED` is allowed for each elements. `0` or `1` shows the qubit is observed and the value is got. :attr:`.UNMEASURED` shows the the qubit is not observed. :type measured_values: list[int] :returns: probability to observe as given :rtype: float .. rubric:: Examples >>> v = [1/4, 1/2, 0, 1/4, 1/4, 1/2, 1/4, 1/2] >>> state = StateVector(3) >>> state.load(v) >>> state.get_marginal_probability([0, 1, StateVector.UNMEASURED]) 0.0625 >>> abs(v[2])**2 + abs(v[6])**2 0.0625 .. py:method:: get_computational_basis_entropy() Get the Shannon entropy of the Z-basis measurement distribution. **State must be normalized.** :returns: entropy :rtype: float .. rubric:: Examples >>> v = [1/4, 1/2, 0, 1/4, 1/4, 1/2, 1/4, 1/2] >>> state = StateVector(3) >>> state.load(v) >>> state.get_computational_basis_entropy() 2.5 >>> import math >>> sum(-abs(a)**2 * math.log2(abs(a)**2) for a in v if a != 0) 2.5 .. rubric:: Notes The result of this function differs from qulacs. This is because scaluq adopted 2 for the base of log in the definition of entropy $\sum_i -p_i \log p_i$ however qulacs adopted e. .. py:method:: add_state_vector_with_coef(coef, state) Add other state vector with multiplying the coef and make superposition. $\ket{\mathrm{this}}\leftarrow\ket{\mathrm{this}}+\mathrm{coef} \ket{\mathrm{state}}$. :param coef: coefficient to multiply to `state` :type coef: complex :param state: state to be added :type state: :class:`StateVector` .. rubric:: Examples >>> state1 = StateVector(1) >>> state1.load([1, 2]) >>> state2 = StateVector(1) >>> state2.load([3, 4]) >>> state1.add_state_vector_with_coef(2j, state2) >>> state1.get_amplitudes() [(1+6j), (2+8j)] .. py:method:: multiply_coef(coef) Multiply coef. $\ket{\mathrm{this}}\leftarrow\mathrm{coef}\ket{\mathrm{this}}$. :param coef: coefficient to multiply :type coef: complex .. rubric:: Examples >>> state = StateVector(1) >>> state.load([1, 2]) >>> state.multiply_coef(2j) >>> state.get_amplitudes() [2j, 4j] .. py:method:: sampling(sampling_count, seed = None) Sampling state vector independently and get list of computational basis :param sampling_count: how many times to apply sampling :type sampling_count: int :param seed: random seed If not specified, the value from random device is used. :type seed: int | None, optional :returns: result of sampling list of `sampling_count` length. Each element is in $[0,2^{\mathrm{n\_qubits}})$ :rtype: list[int] .. rubric:: Examples >>> state = StateVector(2) >>> state.load([1/2, 0, -3**.5/2, 0]) >>> state.sampling(8) # doctest: +SKIP [0, 2, 2, 2, 2, 0, 0, 2] .. py:method:: to_string() Information as `str`. :returns: information as str :rtype: str .. rubric:: Examples >>> state = StateVector(1) >>> state.to_string() 'Qubit Count : 1\nDimension : 2\nState vector : \n 0 : (1,0)\n 1 : (0,0)\n' .. py:method:: load(other) Load amplitudes of `Sequence` :param other: list of complex amplitudes with len $2^{\mathrm{n\_qubits}}$ :type other: collections.abc.Sequence[complex] .. py:method:: load(other) Load amplitudes of :class:`StateVector` :param other: State vector to load from. :type other: :class:`StateVector` .. py:method:: copy_to_default_space() Return a deep copy in the default execution space. :returns: Copied state vector. :rtype: :class:`scaluq.default.f64.StateVector` .. py:method:: copy_to_host_space() Return a deep copy in the host execution space. :returns: Copied state vector. :rtype: :class:`scaluq.host.f64.StateVector` .. py:method:: inner_product(a, b) :staticmethod: Calculate inner product $\braket{a | b}$. :param a: left hand side of inner product :type a: :class:`StateVector` :param b: right hand side of inner product :type b: :class:`StateVector` :returns: inner product $\braket{a | b}$ :rtype: complex .. rubric:: Examples >>> state1 = StateVector(2) >>> state1.load([1/2, 0, 0, 1/2]) # (|00> + |11>)/sqrt(2) >>> state2 = StateVector(2) >>> state2.load([1/2, 0, 0, -1/2]) # (|00> - |11>)/sqrt(2) >>> StateVector.inner_product(state1, state2) 0j .. py:attribute:: UNMEASURED :type: int :value: Ellipsis Constant used for `StateVector::get_marginal_probability` to express the the qubit is not measured. .. py:method:: to_json() Information as json style. :returns: information as json style :rtype: str .. rubric:: Examples >>> state = StateVector(1) >>> state.to_json() '{"amplitudes":[{"imag":0.0,"real":1.0},{"imag":0.0,"real":0.0}],"n_qubits":1}' .. py:method:: load_json(json_str) Read an object from the JSON representation of the state vector. .. py:class:: StateVectorBatched(batch_size, n_qubits) Batched vector representation of quantum state. Qubit index starts from 0. If the amplitudes of $\ket{b_{n-1}\dots b_0}$ are $b_i$, the state is $\sum_i b_i 2^i$. Given `batch_size: int, n_qubits: int`, construct a batched state vector with specified batch size and qubits. Given `other: StateVectorBatched`, Construct a batched state vector by copying another batched state. .. rubric:: Examples >>> states = StateVectorBatched(3, 2) >>> print(states) Qubit Count : 2 Dimension : 4 -------------------- Batch_id : 0 State vector : 00 : (1,0) 01 : (0,0) 10 : (0,0) 11 : (0,0) -------------------- Batch_id : 1 State vector : 00 : (1,0) 01 : (0,0) 10 : (0,0) 11 : (0,0) -------------------- Batch_id : 2 State vector : 00 : (1,0) 01 : (0,0) 10 : (0,0) 11 : (0,0) .. py:method:: n_qubits() Get the number of qubits in each state vector. :returns: The number of qubits. :rtype: int .. py:method:: dim() Get the dimension of each state vector (=$2^{\mathrm{n\_qubits}}$). :returns: The dimension of the vector. :rtype: int .. py:method:: batch_size() Get the batch size (number of state vectors). :returns: The batch size. :rtype: int .. py:method:: set_state_vector(state) Set all state vectors in the batch to the given state. :param state: State to set for all batches. :type state: StateVector .. py:method:: set_state_vector_at(batch_id, state) Set the state vector at a specific batch index. :param batch_id: Index in batch to set. :type batch_id: int :param state: State to set at the specified index. :type state: StateVector .. py:method:: get_state_vector_at(batch_id) Get the state vector at a specific batch index. :param batch_id: Index in batch to get. :type batch_id: int :returns: The state vector at the specified batch index. :rtype: StateVector .. py:method:: view_state_vector_at(batch_id) Return a view of the state vector at a specific batch index. :param batch_id: Index in batch to view. :type batch_id: int :returns: A view of the state vector at the specified batch index. :rtype: StateVector .. py:method:: set_zero_state() Initialize all states to |0...0⟩. .. py:method:: set_computational_basis(basis) Set all states to the specified computational basis state. :param basis: Index of the computational basis state. :type basis: int .. py:method:: set_zero_norm_state() Set all amplitudes to zero. .. py:method:: set_Haar_random_state(set_same_state, seed = None) Initialize with Haar random states. :param batch_size: Number of states in batch. :type batch_size: int :param n_qubits: Number of qubits per state. :type n_qubits: int :param set_same_state: Whether to set all states to the same random state. :type set_same_state: bool :param seed: Random seed (default: random). :type seed: int, optional .. py:method:: Haar_random_state(batch_size, n_qubits, set_same_state, seed = None) :staticmethod: Construct :class:`StateVectorBatched` with Haar random state. :param batch_size: Number of states in batch. :type batch_size: int :param n_qubits: Number of qubits per state. :type n_qubits: int :param set_same_state: Whether to set all states to the same random state. :type set_same_state: bool :param seed: Random seed (default: random). :type seed: int, optional :returns: New batched state vector with random states. :rtype: StateVectorBatched .. py:method:: uninitialized_state(batch_size, n_qubits) :staticmethod: Construct :class:`StateVectorBatched` without initializing. :param batch_size: Number of states in batch. :type batch_size: int :param n_qubits: number of qubits :type n_qubits: int .. py:method:: get_squared_norm() Get squared norm for each state in the batch. :returns: List of squared norms. :rtype: list[float] .. py:method:: normalize() Normalize all states in the batch. .. py:method:: get_zero_probability(target_qubit_index) Get probability of measuring |0⟩ on specified qubit for each state. :param target_qubit_index: Index of qubit to measure. :type target_qubit_index: int :returns: Probabilities for each state in batch. :rtype: list[float] .. py:method:: get_marginal_probability(measured_values) Get marginal probabilities for specified measurement outcomes. :param measured_values: Measurement configuration. :type measured_values: list[int] :returns: Probabilities for each state in batch. :rtype: list[float] .. py:method:: get_computational_basis_entropy() Calculate the Shannon entropy of the Z-basis measurement distribution for each state. :returns: Entropy values for each state. :rtype: list[float] .. py:method:: sampling(sampling_count, seed = None) Sample from the probability distribution of each state. :param sampling_count: Number of samples to take. :type sampling_count: int :param seed: Random seed (default: random). :type seed: int, optional :returns: Samples for each state in batch. :rtype: list[list[int]] .. py:method:: add_state_vector_with_coef(coef, states) Add another batched state vector multiplied by a coefficient. :param coef: Coefficient to multiply with states. :type coef: complex :param states: States to add. :type states: StateVectorBatched .. py:method:: multiply_coef(coef) Multiply all states by a coefficient. :param coef: Coefficient to multiply. :type coef: complex .. py:method:: load(states) Load amplitudes for all states in batch. :param states: Amplitudes for each state. :type states: list[list[complex]] .. py:method:: load(other) Load states from another :class:`StateVectorBatched`. :param other: Batched state vector to load from. :type other: :class:`StateVectorBatched` .. py:method:: get_reduced_state() Get the sum of all states in the batch as a single state vector. :returns: Reduced state vector. :rtype: StateVector .. py:method:: get_amplitudes() Get amplitudes of all states in batch. :returns: Amplitudes for each state. :rtype: list[list[complex]] .. py:method:: copy() Create a deep copy of this batched state vector. :returns: New copy of the states. :rtype: StateVectorBatched .. py:method:: copy_to_default_space() Return a deep copy in the default execution space. :returns: Copied batched state vector. :rtype: :class:`scaluq.default.f64.StateVectorBatched` .. py:method:: copy_to_host_space() Return a deep copy in the host execution space. :returns: Copied batched state vector. :rtype: :class:`scaluq.host.f64.StateVectorBatched` .. py:method:: to_string() Get string representation of the batched states. :returns: String representation of states. :rtype: str .. rubric:: Examples >>> states = StateVectorBatched(2, 3) >>> print(states.to_string()) Qubit Count : 3 Dimension : 8 -------------------- Batch_id : 0 State vector : 000 : (1,0) 001 : (0,0) 010 : (0,0) 011 : (0,0) 100 : (0,0) 101 : (0,0) 110 : (0,0) 111 : (0,0) -------------------- Batch_id : 1 State vector : 000 : (1,0) 001 : (0,0) 010 : (0,0) 011 : (0,0) 100 : (0,0) 101 : (0,0) 110 : (0,0) 111 : (0,0) .. py:method:: to_json() Convert states to JSON string. :returns: JSON representation of states. :rtype: str .. rubric:: Examples >>> states = StateVectorBatched(2, 3) >>> print(states.to_json()) {"amplitudes":[[{"imag":0.0,"real":1.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0}],[{"imag":0.0,"real":1.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0}]],"batch_size":2,"n_qubits":3} .. py:method:: load_json(json_str) Load states from JSON string. :param json_str: JSON string to load from. :type json_str: str .. py:class:: DensityMatrix(n_qubits) DensityMatrix representation of quantum state. Qubit index is start from 0. If the (i,j)-th value of the matrix is $a_{ij}$, the state is $\sum_{i,j} a_{ij} \ket{i}\bra{j}$. .. py:method:: n_qubits() Get the number of qubits. :returns: number of qubits :rtype: int .. rubric:: Examples >>> state = DensityMatrix(3) >>> state.n_qubits() 3 .. py:method:: dim() Get the dimension of the density matrix. ($=2^\mathrm{n\_qubits}$). :returns: dimension of the density matrix :rtype: int .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.dim() 4 .. py:method:: is_hermitian() Check if the density matrix is guaranteed to be Hermitian. :returns: True if the density matrix is Hermitian, False if it may not be Hermitian :rtype: bool .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.is_hermitian() True .. py:method:: force_hermitian() Force the density matrix to be treated as Hermitian. This may enable certain optimizations but should only be used if you are sure the matrix is actually Hermitian. .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.multiply_coef(1j) >>> state.multiply_coef(-1j) >>> state.is_hermitian() False >>> state.force_hermitian() >>> state.is_hermitian() True .. py:method:: get_coherence_at(row_index, col_index) Get coherence at specified position. This is a very slow operation. Use get_matrix() instead if possible. :param row_index: row index :type row_index: int :param col_index: column index :type col_index: int :returns: coherence at the specified position :rtype: complex .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.get_coherence_at(0, 0) (1+0j) >>> state.get_coherence_at(0, 1) 0j .. py:method:: set_coherence_at(row_index, col_index, value) Set coherence at specified position. This is a very slow operation. Use load() instead if possible. is_hermitian is set to False unless diagonal element and real value is passed in. :param row_index: row index :type row_index: int :param col_index: column index :type col_index: int :param value: value to set at the specified position :type value: complex .. rubric:: Examples >>> state = DensityMatrix(2) >>> print(state.get_matrix()) [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] >>> state.set_coherence_at(0, 1, 0.5+0.5j) >>> print(state.get_matrix()) [[1. +0.j 0.5+0.5j 0. +0.j 0. +0.j ] [0. +0.j 0. +0.j 0. +0.j 0. +0.j ] [0. +0.j 0. +0.j 0. +0.j 0. +0.j ] [0. +0.j 0. +0.j 0. +0.j 0. +0.j ]] .. py:method:: set_coherence_pair_at(row_index, col_index, value) Set coherence at specified position and its conjugate position to maintain Hermitian property. This is a very slow operation. Use load() instead if possible. :param row_index: row index :type row_index: int :param col_index: column index :type col_index: int :param value: value to set at the specified position :type value: complex .. rubric:: Examples >>> state = DensityMatrix(2) >>> print(state.get_matrix()) [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] >>> state.set_coherence_pair_at(0, 1, 0.5+0.5j) >>> print(state.get_matrix()) [[1. +0.j 0.5+0.5j 0. +0.j 0. +0.j ] [0.5-0.5j 0. +0.j 0. +0.j 0. +0.j ] [0. +0.j 0. +0.j 0. +0.j 0. +0.j ] [0. +0.j 0. +0.j 0. +0.j 0. +0.j ]] .. py:method:: get_matrix() Get the density matrix as ndarray. :returns: density matrix as 2D array :rtype: Annotated[numpy.typing.NDArray[numpy.complex128], dict(shape=(None, None), order=’C’)] .. rubric:: Examples >>> state = DensityMatrix(2) >>> print(state.get_matrix()) [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] .. py:method:: copy() Get a copy of the density matrix. :returns: a copy of the density matrix :rtype: DensityMatrix .. rubric:: Examples >>> state1 = DensityMatrix(2) >>> state2 = state1.copy() >>> print(state1.get_matrix()) [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] >>> print(state2.get_matrix()) [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] .. py:method:: copy_to_default_space() Get a copy of the density matrix in the default execution space. :returns: a copy of the density matrix in the default execution space :rtype: :class:`scaluq.default.f64.DensityMatrix` .. rubric:: Examples >>> state_host = DensityMatrix(2) >>> state_default = state_host.copy_to_default_space() >>> print(state_default.get_matrix()) [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] .. py:method:: copy_to_host_space() Get a copy of the density matrix in the host execution space. :returns: a copy of the density matrix in the host execution space :rtype: :class:`scaluq.host.f64.DensityMatrix` .. rubric:: Examples >>> state_default = DensityMatrix(2) >>> state_host = state_default.copy_to_host_space() >>> print(state_host.get_matrix()) [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] .. py:method:: load(matrix, is_hermitian = False) Load the density matrix from a 2D array. :param matrix: 2D array representing the density matrix :type matrix: Annotated[numpy.typing.NDArray[numpy.complex128], dict(shape=(None, None), order=’C’)] :param is_hermitian: Whether the input matrix is guaranteed to be Hermitian. :type is_hermitian: bool .. rubric:: Examples >>> import numpy as np >>> state = DensityMatrix(1) >>> matrix = np.array([[0.5+0.5j, 0], [0, 0.5-0.5j]]) >>> state.load(matrix, is_hermitian=True) >>> print(state.get_matrix()) [[0.5+0.5j 0. +0.j ] [0. +0.j 0.5-0.5j]] .. py:method:: load(other) Load the density matrix from another DensityMatrix. :param other: DensityMatrix to load from :type other: DensityMatrix .. rubric:: Examples >>> state1 = DensityMatrix.Haar_random_state(1) >>> print(state1.get_matrix()) # doctest: +SKIP [[ 0.35920411+8.30722924e-18j -0.29205502-3.80631554e-01j] [-0.29205502+3.80631554e-01j 0.64079589+5.48595618e-18j]] >>> state2 = DensityMatrix(1) >>> state2.load(state1) >>> print(state2.get_matrix()) # doctest: +SKIP [[ 0.35920411+8.30722924e-18j -0.29205502-3.80631554e-01j] [-0.29205502+3.80631554e-01j 0.64079589+5.48595618e-18j]] .. py:method:: load(state_vector) Load the density matrix from a StateVector. The density matrix is set to $\ket{\psi}\bra{\psi}$ where $\ket{\psi}$ is the input state vector. :param state_vector: StateVector to load from :type state_vector: StateVector .. rubric:: Examples >>> sv = StateVector(2) >>> sv.set_computational_basis(1) >>> dm = DensityMatrix(2) >>> dm.load(sv) >>> print(dm.get_matrix()) [[0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 1.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] .. py:method:: uninitialized_state(n_qubits) :staticmethod: Create an uninitialized density matrix with specified number of qubits. :param n_qubits: number of qubits :type n_qubits: int :returns: an uninitialized density matrix :rtype: DensityMatrix .. py:method:: Haar_random_state(n_qubits, seed = None) :staticmethod: Create a density matrix representing a Haar random state. :param n_qubits: number of qubits :type n_qubits: int :param seed: random seed If not specified, the value from random device is used. :type seed: int | None, optional :returns: a density matrix representing a Haar random state :rtype: DensityMatrix .. rubric:: Examples >>> state = DensityMatrix.Haar_random_state(1) >>> print(state.get_matrix()) # doctest: +SKIP [[ 0.35920411+8.30722924e-18j -0.29205502-3.80631554e-01j] [-0.29205502+3.80631554e-01j 0.64079589+5.48595618e-18j]] >>> state1 = DensityMatrix.Haar_random_state(1, seed=42) >>> state2 = DensityMatrix.Haar_random_state(1, seed=42) >>> print(state1.get_matrix()) # doctest: +SKIP [[ 0.7662367 -2.34701458e-17j -0.35360255-2.32558070e-01j] [-0.35360255+2.32558070e-01j 0.2337633 -7.47914693e-19j]] >>> print(state2.get_matrix()) # doctest: +SKIP [[ 0.7662367 -2.34701458e-17j -0.35360255-2.32558070e-01j] [-0.35360255+2.32558070e-01j 0.2337633 -7.47914693e-19j]] .. py:method:: set_zero_state() Set the density matrix to the zero state $\ket{0\dots0}\bra{0\dots0}$. .. rubric:: Examples >>> state = DensityMatrix.uninitialized_state(2) >>> state.set_zero_state() >>> print(state.get_matrix()) [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] .. py:method:: set_zero_norm_state() Set the density matrix to the 0 (zero matrix). .. rubric:: Examples >>> state = DensityMatrix.uninitialized_state(2) >>> state.set_zero_norm_state() >>> print(state.get_matrix()) [[0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] .. py:method:: set_computational_basis(basis_index) Set the density matrix to a computational basis state $\ket{b}\bra{b}$ where $b$ is the binary representation of the input basis index. :param basis_index: index of the computational basis state to set (0-based) :type basis_index: int .. rubric:: Examples >>> state = DensityMatrix.uninitialized_state(2) >>> state.set_computational_basis(2) # sets state to |10><10| >>> print(state.get_matrix()) [[0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 1.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+0.j]] .. py:method:: set_Haar_random_state(seed = None) Set the density matrix to represent a Haar random state. :param seed: random seed If not specified, the value from random device is used. :type seed: int | None, optional .. rubric:: Examples >>> state = DensityMatrix(1) >>> state.set_Haar_random_state(seed=42) >>> print(state.get_matrix()) # doctest: +SKIP [[ 0.7662367 -2.34701458e-17j -0.35360255-2.32558070e-01j] [-0.35360255+2.32558070e-01j 0.2337633 -7.47914693e-19j]] .. py:method:: get_trace() Calculate the trace of the density matrix. :returns: trace of the density matrix :rtype: complex .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.get_trace() (1+0j) .. py:method:: get_partial_trace(traced_out_qubits) Calculate the partial trace of the density matrix by tracing out the specified qubits. :param traced_out_qubits: indices of qubits to be traced out :type traced_out_qubits: collections.abc.Sequence[int] :returns: the resulting density matrix after partial trace :rtype: DensityMatrix .. rubric:: Examples >>> state = DensityMatrix.Haar_random_state(2) >>> print(state.get_matrix()) # doctest: +SKIP [[ 0.51491987-2.74660016e-17j -0.23762498-1.56281696e-01j 0.10531599+3.49755601e-01j -0.13503799+1.31271109e-01j] [-0.23762498+1.56281696e-01j 0.15709162+1.84452504e-20j -0.15475438-1.29440927e-01j 0.02247559-1.01563879e-01j] [ 0.10531599-3.49755601e-01j -0.15475438+1.29440927e-01j 0.25910912-1.49078030e-18j 0.06154578+1.18572309e-01j] [-0.13503799-1.31271109e-01j 0.02247559+1.01563879e-01j 0.06154578-1.18572309e-01j 0.06887938-1.44012992e-19j]] >>> reduced_state = state.get_partial_trace([1]) >>> print(reduced_state.get_matrix()) # doctest: +SKIP [[ 0.774029 -2.89567819e-17j -0.17607919-3.77093869e-02j] [-0.17607919+3.77093869e-02j 0.225971 -1.25567742e-19j]] .. py:method:: normalize() Normalize the density matrix so that its trace becomes 1. .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.multiply_coef(2) >>> state.normalize() >>> print(state.get_trace()) (1+0j) .. py:method:: get_purity() Calculate the purity of the quantum state represented by the density matrix. Purity is defined as $\mathrm{Tr}(\rho^2)$ where $\rho$ is the density matrix. :returns: purity of the quantum state :rtype: float .. rubric:: Examples >>> state1 = DensityMatrix.Haar_random_state(2, 0) >>> print(state1.get_purity()) # doctest: +SKIP 1.0000000000000002 >>> state2 = DensityMatrix.Haar_random_state(2, 1) >>> state1.multiply_coef(0.5) >>> state1.add_density_matrix_with_coef(0.5, state2) >>> print(state1.get_purity()) # doctest: +SKIP 0.6238584782007198 .. rubric:: Notes The matrix must be hermitian and normalized .. py:method:: get_zero_probability(target_qubit_index) Calculate the probability of measuring 0 on the target qubit. :param target_qubit_index: index of the target qubit :type target_qubit_index: int :returns: probability of measuring 0 on the target qubit :rtype: float .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.set_computational_basis(2) # sets state to |10><10| >>> state.get_zero_probability(0) 1.0 >>> state.get_zero_probability(1) 0.0 .. rubric:: Notes The matrix must be hermitian and normalized .. py:method:: get_marginal_probability(measured_values) Get the marginal probability to observe as given. :param measured_values: list with len n_qubits. `0`, `1` or :attr:`.UNMEASURED` is allowed for each elements. `0` or `1` shows the qubit is observed and the value is got. :attr:`.UNMEASURED` shows the the qubit is not observed. :type measured_values: list[int] :returns: probability to observe as given :rtype: float .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.set_computational_basis(2) # sets state to |10><10| >>> state.get_marginal_probability([0, 1]) 1.0 >>> state.get_marginal_probability([0, DensityMatrix.UNMEASURED]) 1.0 >>> state.get_marginal_probability([DensityMatrix.UNMEASURED, 1]) 1.0 >>> state.get_marginal_probability([1, DensityMatrix.UNMEASURED]) 0.0 .. rubric:: Notes The matrix must be hermitian and normalized .. py:method:: sampling(sampling_count, seed = None) Sampling density matrix independently and get list of computational basis :param sampling_count: number of samples to draw :type sampling_count: int :param seed: random seed If not specified, the value from random device is used. :type seed: int | None, optional :returns: list of sampled computational basis represented as integers :rtype: List[int] .. rubric:: Examples >>> import numpy as np >>> state = DensityMatrix.uninitialized_state(1) >>> state.load(np.array([[0.5, -0.5j], [0.5j, 0.5]]), True) >>> print(state.sampling(10, seed=42)) # doctest: +SKIP [0, 1, 1, 0, 0, 0, 1, 0, 1, 1] .. rubric:: Notes The matrix must be hermitian and normalized .. py:method:: get_computational_basis_entropy() Calculate the computational basis entropy of the quantum state represented by the density matrix. Computational basis entropy is defined as $-\sum_i p_i \log_2 p_i$ where $p_i$ is the probability of measuring the computational basis state $\ket{i}$, which can be calculated as the (i,i)-th element of the density matrix. :returns: computational basis entropy of the quantum state :rtype: float .. rubric:: Examples >>> state = DensityMatrix(2) >>> state.set_computational_basis(2) # sets state to |10><10| >>> state.get_computational_basis_entropy() 0.0 >>> import numpy as np >>> state = DensityMatrix.uninitialized_state(1) >>> state.load(np.array([[0.5, -0.5j], [0.5j, 0.5]]), True) >>> state.get_computational_basis_entropy() 1.0 .. rubric:: Notes The matrix must be hermitian and normalized .. py:method:: add_density_matrix_with_coef(coef, other) Add another density matrix to this density matrix with a coefficient. This performs the operation $\rho \leftarrow \rho + c \sigma$ where $\rho$ is this density matrix, $c$ is the coefficient and $\sigma$ is the other density matrix. :param coef: coefficient to multiply the other density matrix :type coef: complex :param other: the other density matrix to be added :type other: DensityMatrix .. rubric:: Examples >>> state1 = DensityMatrix.Haar_random_state(1, 1) >>> state2 = DensityMatrix.Haar_random_state(1, 2) >>> print(state1.get_matrix()) # doctest: +SKIP [[ 0.51823805+2.35020398e-18j -0.20611927-4.55172737e-01j] [-0.20611927+4.55172737e-01j 0.48176195+2.36023838e-19j]] >>> print(state2.get_matrix()) # doctest: +SKIP [[0.20777367+3.60776697e-18j 0.36552629-1.76051983e-01j] [0.36552629+1.76051983e-01j 0.79222633-1.66856281e-17j]] >>> state1.add_density_matrix_with_coef(0.5, state2) >>> print(state1.get_matrix()) # doctest: +SKIP [[ 0.62212489+4.15408747e-18j -0.02335612-5.43198728e-01j] [-0.02335612+5.43198728e-01j 0.87787511-8.10679023e-18j]] .. py:method:: multiply_coef(coef) Multiply this density matrix by a coefficient. This performs the operation $\rho \leftarrow c \rho$ where $\rho$ is this density matrix and $c$ is the coefficient. :param coef: coefficient to multiply the density matrix :type coef: complex .. rubric:: Examples >>> state = DensityMatrix.Haar_random_state(1, 1) >>> print(state.get_matrix()) # doctest: +SKIP [[ 0.51823805+2.35020398e-18j -0.20611927-4.55172737e-01j] [-0.20611927+4.55172737e-01j 0.48176195+2.36023838e-19j]] >>> state.multiply_coef(2) >>> print(state.get_matrix()) # doctest: +SKIP [[ 1.0364761 +4.70040797e-18j -0.41223854-9.10345474e-01j] [-0.41223854+9.10345474e-01j 0.9635239 +4.72047677e-19j]] .. py:method:: to_string() Convert the density matrix to a string representation. .. py:method:: to_json() Information as json style. :returns: information as json style :rtype: str .. rubric:: Examples >>> state = DensityMatrix(2) >>> print(state.to_json()) {"is_hermitian":true,"matrix":[[{"imag":0.0,"real":1.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0}],[{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0}],[{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0}],[{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0},{"imag":0.0,"real":0.0}]],"n_qubits":2} .. py:method:: load_json(json_str) Read an object from the JSON representation of the density matrix. .. py:attribute:: UNMEASURED :type: int :value: Ellipsis Constant used for `DensityMatrix::get_marginal_probability` to express the the qubit is not measured. .. py:class:: SparseMatrixGate(arg) Specific class of sparse matrix gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: DenseMatrixGate(arg) Specific class of dense matrix gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:function:: merge_gate(arg0, arg1, /) Merge two gates. return value is (merged gate, global phase). .. py:class:: Operator(n_terms) General quantum operator class. Given `qubit_count: int`, Initialize operator with specified number of qubits. .. rubric:: Examples >>> terms = [PauliOperator("X 0 Y 2"), PauliOperator("Z 1 X 3", 2j)] >>> op = Operator(terms) >>> pauli = PauliOperator("X 1", -1j) >>> op *= pauli >>> print(op.to_json()) {"terms":[{"coef":{"imag":-1.0,"real":0.0},"pauli_string":"X 0 X 1 Y 2"},{"coef":{"imag":2.0,"real":0.0},"pauli_string":"Y 1 X 3"}]} .. py:class:: GroundState Structure to hold the ground state information. .. py:property:: eigenvalue :type: complex .. py:property:: state :type: StateVector .. py:method:: is_hermitian() Check if the operator is Hermitian. .. py:method:: load(terms) Load the operator with a list of Pauli operators. .. py:method:: uninitialized_operator(n_terms) :staticmethod: Create an uninitialized operator with a specified number of terms. .. py:method:: n_terms() Get the number of terms in the operator. .. py:method:: get_terms() Get the list of Pauli terms that make up the operator. .. py:method:: to_string() Get string representation of the operator. .. py:method:: to_string() .. py:method:: optimize() Optimize the operator by combining like terms. .. py:method:: get_dagger() Get the adjoint (Hermitian conjugate) of the operator. .. py:method:: apply_to_state(state) Apply the operator to a state vector. .. py:method:: get_expectation_value(state) Get the expectation value of the operator with respect to a state vector. .. py:method:: get_expectation_value(states) Get the expectation values of the operator for a batch of state vectors. .. py:method:: get_expectation_values(state) Get the expectation values of the pauli operators with respect to a state vector. .. py:method:: get_transition_amplitude(source, target) Get the transition amplitude of the operator between two state vectors. .. py:method:: get_transition_amplitude(states_source, states_target) Get the transition amplitudes of the operator for a batch of state vectors. .. py:method:: get_matrix(arg, /) Get matrix representation of the Operator. Tensor product is applied from n_qubits-1 to 0. .. py:method:: solve_ground_state_by_power_method(initial_state, iter_count, mu = None) Solve for the ground state using the power method. :param initial_state: Initial state vector for the iteration. Passing Haar_random_state is often nice. :type initial_state: :class:`StateVector` :param iter_count: Number of iterations to perform. :type iter_count: int :param mu: Shift value to accelerate convergence. The value must be larger than largest eigenvalue. If not provided, a default value is calculated internally. :type mu: complex, optional :returns: The ground state information including eigenvalue and ground state vector. :rtype: :class:`Operator.GroundState` .. rubric:: Examples >>> terms = [PauliOperator("", -3.8505), PauliOperator("X 1", -0.2288), PauliOperator("Z 1", -1.0466), PauliOperator("X 0", -0.2288), PauliOperator("X 0 X 1", 0.2613), PauliOperator("X 0 Z 1", 0.2288), PauliOperator("Z 0", -1.0466), PauliOperator("Z 0 X 1", 0.2288), PauliOperator("Z 0 Z 1", 0.2356)] >>> op = Operator(terms) >>> op *= .5 >>> ground_state = op.solve_ground_state_by_power_method(StateVector.Haar_random_state(2, seed=0), 200) >>> ground_state.eigenvalue.real # doctest: +ELLIPSIS -2.862620764... >>> print(ground_state.state.get_amplitudes()) # doctest: +SKIP [(0.593378420...-0.801949191...j), (-0.00937288681...+0.0126674290...j), (-0.00937288706...+0.0126674292...j), (-0.0389261878...+0.0526086285...j)] .. py:method:: solve_ground_state_by_arnoldi_method(initial_state, iter_count, mu = None) Solve for the ground state using the Arnoldi method. :param initial_state: Initial state vector for the iteration. Passing Haar_random_state is often nice. :type initial_state: :class:`StateVector` :param iter_count: Number of iterations to perform. Too large value causes error on calculating eigenvalue of Hessenberg matrix. :type iter_count: int :param mu: Shift value to accelerate convergence. The value must be larger than largest eigenvalue. If not provided, a default value is calculated internally. :type mu: complex, optional :returns: The ground state information including eigenvalue and ground state vector. :rtype: :class:`Operator.GroundState` .. rubric:: Examples >>> terms = [PauliOperator("", -3.8505), PauliOperator("X 1", -0.2288), PauliOperator("Z 1", -1.0466), PauliOperator("X 0", -0.2288), PauliOperator("X 0 X 1", 0.2613), PauliOperator("X 0 Z 1", 0.2288), PauliOperator("Z 0", -1.0466), PauliOperator("Z 0 X 1", 0.2288), PauliOperator("Z 0 Z 1", 0.2356)] >>> op = Operator(terms) >>> op *= .5 >>> ground_state = op.solve_ground_state_by_arnoldi_method(StateVector.Haar_random_state(2, seed=0), 40) >>> ground_state.eigenvalue.real # doctest: +ELLIPSIS -2.862620764... >>> ground_state.state.get_amplitudes() # doctest: +SKIP [(0.593378420...-0.801949191...j), (-0.00937288693...+0.0126674291...j), (-0.00937288693...+0.0126674291...j), (-0.0389261878...+0.0526086285...j)] .. rubric:: Notes This works even if it is not Hermitian. An eigenvalue with the smallest real part is returned as the ground state. .. py:method:: calculate_default_mu() Calculate a default shift value `mu` for ground state solvers. :returns: Calculated shift value `mu`. :rtype: complex .. py:method:: copy_to_default_space() Return a deep copy in the default execution space. .. py:method:: copy_to_host_space() Return a deep copy in the host execution space. .. py:method:: to_json() Information as json style. .. py:method:: load_json(json_str) Read an object from the JSON representation of the operator. .. py:class:: OperatorBatched General quantum operator class for batched operators. .. py:method:: copy() Return a copy. .. py:method:: load(terms) Load a vector of Pauli operators. :param terms: :type terms: A vector of Pauli operators. .. py:method:: load(terms) Load a vector of Operators. :param terms: :type terms: A vector of Operators. .. py:method:: to_string() Return a string representation of the operator. .. py:method:: to_string() Get string representation of the OperatorBatched. .. py:method:: batch_size() Return the batch size of the operator. .. py:method:: get_dagger() Return the Hermitian conjugate of the operator. .. py:method:: get_applied_states(state_vector, batch_size = 1) Apply the batched operator to a state vector. :param state_vector: :type state_vector: A state vector to be applied. :param batch_size: :type batch_size: In the update process, the batch size to be processed simultaneously. .. py:method:: get_expectation_value(state_vector) Return a vector of expectation values for each operator. :param state_vector: :type state_vector: A state vector to compute expectation values. .. py:method:: get_transition_amplitude(state_vector_bra, state_vector_ket) Return a vector of transition amplitudes for each operator. :param state_vector_bra: :type state_vector_bra: A bra state vector. :param state_vector_ket: :type state_vector_ket: A ket state vector. .. py:method:: get_operator_at(index) Return the operator at the specified index. :param index: :type index: Index of the operator. .. py:method:: view_operator_at(index) Return a view of the operator at the specified index. :param index: :type index: Index of the operator. .. py:method:: get_operators() Return a vector of all operators. .. py:method:: copy_to_default_space() Return a deep copy in the default execution space. .. py:method:: copy_to_host_space() Return a deep copy in the host execution space. .. py:method:: to_json() Information as json style. .. py:method:: load_json(json_str) Read an object from the JSON representation of the OperatorBatched. .. py:class:: IGate(arg) Specific class of I gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: GlobalPhaseGate(arg) Specific class of gate, which rotate global phase, represented as $e^{i\gamma}I$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: XGate(arg) Specific class of Pauli-X gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: YGate(arg) Specific class of Pauli-Y gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: ZGate(arg) Specific class of Pauli-Z gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: HGate(arg) Specific class of Hadamard gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: SGate(arg) Specific class of S gate, represented as $\begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: SdagGate(arg) Specific class of inverse of S gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: TGate(arg) Specific class of T gate, represented as $\begin{bmatrix} 1 & 0 \\ 0 &e^{i \pi/4} \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: TdagGate(arg) Specific class of inverse of T gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: SqrtXGate(arg) Specific class of sqrt(X) gate, represented as $\frac{1}{\sqrt{2}} \begin{bmatrix} 1+i & 1-i\\ 1-i & 1+i \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: SqrtXdagGate(arg) Specific class of inverse of sqrt(X) gate, represented as $\frac{1}{\sqrt{2}} \begin{bmatrix} 1-i & 1+i\\ 1+i & 1-i \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: SqrtYGate(arg) Specific class of sqrt(Y) gate, represented as $\frac{1}{\sqrt{2}} \begin{bmatrix} 1+i & -1-i \\ 1+i & 1+i \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: SqrtYdagGate(arg) Specific class of inverse of sqrt(Y) gate, represented as $\frac{1}{\sqrt{2}} \begin{bmatrix} 1-i & 1-i\\ -1+i & 1-i \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: P0Gate(arg) Specific class of projection gate to $\ket{0}$. .. rubric:: Notes This gate is not unitary. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: P1Gate(arg) Specific class of projection gate to $\ket{1}$. .. rubric:: Notes This gate is not unitary. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: RXGate(arg) Specific class of X rotation gate, represented as $e^{-i\frac{\theta}{2}X}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: angle() Get `angle` property. .. py:class:: RYGate(arg) Specific class of Y rotation gate, represented as $e^{-i\frac{\theta}{2}Y}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: angle() Get `angle` property. .. py:class:: RZGate(arg) Specific class of Z rotation gate, represented as $e^{-i\frac{\theta}{2}Z}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: angle() Get `angle` property. .. py:class:: U1Gate(arg) Specific class of IBMQ's U1 Gate, which is a rotation about Z-axis, represented as $\begin{bmatrix} 1 & 0 \\ 0 & e^{i\lambda} \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: U2Gate(arg) Specific class of IBMQ's U2 Gate, which is a rotation about X+Z-axis, represented as $\frac{1}{\sqrt{2}} \begin{bmatrix}1 & -e^{-i\lambda}\\ e^{i\phi} & e^{i(\phi+\lambda)} \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: phi() Get `phi` property. .. py:class:: U3Gate(arg) Specific class of IBMQ's U3 Gate, which is a rotation about 3 axis, represented as $\begin{bmatrix} \cos \frac{\theta}{2} & -e^{i\lambda}\sin\frac{\theta}{2}\\ e^{i\phi}\sin\frac{\theta}{2} & e^{i(\phi+\lambda)}\cos\frac{\theta}{2} \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: theta() Get `theta` property. .. py:method:: phi() Get `phi` property. .. py:class:: SwapGate(arg) Specific class of two-qubit swap gate. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: EcrGate(arg) Specific class of two-qubit ecr gate.represented as $\frac{1}{\sqrt{2}}\begin{bmatrix} 0 & 1 & 0 & i \\ 1 & 0 & -i & 0 \\ 0 & i & 0 & 1 \\ -i & 0 & 1 & 0 \end{bmatrix}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: physical_control() Get `physical_control_indices` property. .. py:method:: physical_target() Get `physical_target_indices` property. .. py:class:: MeasurementGate(arg) Specific class of computational-basis measurement gate. .. rubric:: Notes This gate is not unitary and requires a classical register when applied. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: classical_bit_index() Get `classical_bit_index` property. .. py:method:: reset() Return whether this measurement resets the target qubit to |0>. .. py:class:: PauliGate(arg) Specific class of multi-qubit pauli gate, which applies single-qubit Pauli gate to each of qubit. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: PauliRotationGate(arg) Specific class of multi-qubit pauli-rotation gate, represented as $e^{-i\frac{\theta}{2}P}$. Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: gate_type() Get gate type as `GateType` enum. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits are not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: control_value_list() Get control values as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits are not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: control_value_mask() Get control values as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse gate as `Gate` type. If not exists, return None. .. py:method:: get_matrix() Get matrix representation of the gate. Note: The matrix is constructed by reordering target qubits in ascending order of their indices. The qubit with the smaller index is treated as the first target, and the larger as the second. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:method:: update_quantum_state(state_vector) Apply gate to `state_vector`. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state_vector, classical_register, seed = None) Apply gate to `state_vector` with `classical_register` and `seed`. .. py:method:: update_quantum_state(states) Apply gate to `states`. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, seed = None) Apply gate to `states` with `classical_register` and `seed`. .. py:class:: ParamRXGate(arg) Specific class of parametric X rotation gate, represented as $e^{-i\frac{\mathrm{\theta}}{2}X}$. `theta` is given as `param * param_coef`. .. rubric:: Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: param_gate_type() Get parametric gate type as `ParamGateType` enum. .. py:method:: param_coef() Get coefficient of parameter. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits is not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits is not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse parametric-gate as `ParamGate` type. If not exists, return None. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) Apply gate to `states` with holding the parameters. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: get_matrix(param) Get matrix representation of the gate with holding the parameter. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:class:: ParamRYGate(arg) Specific class of parametric Y rotation gate, represented as $e^{-i\frac{\mathrm{\theta}}{2}Y}$. `theta` is given as `param * param_coef`. .. rubric:: Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: param_gate_type() Get parametric gate type as `ParamGateType` enum. .. py:method:: param_coef() Get coefficient of parameter. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits is not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits is not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse parametric-gate as `ParamGate` type. If not exists, return None. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) Apply gate to `states` with holding the parameters. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: get_matrix(param) Get matrix representation of the gate with holding the parameter. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:class:: ParamRZGate(arg) Specific class of parametric Z rotation gate, represented as $e^{-i\frac{\mathrm{\theta}}{2}Z}$. `theta` is given as `param * param_coef`. .. rubric:: Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: param_gate_type() Get parametric gate type as `ParamGateType` enum. .. py:method:: param_coef() Get coefficient of parameter. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits is not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits is not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse parametric-gate as `ParamGate` type. If not exists, return None. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) Apply gate to `states` with holding the parameters. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: get_matrix(param) Get matrix representation of the gate with holding the parameter. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:class:: ParamPauliRotationGate(arg) Parametric multi-qubit pauli-rotation gate, represented as $e^{-i\frac{\theta}{2}P}$. `theta` is given as `param * param_coef`. .. rubric:: Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: param_gate_type() Get parametric gate type as `ParamGateType` enum. .. py:method:: param_coef() Get coefficient of parameter. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits is not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits is not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse parametric-gate as `ParamGate` type. If not exists, return None. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) Apply gate to `states` with holding the parameters. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: get_matrix(param) Get matrix representation of the gate with holding the parameter. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:class:: ParamProbabilisticGate(arg) Specific class of parametric probabilistic gate. The gate to apply is picked from a certain distribution. .. rubric:: Notes Upcast is required to use gate-general functions (ex: add to Circuit). .. py:method:: param_gate_type() Get parametric gate type as `ParamGateType` enum. .. py:method:: param_coef() Get coefficient of parameter. .. py:method:: target_qubit_list() Get target qubits as `list[int]`. **Control qubits is not included.** .. py:method:: control_qubit_list() Get control qubits as `list[int]`. .. py:method:: operand_qubit_list() Get target and control qubits as `list[int]`. .. py:method:: target_qubit_mask() Get target qubits as mask. **Control qubits is not included.** .. py:method:: control_qubit_mask() Get control qubits as mask. .. py:method:: operand_qubit_mask() Get target and control qubits as mask. .. py:method:: get_inverse() Generate inverse parametric-gate as `ParamGate` type. If not exists, return None. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: update_quantum_state(state, param) Apply gate to `state_vector` with holding the parameter. `state_vector` in args is directly updated. .. py:method:: update_quantum_state(state, classical_register, param, seed = None) Apply gate to `state_vector` with `classical_register`, parameter, and `seed`. .. py:method:: update_quantum_state(states, params) Apply gate to `states` with holding the parameters. `states` in args is directly updated. .. py:method:: update_quantum_state(states, classical_register, params, seed = None) Apply gate to `states` with `classical_register`, parameters, and `seed`. .. py:method:: get_matrix(param) Get matrix representation of the gate with holding the parameter. .. py:method:: to_string() Get string representation of the gate. .. py:method:: to_json() Get JSON representation of the gate. .. py:method:: load_json(json_str) Read an object from the JSON representation of the gate. .. py:method:: gate_list() .. py:method:: distribution() .. py:class:: Circuit Quantum circuit representation. .. rubric:: Examples >>> circuit = Circuit() >>> print(circuit.to_json()) {"gate_list":[]} .. py:method:: gate_list() Get property of `gate_list`. :returns: List of gates. :rtype: list .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_gate(gate.X(0)) >>> len(circuit.gate_list()) 1 .. py:method:: n_gates() Get property of `n_gates`. :returns: Property of `n_gates`. :rtype: int .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_gate(gate.X(0)) >>> circuit.add_gate(gate.CX(0, 1)) >>> print(circuit.n_gates()) 2 .. py:method:: key_set() Get set of keys of parameters. :returns: Set of keys. :rtype: set[str] .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_param_gate(gate.ParamRX(0, 0.0), "theta") >>> circuit.add_param_gate(gate.ParamRY(1, 2.0), "phi") >>> print(sorted(circuit.key_set())) ['phi', 'theta'] .. py:method:: get_gate_at(index) Get reference of i-th gate. :param index: Index of gate :type index: int :returns: Gate at i-th index :rtype: Gate .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_gate(gate.X(0)) >>> print(circuit.get_gate_at(0)) Gate Type: X Target Qubits: {0} Control Qubits: {} Control Value: {} .. py:method:: get_param_key_at(index) Get parameter key of i-th gate. If it is not parametric, return None. :param index: Index of gate :type index: int :returns: Parameter key :rtype: str | None .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_param_gate(gate.ParamRX(0, 0.0), "theta") >>> circuit.add_gate(gate.X(1)) >>> circuit.get_param_key_at(0) 'theta' >>> circuit.get_param_key_at(1) is None True .. py:method:: calculate_depth() Get depth of circuit. :returns: Depth of circuit :rtype: int .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_gate(gate.X(0)) >>> circuit.add_gate(gate.Y(1)) >>> circuit.add_gate(gate.CX(0, 1)) >>> print(circuit.calculate_depth()) 2 .. py:method:: add_gate(gate) Add gate to circuit. :param gate: Gate to add :type gate: Gate .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_gate(gate.X(0)) .. py:method:: add_conditional_gate(gate, condition) Add gate with a user-defined classical condition. .. py:method:: add_conditional_gate(gate, classical_bit_index, expected_value) Add gate with a condition on a classical bit. .. py:method:: add_param_gate(param_gate, param_key) Add parametric gate with specifying key. Given param_gate is copied. :param param_gate: Parametric gate to add :type param_gate: ParamGate :param param_key: Parameter key :type param_key: str .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_param_gate(gate.ParamRX(0, 0.0), "theta") .. py:method:: add_conditional_param_gate(param_gate, param_key, condition) Add parametric gate with a user-defined classical condition. .. py:method:: add_conditional_param_gate(param_gate, param_key, classical_bit_index, expected_value) Add parametric gate with a condition on a classical bit. .. py:method:: add_circuit(other) Add all gates in specified circuit. Given gates are copied. :param other: Circuit to add :type other: Circuit .. rubric:: Examples >>> circuit = Circuit() >>> circuit.add_gate(gate.X(0)) >>> circuit2 = Circuit() >>> circuit2.add_gate(gate.Y(1)) >>> circuit.add_circuit(circuit2) >>> circuit.n_gates() 2 .. py:method:: copy() Copy circuit. Returns a new circuit instance with all gates copied by reference. .. py:method:: get_inverse() Get inverse of circuit. All the gates are newly created. .. py:method:: to_json() Information as json style. .. py:method:: load_json(json_str) Read an object from the JSON representation of the circuit. .. py:method:: update_quantum_state(state, **kwargs) Apply gate to the StateVector. StateVector in args is directly updated. If the circuit contains parametric gate, you have to give real value of parameter as "name=value" format in kwargs. .. py:method:: update_quantum_state(state, params = {}, seed = None) Apply gate to the StateVector. StateVector in args is directly updated. If the circuit contains parametric gate, you have to give real value of parameter as dict[str, float] in 2nd arg. .. py:method:: update_quantum_state(state, classical_register, params = {}, seed = None) Apply gate to the StateVector with classical register and optional seed. .. py:method:: update_quantum_state(state, classical_register, **kwargs) Apply gate to the StateVector with classical register. If the circuit contains parametric gate, give parameter values as "name=value" in kwargs. .. py:method:: update_quantum_state(state, **kwargs) Apply gate to the StateVectorBatched. StateVectorBatched in args is directly updated. If the circuit contains parametric gate, you have to give real value of parameter as "name=[value1, value2, ...]" format in kwargs. .. py:method:: update_quantum_state(state, params = {}, seed = None) Apply gate to the StateVectorBatched. StateVectorBatched in args is directly updated. If the circuit contains parametric gate, you have to give real value of parameter as dict[str, list[float]] in 2nd arg. .. py:method:: update_quantum_state(state, classical_register, params = {}, seed = None) Apply gate to the StateVectorBatched with classical register and optional seed. .. py:method:: update_quantum_state(state, classical_register, **kwargs) Apply gate to the StateVectorBatched with classical register. If the circuit contains parametric gate, give parameter values as "name=[value1, value2, ...]" in kwargs. .. py:method:: update_quantum_state(state, **kwargs) Apply gate to the StateVector. StateVector in args is directly updated. If the circuit contains parametric gate, you have to give real value of parameter as "name=value" format in kwargs. .. py:method:: update_quantum_state(state, params = {}, seed = None) Apply gate to the StateVector. StateVector in args is directly updated. If the circuit contains parametric gate, you have to give real value of parameter as dict[str, float] in 2nd arg. .. py:method:: update_quantum_state(state, classical_register, params = {}, seed = None) Apply gate to the StateVector with classical register and optional seed. .. py:method:: update_quantum_state(state, classical_register, **kwargs) Apply gate to the StateVector with classical register. If the circuit contains parametric gate, give parameter values as "name=value" in kwargs. .. py:method:: update_quantum_state(state, **kwargs) Apply gate to the StateVectorBatched. StateVectorBatched in args is directly updated. If the circuit contains parametric gate, you have to give real value of parameter as "name=[value1, value2, ...]" format in kwargs. .. py:method:: update_quantum_state(state, params = {}, seed = None) Apply gate to the StateVectorBatched. StateVectorBatched in args is directly updated. If the circuit contains parametric gate, you have to give real value of parameter as dict[str, list[float]] in 2nd arg. .. py:method:: update_quantum_state(state, classical_register, params = {}, seed = None) Apply gate to the StateVectorBatched with classical register and optional seed. .. py:method:: update_quantum_state(state, classical_register, **kwargs) Apply gate to the StateVectorBatched with classical register. If the circuit contains parametric gate, give parameter values as "name=[value1, value2, ...]" in kwargs. .. py:method:: optimize(max_block_size = 3) Optimize circuit. Create qubit dependency tree and merge neighboring gates if the new gate has less than or equal to `max_block_size` or the new gate is Pauli. .. py:method:: optimize(max_block_size = 3) .. py:method:: simulate_noise(initial_state, sampling_count, parameters = {}, seed = None) Simulate noise circuit. Return all the possible states and their counts. .. py:method:: simulate_noise(initial_state, sampling_count, parameters = {}, seed = None) .. py:method:: compute_expectation_gradient_backprop(state, bistate, parameters) Low-level implementation for expectation gradient that assumes the forward state and observable-applied bistate are already prepared, and computes gradient using back propagation. .. py:method:: compute_expectation_gradient_backprop(state, bistate, parameters) .. py:method:: compute_expectation_gradient(observable, parameters) Compute gradient of expectation value of observable using back propagation. .. py:method:: compute_expectation_gradient(observable, parameters) .. py:method:: add_observable_rotation_gate(observable, angle, num_repeats) Add observable rotation gate. :param observable: observable :type observable: Operator :param angle: angle :type angle: float :param num_repeats: repeats num :type num_repeats: int .. rubric:: Examples >>> circuit = Circuit() >>> terms = [] >>> terms.append(PauliOperator("Z 0 Z 1")) >>> observable = Operator(terms) >>> circuit.add_observable_rotation_gate(observable, 0.1, 100) .. py:method:: add_observable_rotation_gate(observable, angle, num_repeats) .. py:class:: PauliOperator(coef = 1.0) Pauli operator as coef and tensor product of single pauli for each qubit. Given `coef: complex`, Initialize operator which just multiplying coef. Given `target_qubit_list: list[int], pauli_id_list: list[int], coef: complex`, Initialize pauli operator. For each `i`, single pauli correspond to `pauli_id_list[i]` is applied to `target_qubit_list[i]`-th qubit. Given `pauli_string: str, coef: complex`, Initialize pauli operator. For each `i`, single pauli correspond to `pauli_id_list[i]` is applied to `target_qubit_list[i]`-th qubit. Given `pauli_id_par_qubit: list[int], coef: complex`, Initialize pauli operator. For each `i`, single pauli correspond to `paul_id_per_qubit[i]` is applied to `i`-th qubit. Given `bit_flip_mask: int, phase_flip_mask: int, coef: complex`, Initialize pauli operator. For each `i`, single pauli applied to `i`-th qubit is got from `i-th` bit of `bit_flip_mask` and `phase_flip_mask` as follows. .. csv-table:: "bit_flip","phase_flip","pauli" "0","0","I" "0","1","Z" "1","0","X" "1","1","Y" .. rubric:: Examples >>> pauli = PauliOperator("X 3 Y 2") >>> print(pauli.to_json()) {"coef":{"imag":0.0,"real":1.0},"pauli_string":"Y 2 X 3"} .. py:method:: coef() Get property `coef`. .. py:method:: target_qubit_list() Get qubits to be applied pauli. .. py:method:: pauli_id_list() Get pauli id to be applied. The order is correspond to the result of `target_qubit_list` .. py:method:: get_XZ_mask_representation() Get single-pauli property as binary integer representation. See description of `__init__(bit_flip_mask_py: int, phase_flip_mask_py: int, coef: float=1.)` for details. .. py:method:: get_pauli_string() Get single-pauli property as string representation. See description of `__init__(pauli_string: str, coef: float=1.)` for details. .. py:method:: get_dagger() Get adjoint operator. .. py:method:: apply_to_state(state) Apply pauli to state vector. .. py:method:: get_expectation_value(state) Get expectation value of measuring state vector. $\bra{\psi}P\ket{\psi}$. .. py:method:: get_transition_amplitude(source, target) Get transition amplitude of measuring state vector. $\bra{\chi}P\ket{\psi}$. .. py:method:: get_matrix() Get matrix representation of the PauliOperator. Tensor product is applied from $(n-1)$ -th qubit to $0$ -th qubit. Only the X, Y, and Z components are taken into account in the result. .. py:method:: get_full_matrix(n_qubits) Get matrix representation of the PauliOperator. Tensor product is applied from $(n-1)$ -th qubit to $0$ -th qubit. .. py:method:: get_matrix_ignoring_coef() Get matrix representation of the PauliOperator, but with forcing `coef=1.`Only the X, Y, and Z components are taken into account in the result. .. py:method:: get_full_matrix_ignoring_coef(n_qubits) Get matrix representation of the PauliOperator, but with forcing `coef=1.` .. py:method:: to_json() Information as json style. .. py:method:: load_json(json_str) Read an object from the JSON representation of the Pauli operator. .. py:method:: to_string() Get string representation of the Pauli operator.