:py:mod:`pyqrack.qrack_circuit` =============================== .. py:module:: pyqrack.qrack_circuit Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: pyqrack.qrack_circuit.QrackCircuit Attributes ~~~~~~~~~~ .. autoapisummary:: pyqrack.qrack_circuit._IS_QISKIT_AVAILABLE pyqrack.qrack_circuit._IS_QISKIT_AVAILABLE pyqrack.qrack_circuit._IS_QUIMB_AVAILABLE pyqrack.qrack_circuit._IS_QUIMB_AVAILABLE pyqrack.qrack_circuit._IS_TENSORCIRCUIT_AVAILABLE pyqrack.qrack_circuit._IS_TENSORCIRCUIT_AVAILABLE .. py:data:: _IS_QISKIT_AVAILABLE :value: True .. py:data:: _IS_QISKIT_AVAILABLE :value: False .. py:data:: _IS_QUIMB_AVAILABLE :value: True .. py:data:: _IS_QUIMB_AVAILABLE :value: False .. py:data:: _IS_TENSORCIRCUIT_AVAILABLE :value: True .. py:data:: _IS_TENSORCIRCUIT_AVAILABLE :value: False .. py:class:: QrackCircuit(is_collapse=True, clone_cid=-1, is_inverse=False, past_light_cone=[]) Class that exposes the QCircuit class of Qrack QrackCircuit allows the user to specify a unitary circuit, before running it. Upon running the state, the result is a QrackSimulator state. Currently, measurement is not supported, but measurement can be run on the resultant QrackSimulator. .. attribute:: cid Qrack ID of this circuit :type: int .. py:method:: __del__() .. py:method:: _ulonglong_byref(a) .. py:method:: _double_byref(a) .. py:method:: _complex_byref(a) .. py:method:: clone() Make a new circuit that is an exact clone of this circuit :raises RuntimeError: QrackCircuit C++ library raised an exception. .. py:method:: inverse() Make a new circuit that is the exact inverse of this circuit :raises RuntimeError: QrackCircuit C++ library raised an exception. .. py:method:: past_light_cone(q) Make a new circuit with just this circuits' past light cone for certain qubits. :param q: list of qubit indices to include at beginning of past light cone :raises RuntimeError: QrackCircuit C++ library raised an exception. .. py:method:: get_qubit_count() Get count of qubits in circuit :raises RuntimeError: QrackCircuit C++ library raised an exception. .. py:method:: swap(q1, q2) Add a 'Swap' gate to the circuit :param q1: qubit index #1 :param q2: qubit index #2 :raises RuntimeError: QrackCircuit C++ library raised an exception. .. py:method:: mtrx(m, q) Operation from matrix. Applies arbitrary operation defined by the given matrix. :param m: row-major complex list representing the operator. :param q: the qubit number on which the gate is applied to. :raises ValueError: 2x2 matrix 'm' in QrackCircuit.mtrx() must contain at least 4 elements. :raises RuntimeError: QrackSimulator raised an exception. .. py:method:: ucmtrx(c, m, q, p) Multi-controlled single-target-qubit gate Specify a controlled gate by its control qubits, its single-qubit matrix "payload," the target qubit, and the permutation of qubits that activates the gate. :param c: list of controlled qubits :param m: row-major complex list representing the operator. :param q: target qubit :param p: permutation of target qubits :raises ValueError: 2x2 matrix 'm' in QrackCircuit.ucmtrx() must contain at least 4 elements. :raises RuntimeError: QrackSimulator raised an exception. .. py:method:: run(qsim) Run circuit on simulator Run the encoded circuit on a specific simulator. The result will remain in this simulator. :param qsim: QrackSimulator on which to run circuit :raises RuntimeError: QrackCircuit raised an exception. .. py:method:: out_to_file(filename) Output optimized circuit to file Outputs the (optimized) circuit to a file named according to the "filename" parameter. :param filename: Name of file .. py:method:: in_from_file() Read in optimized circuit from file Reads in an (optimized) circuit from a file named according to the "filename" parameter. :param filename: Name of file .. py:method:: file_to_qiskit_circuit() Convert an output file to a Qiskit circuit Reads in an (optimized) circuit from a file named according to the "filename" parameter and outputs a Qiskit circuit. :param filename: Name of file :raises RuntimeErorr: Before trying to file_to_qiskit_circuit() with QrackCircuit, you must install Qiskit, numpy, and math! .. py:method:: in_from_qiskit_circuit() Read a Qiskit circuit into a QrackCircuit Reads in a circuit from a Qiskit `QuantumCircuit` :param circ: Qiskit circuit :raises RuntimeErorr: Before trying to file_to_qiskit_circuit() with QrackCircuit, you must install Qiskit, numpy, and math! .. py:method:: file_to_quimb_circuit(circuit_type=QuimbCircuitType.Circuit, psi0=None, gate_opts=None, tags=None, psi0_dtype='complex128', psi0_tag='PSI0', bra_site_ind_id='b{}') Convert an output file to a Quimb circuit Reads in an (optimized) circuit from a file named according to the "filename" parameter and outputs a Quimb circuit. :param filename: Name of file :param circuit_type: "QuimbCircuitType" enum value specifying type of Quimb circuit :param psi0: The initial state, assumed to be |00000....0> if not given. The state is always copied and the tag PSI0 added :param gate_opts: Default keyword arguments to supply to each gate_TN_1D() call during the circuit :param tags: Tag(s) to add to the initial wavefunction tensors (whether these are propagated to the rest of the circuit’s tensors :param psi0_dtype: Ensure the initial state has this dtype. :param psi0_tag: Ensure the initial state has this tag. :param bra_site_ind_id: Use this to label ‘bra’ site indices when creating certain (mostly internal) intermediate tensor networks. :raises RuntimeErorr: Before trying to file_to_quimb_circuit() with QrackCircuit, you must install quimb, Qiskit, numpy, and math! .. py:method:: file_to_tensorcircuit(inputs=None, circuit_params=None, binding_params=None) Convert an output file to a TensorCircuit circuit Reads in an (optimized) circuit from a file named according to the "filename" parameter and outputs a TensorCircuit circuit. :param filename: Name of file :param inputs: pass-through to tensorcircuit.Circuit.from_qiskit :param circuit_params: pass-through to tensorcircuit.Circuit.from_qiskit :param binding_params: pass-through to tensorcircuit.Circuit.from_qiskit :raises RuntimeErorr: Before trying to file_to_quimb_circuit() with QrackCircuit, you must install TensorCircuit, Qiskit, numpy, and math! .. py:method:: in_from_tensorcircuit(enable_instruction=False, enable_inputs=False) Convert a TensorCircuit circuit to a QrackCircuit Accepts a TensorCircuit circuit and outputs an equivalent QrackCircuit :param tcirc: TensorCircuit circuit :param enable_instruction: whether to also export measurement and reset instructions :param enable_inputs: whether to also export the inputs :raises RuntimeErorr: Before trying to in_from_tensorcircuit() with QrackCircuit, you must install TensorCircuit, Qiskit, numpy, and math!