예제 #1
0
    def __init__(self, abstract_circuit: QCircuit, variables, noise_model=None,
                 use_mapping=True, optimize_circuit=True, *args, **kwargs):
        self._variables = tuple(abstract_circuit.extract_variables())
        self.use_mapping = use_mapping

        compiler_arguments = self.compiler_arguments
        if noise_model is not None:
            compiler_arguments["cc_max"] = True
            compiler_arguments["controlled_phase"] = True
            compiler_arguments["controlled_rotation"] = True
            compiler_arguments["hadamard_power"] = True

        # compile the abstract_circuit
        c = compiler.Compiler(**compiler_arguments)

        if self.use_mapping:
            qubits = abstract_circuit.qubits
        else:
            qubits = range(abstract_circuit.n_qubits)

        self._qubits = qubits
        self.abstract_qubit_map = {q: i for i, q in enumerate(qubits)}
        self.qubit_map = self.make_qubit_map(qubits)

        compiled = c(abstract_circuit)
        self.abstract_circuit = compiled
        # translate into the backend object
        self.circuit = self.create_circuit(abstract_circuit=compiled, variables=variables)

        if optimize_circuit:
            self.circuit = self.optimize_circuit(circuit=self.circuit)

        self.noise_model = noise_model
예제 #2
0
    def __init__(self,
                 abstract_circuit: QCircuit,
                 variables,
                 noise=None,
                 device=None,
                 qubit_map=None,
                 optimize_circuit=True,
                 *args,
                 **kwargs):
        """

        Parameters
        ----------
        abstract_circuit: QCircuit:
            the circuit which is to be rendered in the backend language.
        variables:
            values for the variables of abstract_circuit
        noise: optional:
            noise to apply to abstract circuit.
        device: optional:
            device on which to sample (or emulate sampling) abstract circuit.
        qubit_map: dictionary:
            a qubit map which maps the abstract qubits in the abstract_circuit to the qubits on the backend
            there is no need to initialize the corresponding backend types
            the dictionary should simply be {int:int} (preferred) or {int:name}
            if None the default will map to qubits 0 ... n_qubits -1 in the backend
        optimize_circuit: bool:
            whether or not to attempt backend depth optimization. Defaults to true.
        args
        kwargs
        """
        self.no_translation = False
        self._variables = tuple(abstract_circuit.extract_variables())

        compiler_arguments = self.compiler_arguments
        if noise is not None:
            compiler_arguments["cc_max"] = True
            compiler_arguments["controlled_phase"] = True
            compiler_arguments["controlled_rotation"] = True
            compiler_arguments["hadamard_power"] = True

        # compile the abstract_circuit
        c = compiler.Compiler(**compiler_arguments)

        if qubit_map is None:
            qubit_map = {q: i for i, q in enumerate(abstract_circuit.qubits)}

        # qubit map is initialized to have BackendQubits as values (they carry number and instance attributes)
        self.qubit_map = self.make_qubit_map(qubit_map)

        # pre-compilation (still an abstract ciruit, but with gates decomposed depending on backend requirements)
        compiled = c(abstract_circuit)
        self.abstract_circuit = compiled

        # translate into the backend object
        self.circuit = self.create_circuit(abstract_circuit=compiled,
                                           variables=variables)

        if optimize_circuit and noise is None:
            self.circuit = self.optimize_circuit(circuit=self.circuit)

        self.noise = noise

        self.check_device(device)
        self.device = self.retrieve_device(device)
예제 #3
0
    def __init__(self,
                 abstract_circuit: QCircuit,
                 variables,
                 noise=None,
                 device=None,
                 use_mapping=True,
                 optimize_circuit=True,
                 *args,
                 **kwargs):
        """

        Parameters
        ----------
        abstract_circuit: QCircuit:
            the circuit which is to be rendered in the backend language.
        variables:
            values for the variables of abstract_circuit
        noise: optional:
            noise to apply to abstract circuit.
        device: optional:
            device on which to sample (or emulate sampling) abstract circuit.
        use_mapping: bool:
            whether or not to use qubit mapping. Defaults to true.
        optimize_circuit: bool:
            whether or not to attempt backend depth optimization. Defaults to true.
        args
        kwargs
        """
        self._variables = tuple(abstract_circuit.extract_variables())
        self.use_mapping = use_mapping

        compiler_arguments = self.compiler_arguments
        if noise is not None:
            compiler_arguments["cc_max"] = True
            compiler_arguments["controlled_phase"] = True
            compiler_arguments["controlled_rotation"] = True
            compiler_arguments["hadamard_power"] = True

        # compile the abstract_circuit
        c = compiler.Compiler(**compiler_arguments)

        if self.use_mapping:
            qubits = abstract_circuit.qubits
        else:
            qubits = range(abstract_circuit.n_qubits)

        self._qubits = qubits
        self.abstract_qubit_map = {q: i for i, q in enumerate(qubits)}
        self.qubit_map = self.make_qubit_map(qubits)

        compiled = c(abstract_circuit)
        self.abstract_circuit = compiled
        # translate into the backend object
        self.circuit = self.create_circuit(abstract_circuit=compiled,
                                           variables=variables)

        if optimize_circuit and noise == None:
            self.circuit = self.optimize_circuit(circuit=self.circuit)

        self.noise = noise

        self.check_device(device)
        self.device = self.retrieve_device(device)
예제 #4
0
    def __init__(self,
                 abstract_circuit: QCircuit,
                 variables,
                 noise=None,
                 device=None,
                 qubit_map=None,
                 optimize_circuit=True,
                 *args,
                 **kwargs):
        """

        Parameters
        ----------
        abstract_circuit: QCircuit:
            the circuit which is to be rendered in the backend language.
        variables:
            values for the variables of abstract_circuit
        noise: optional:
            noise to apply to abstract circuit.
        device: optional:
            device on which to sample (or emulate sampling) abstract circuit.
        qubit_map: dictionary:
            a qubit map which maps the abstract qubits in the abstract_circuit to the qubits on the backend
            there is no need to initialize the corresponding backend types
            the dictionary should simply be {int:int} (preferred) or {int:name}
            if None the default will map to qubits 0 ... n_qubits -1 in the backend
        optimize_circuit: bool:
            whether or not to attempt backend depth optimization. Defaults to true.
        args
        kwargs
        """

        self._input_args = {
            "abstract_circuit": abstract_circuit,
            "variables": variables,
            "noise": noise,
            "qubit_map": qubit_map,
            "optimize_circuits": optimize_circuit,
            "device": device,
            **kwargs
        }

        self.no_translation = False
        self._variables = tuple(abstract_circuit.extract_variables())

        compiler_arguments = self.compiler_arguments
        if noise is not None:
            compiler_arguments["cc_max"] = True
            compiler_arguments["controlled_phase"] = True
            compiler_arguments["controlled_rotation"] = True
            compiler_arguments["hadamard_power"] = True

        # compile the abstract_circuit
        c = compiler.Compiler(**compiler_arguments)

        if qubit_map is None:
            qubit_map = {q: i for i, q in enumerate(abstract_circuit.qubits)}
        elif not qubit_map == {
                q: i
                for i, q in enumerate(abstract_circuit.qubits)
        }:
            warnings.warn(
                "reveived custom qubit_map = {}\n"
                "This is not fully integrated and might result in unexpected behaviour!"
                .format(qubit_map), TequilaWarning)

            if len(qubit_map) > abstract_circuit.max_qubit() + 1:
                raise TequilaException(
                    "Custom qubit_map has too many qubits {} vs {}".format(
                        len(qubit_map),
                        abstract_circuit.max_qubit() + 1))
            if max(qubit_map.keys()) > abstract_circuit.max_qubit():
                raise TequilaException(
                    "Custom qubit_map tries to assign qubit {} but we only have {}"
                    .format(max(qubit_map.keys()),
                            abstract_circuit.max_qubit()))

        # qubit map is initialized to have BackendQubits as values (they carry number and instance attributes)
        self.qubit_map = self.make_qubit_map(qubit_map)

        # pre-compilation (still an abstract ciruit, but with gates decomposed depending on backend requirements)
        compiled = c(abstract_circuit)
        self.abstract_circuit = compiled

        self.noise = noise
        self.check_device(device)
        self.device = self.retrieve_device(device)

        # translate into the backend object
        self.circuit = self.create_circuit(abstract_circuit=compiled,
                                           variables=variables)

        if optimize_circuit and noise is None:
            self.circuit = self.optimize_circuit(circuit=self.circuit)