Пример #1
0
def circuit2superop(circuit, min_qubits=1):
    """Return the SuperOp for a standard instruction."""
    # Get number of qubits
    max_qubits = 1
    for instr in circuit:
        qubits = []
        if hasattr(instr, 'qubits'):
            qubits = instr.qubits
        elif isinstance(instr, dict):
            qubits = instr.get('qubits', [])
        max_qubits = max(max_qubits, 1 + max(qubits))

    num_qubits = max(max_qubits, min_qubits)

    # Initialize N-qubit identity superoperator
    superop = SuperOp(np.eye(4**num_qubits))
    # compose each circuit element with the superoperator
    for instr in circuit:
        instr_op = standard_instruction_channel(instr)
        if instr_op is None:
            raise NoiseError('Cannot convert instruction {} to SuperOp'.format(instr))
        if hasattr(instr, 'qubits'):
            qubits = instr.qubits
        else:
            qubits = instr['qubits']
        superop = superop.compose(instr_op, qubits)
    return superop
Пример #2
0
def circuit2superop(circuit, min_qubits=1):
    """Return the SuperOp for a standard instruction."""
    warnings.warn(
        'circuit2superop has been deprecated as of qiskit-aer 0.10.0'
        ' and will be removed no earlier than 3 months from that release date.',
        DeprecationWarning, stacklevel=2)

    # Get number of qubits
    max_qubits = 1
    for instr in circuit:
        qubits = []
        if hasattr(instr, 'qubits'):
            qubits = instr.qubits
        elif isinstance(instr, dict):
            qubits = instr.get('qubits', [])
        max_qubits = max(max_qubits, 1 + max(qubits))

    num_qubits = max(max_qubits, min_qubits)

    # Initialize N-qubit identity superoperator
    superop = SuperOp(np.eye(4**num_qubits))
    # compose each circuit element with the superoperator
    for instr in circuit:
        instr_op = standard_instruction_channel(instr)
        if instr_op is None:
            raise NoiseError('Cannot convert instruction {} to SuperOp'.format(instr))
        if hasattr(instr, 'qubits'):
            qubits = instr.qubits
        else:
            qubits = instr['qubits']
        superop = superop.compose(instr_op, qubits)
    return superop
Пример #3
0
def circuit2superop(circuit, min_qubits=1):
    """Return the SuperOp for a standard instruction."""
    # Get number of qubits
    max_qubits = 1
    for instr in circuit:
        qubits = []
        if hasattr(instr, 'qubits'):
            qubits = instr.qubits
        elif isinstance(instr, dict):
            qubits = instr.get('qubits', [])
        max_qubits = max(max_qubits, 1 + max(qubits))

    num_qubits = max(max_qubits, min_qubits)

    # Initialize N-qubit identity superoperator
    superop = SuperOp(np.eye(4**num_qubits))
    # compose each circuit element with the superoperator
    for instr in circuit:
        name = None
        qubits = None
        params = None
        if isinstance(instr, dict):
            # Parse from plain dictionary qobj instruction
            name = instr['name']
            qubits = instr.get('qubits')
            params = instr.get('params')
        else:
            # Parse from QasmQobjInstruction
            if hasattr(instr, 'name'):
                name = instr.name
            if hasattr(instr, 'qubits'):
                qubits = instr.qubits
            if hasattr(instr, 'params'):
                params = instr.params
        if name is 'reset':
            instr_op = reset_superop(len(qubits))
        elif name is 'kraus':
            instr_op = Kraus(params)
        else:
            instr_op = SuperOp(standard_instruction_operator(name, params))
        superop = superop.compose(instr_op, qubits=qubits)
    return superop