コード例 #1
0
 def __peek_measure_all_basis(self, cbits, basis, collapse):
     cbasis = bytes(basis, 'utf-8')
     ccollapse = 1 if collapse else 0
     res = q1tsimffi.unpack_result(
         self.__sim.circuit_measure_all(self.__ptr, cbits, len(cbits),
                                        cbasis, ccollapse))
     return res
コード例 #2
0
    def add_gate(self, name, qbits, params=None):
        """Add a gate.

        Append a n-ary quantum gate gate, operating on the n qubits in bits, to
        this circuit.
        """
        cname = bytes(name, 'utf-8')
        if params is None:
            res = q1tsimffi.unpack_result(
                self.__sim.circuit_add_gate(self.__ptr, cname, qbits,
                                            len(qbits), cffi.FFI.NULL, 0))
        else:
            cparams = q1tsimffi.make_parameters(params)
            res = q1tsimffi.unpack_result(
                self.__sim.circuit_add_gate(self.__ptr, cname, qbits,
                                            len(qbits), cparams, len(params)))
        return res
コード例 #3
0
    def c_qasm(self):
        """Export to c-Qasm.

        Export this circuit to a program in c-Qasm format. On a successful
        conversion, returns a string with the program text.
        """
        res = q1tsimffi.unpack_result(self.__sim.circuit_c_qasm(self.__ptr))
        return res
コード例 #4
0
    def latex(self):
        """Export to OpenQasm

        Export this circuit to LaTeX using the qcircuit pacakge. On a successful
        conversion, returns a string with the LaTeX code.
        """
        res = q1tsimffi.unpack_result(self.__sim.circuit_latex(self.__ptr))
        return res
コード例 #5
0
    def reexecute(self):
        """Execute a circuit again.

        Run this circuit again, starting with the state from the previous
        execution.
        """
        res = q1tsimffi.unpack_result(self.__sim.circuit_reexecute(self.__ptr))
        return res
コード例 #6
0
    def reset_all(self):
        """Reset all qubits.

        Reset the entire quantum state of the circuit to |00...0⟩. The classical
        register is not affected.
        """
        res = q1tsimffi.unpack_result(self.__sim.circuit_reset_all(self.__ptr))
        return res
コード例 #7
0
    def execute(self, nr_shots):
        """Execute this circuit

        Execute this circuit, performing its operations and measurements.
        Measurements are made over nr_shots executions of the circuit. This
        function clears any previous states of the system (quantum or classical).
        """
        res = q1tsimffi.unpack_result(
            self.__sim.circuit_execute(self.__ptr, nr_shots))
        return res
コード例 #8
0
    def reset(self, qbit):
        """Reset a qubit

        Reset the qubit qbit to |0⟩. This is done by measuring the bit, and
        flipping it if the result is 1, so this is potentially an expensive
        operation.
        """
        res = q1tsimffi.unpack_result(
            self.__sim.circuit_reset(self.__ptr, qbit))
        return res
コード例 #9
0
    def histogram(self):
        """Create a histogram of measurements.

        Create a histogram of the measured classical bits and return it as a
        dictionary mapping measurement result to the number of times the result
        was measured. The n bits in the classical register are collected in a
        string key, with the last character in the key corresponding to the
        first bit (at index 0) in the classical register and vice versa.
        """
        res = q1tsimffi.unpack_result(self.__sim.circuit_histogram(self.__ptr))
        return res
コード例 #10
0
    def add_conditional_gate(self, control, target, name, qbits, params=None):
        """Add a conditional gate.

        Append a n-ary gate gate, that will operate on the n qubits in
        bits to this circuit. The gate will only be applied only when the
        classical bits with indices from control form the target word target.
        The bit at the position of the first index in control is interpreted
        as the least significant bit to check.
        """
        cname = bytes(name, 'utf-8')
        if params is None:
            res = q1tsimffi.unpack_result(
                self.__sim.circuit_add_conditional_gate(
                    self.__ptr, control, len(control), target, cname, qbits,
                    len(qbits), cffi.FFI.NULL, 0))
        else:
            res = q1tsimffi.unpack_result(
                self.__sim.circuit_add_conditional_gate(
                    self.__ptr, control, len(control), target, cname, qbits,
                    len(qbits), params, len(params)))
        return res
コード例 #11
0
 def cstate(self):
     """Return the classical state (i.e. measurement results) of this circuit"""
     res = q1tsimffi.unpack_result(self.__sim.circuit_cstate(self.__ptr))
     return res