Skip to content

Dashboard Core — Graphical Builder

Turns the ops list produced by the graphical (drag-and-drop) circuit builder component into dense_evolution's own (name, *qubits[, param]) gate-tuple format, so a circuit built visually runs through the exact same execution path as one written in OpenQASM.

graphical_builder

Turns the ops list produced by the graphical (drag-and-drop) circuit builder component into dense_evolution's own (name, *qubits[, param]) gate tuples -- the same format dashboard_core.engine already runs on the real dense_evolution DenseSVSimulator (via dashboard_core.qasm_library. gate_tuples_to_qasm for the QASM round-trip). No separate execution path for graphically-built circuits, and no Qiskit QuantumCircuit ever built here: they go through the exact same engine as typed OpenQASM.

ops_to_native_tuples

ops_to_native_tuples(n_qubits: int, ops: list) -> list

Build dense_evolution's own (name, *qubits[, param]) gate tuples from the builder's op list -- the same shape dashboard_core.engine's QASMParser-based pipeline and qasm_library.gate_tuples_to_qasm both already accept, and the same validation the old QuantumCircuit-based version did (qubit range, unknown gate name), just performed by hand instead of relying on Qiskit's own checks.

Parameters

n_qubits : int ops : list[dict] Each dict has 'gate' (one of the GATE_PALETTE gate ids: h/x/y/z/s/t/ rx/ry/rz/cx/cy/cz/swap) and 'qubits' (list[int]).

Returns

list[tuple] Pass to qasm_library.gate_tuples_to_qasm(tuples, n_qubits) for the QASM text the rest of the Composer already runs on (measure_all equivalent included there by default).

Source code in tools/dashboard_core/graphical_builder.py
def ops_to_native_tuples(n_qubits: int, ops: list) -> list:
    """Build dense_evolution's own (name, *qubits[, param]) gate tuples
    from the builder's op list -- the same shape dashboard_core.engine's
    QASMParser-based pipeline and qasm_library.gate_tuples_to_qasm both
    already accept, and the same validation the old QuantumCircuit-based
    version did (qubit range, unknown gate name), just performed by hand
    instead of relying on Qiskit's own checks.

    Parameters
    ----------
    n_qubits : int
    ops : list[dict]
        Each dict has 'gate' (one of the GATE_PALETTE gate ids: h/x/y/z/s/t/
        rx/ry/rz/cx/cy/cz/swap) and 'qubits' (list[int]).

    Returns
    -------
    list[tuple]
        Pass to qasm_library.gate_tuples_to_qasm(tuples, n_qubits) for the
        QASM text the rest of the Composer already runs on (measure_all
        equivalent included there by default).
    """
    if n_qubits < 1:
        raise ValueError("circuit must have at least 1 qubit")

    tuples = []
    for op in ops:
        gate = op.get("gate")
        qubits = op.get("qubits", [])
        for q in qubits:
            if not (0 <= q < n_qubits):
                raise ValueError(f"qubit index {q} out of range for {n_qubits}-qubit circuit")

        if gate in _SINGLE_QUBIT_METHODS:
            (q,) = qubits
            tuples.append((gate, q))
        elif gate in _ROTATION_METHODS:
            (q,) = qubits
            tuples.append((gate, q, _DEFAULT_ROTATION_ANGLE))
        elif gate == "swap":
            a, b = qubits
            tuples.append(("swap", a, b))
        elif gate in ("cx", "cy", "cz"):
            control, target = qubits
            tuples.append((gate, control, target))
        else:
            raise ValueError(f"unknown gate from circuit builder: {gate!r}")

    return tuples

See also: dashboard_core.circuit_builder_component, the UI component this module's output feeds.