Ejemplo n.º 1
0
    def new_scaling_function(circuit: QPROGRAM, *args: Any,
                             **kwargs: Any) -> QPROGRAM:
        # Convert to Mitiq representation.
        mitiq_circuit, input_circuit_type = convert_to_mitiq(circuit)

        # Scale the noise in the circuit.
        scaled_circuit = noise_scaling_function(mitiq_circuit, *args, **kwargs)

        if kwargs.get("return_mitiq") is True:
            return scaled_circuit

        # Base conversion back to input type.
        scaled_circuit = convert_from_mitiq(scaled_circuit, input_circuit_type)

        # Keep the same register structure and measurement order with Qiskit.
        if input_circuit_type == "qiskit":
            from mitiq.mitiq_qiskit.conversions import (
                _transform_registers,
                _measurement_order,
            )

            scaled_circuit.remove_final_measurements()
            _transform_registers(
                scaled_circuit,
                new_qregs=circuit.qregs,
                new_cregs=circuit.cregs if scaled_circuit.cregs else None,
            )
            if circuit.cregs and not scaled_circuit.cregs:
                scaled_circuit.add_register(*circuit.cregs)

            for q, c in _measurement_order(circuit):
                scaled_circuit.measure(q, c)

        return scaled_circuit
Ejemplo n.º 2
0
    def new_scaling_function(
        circuit: QPROGRAM, *args: Any, **kwargs: Any
    ) -> QPROGRAM:
        scaled_circuit = atomic_converter(noise_scaling_function)(
            circuit, *args, **kwargs
        )

        # Keep the same register structure and measurement order with Qiskit.
        if "qiskit" in scaled_circuit.__module__:
            from mitiq.mitiq_qiskit.conversions import (
                _transform_registers,
                _measurement_order,
            )

            scaled_circuit.remove_final_measurements()
            _transform_registers(
                scaled_circuit,
                new_qregs=circuit.qregs,
                new_cregs=circuit.cregs if scaled_circuit.cregs else None,
            )
            if circuit.cregs and not scaled_circuit.cregs:
                scaled_circuit.add_register(*circuit.cregs)

            for q, c in _measurement_order(circuit):
                scaled_circuit.measure(q, c)

        return scaled_circuit
Ejemplo n.º 3
0
def test_measurement_order(size):
    q, c = qiskit.QuantumRegister(size), qiskit.ClassicalRegister(size)
    circuit = qiskit.QuantumCircuit(q, c)

    index_order = [int(i) for i in np.random.RandomState(1).permutation(size)]
    for i in index_order:
        circuit.measure(q[i], c[i])

    order = _measurement_order(circuit)
    assert order == [(q[i], c[i]) for i in index_order]