Qiskit/qiskit_humaneval_hard huggingface dataset:
Given a Deutsch-Jozsa oracle in which the final qubit is the "output" qubit, return True if the oracle is constant or False otherwise.
You must implement this using a function named `dj_algorithm` with the following arguments: oracle.

Solution:
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
from numpy import isclose

def dj_algorithm(oracle):
    n = oracle.num_qubits
    qc = QuantumCircuit(n, n - 1)
    qc.x(n - 1)
    qc.h(range(n))
    qc.compose(oracle, inplace=True)
    qc.h(range(n))
    qc.measure(range(n - 1), range(n - 1))
    counts = StatevectorSampler().run([qc]).result()[0].data.c.get_counts()
    return isclose(counts.get('00000000', 0), 1024)


Test:
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
from numpy import isclose
def check(candidate):
    balanced = QuantumCircuit(5)
    balanced.cx(3, 4)
    assert candidate(balanced) == False
    constant = QuantumCircuit(9)
    constant.x(8)
    assert candidate(constant) == True

check(dj_algorithm)
Transpile a 7-qubit GHZ circuit using LookaheadSwap pass and the input custom coupling map.
You must implement this using a function named `passmanager_Lookahead` with the following arguments: coupling.

Solution:
from qiskit import QuantumCircuit
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.passes import LookaheadSwap
from qiskit.transpiler.passmanager import PassManager

def passmanager_Lookahead(coupling):
    ghz = QuantumCircuit(7)
    ghz.h(0)
    ghz.cx(0, range(1, 7))
    coupling_map = CouplingMap(couplinglist=coupling)
    ls = LookaheadSwap(coupling_map=coupling_map)
    pass_manager = PassManager(ls)
    lookahead_circ = pass_manager.run(ghz)
    return lookahead_circ


Test:
from qiskit import QuantumCircuit
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.passes import LookaheadSwap
from qiskit.transpiler.passmanager import PassManager
def check(candidate):
    from qiskit.quantum_info import Statevector
    from qiskit.transpiler.passes import CheckMap
    from qiskit.converters import circuit_to_dag
    coupling = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]
    coupling_map = CouplingMap(couplinglist=coupling)
    result = candidate(coupling)
    chkmp = CheckMap(coupling_map)
    chkmp.run(circuit_to_dag(result))
    assert chkmp.property_set["is_swap_mapped"] == True
    solution = QuantumCircuit(7)
    solution.h(0)
    solution.cx(0, range(1, 7))
    ls = LookaheadSwap(coupling_map=coupling_map)
    pass_manager = PassManager(ls)
    lookahead_circ = pass_manager.run(solution)
    assert Statevector.from_instruction(lookahead_circ).equiv(Statevector.from_instruction(result))

check(passmanager_Lookahead)
Construct a DAG circuit for a 3-qubit Quantum Circuit with the bell state applied on qubit 0 and 1. Finally return the DAG Circuit object.
You must implement this using a function named `bell_dag` with no arguments.

Solution:
from qiskit.dagcircuit import DAGCircuit
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.converters import circuit_to_dag

def bell_dag():
    q = QuantumRegister(3, 'q')
    c = ClassicalRegister(3, 'c')
    circ = QuantumCircuit(q, c)
    circ.h(q[0])
    circ.cx(q[0], q[1])
    circ.measure(q[0], c[0])
    dag = circuit_to_dag(circ)
    return dag


Test:
from qiskit.dagcircuit import DAGCircuit
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.converters import circuit_to_dag
def check(candidate):
    result = candidate()
    assert type(result) == DAGCircuit
    assert result.num_qubits() == 3
    assert result.depth() == 3
    assert dict(result.count_ops()) == {'h': 1, 'cx': 1, 'measure':1}

check(bell_dag)
Generate a DAG circuit for 3-qubit Quantum Circuit which consists of H gate on qubit 0 and CX gate on qubit 0 and 1. After converting the circuit to DAG, apply a Hadamard operation to the back of qubit 0 and return the DAGCircuit.
You must implement this using a function named `apply_op_back` with no arguments.

Solution:
from qiskit.dagcircuit import DAGCircuit
from qiskit.converters import circuit_to_dag
from qiskit.circuit.library import HGate
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit

def apply_op_back():
    q = QuantumRegister(3, "q")
    c = ClassicalRegister(3, "c")
    circ = QuantumCircuit(q, c)
    circ.h(q[0])
    circ.cx(q[0], q[1])
    dag = circuit_to_dag(circ)
    dag.apply_operation_back(HGate(), qargs=[q[0]])
    return dag


Test:
from qiskit.dagcircuit import DAGCircuit
from qiskit.converters import circuit_to_dag
from qiskit.circuit.library import HGate
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
def check(candidate):
    from qiskit.quantum_info import Statevector
    from qiskit.converters import dag_to_circuit
    result = candidate()
    assert type(result) == DAGCircuit
    assert result.num_qubits() == 3
    last_node = result.op_nodes()[-1]
    assert last_node.name == "h"
    assert len(result.descendants(last_node)) == 1
    q = QuantumRegister(3, "q")
    c = ClassicalRegister(3, "c")
    circ = QuantumCircuit(q, c)
    circ.h(q[0])
    circ.cx(q[0], q[1])
    circ.h(0)

    candidate_circ = dag_to_circuit(result)
    assert Statevector.from_instruction(circ).equiv(Statevector.from_instruction(candidate_circ))

check(apply_op_back)
Prepare phi plus and phi minus bell states and visualize their results in a histogram and return the histogram.
You must implement this using a function named `visualize_bell_states` with no arguments.

Solution:
from matplotlib.figure import Figure
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.visualization import plot_histogram

def visualize_bell_states():
    phi_plus = QuantumCircuit(2)
    phi_minus = QuantumCircuit(2)
    phi_plus.h(0)
    phi_plus.cx(0,1)
    phi_minus.x(0)
    phi_minus.h(0)
    phi_minus.cx(0,1)
    phi_plus.measure_all()
    phi_minus.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result_phi_plus = sampler.run([phi_plus], shots=1000).result()
    result_phi_minus = sampler.run([phi_minus], shots=1000).result()
    phi_plus_counts = result_phi_plus[0].data.meas.get_counts()
    phi_minus_counts = result_phi_minus[0].data.meas.get_counts()
    return plot_histogram([phi_plus_counts, phi_minus_counts], legend = ['|Φ+⟩ Count', '|Φ-⟩ Count'])


Test:
from matplotlib.figure import Figure
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.visualization import plot_histogram
def check(candidate):
    from matplotlib.patches import Rectangle
    result = candidate()
    assert isinstance(result, Figure)
    gca = result.gca()
    assert {xlabel.get_text() for xlabel in gca.get_xticklabels()} == {"00", "11"}
    objs = gca.findobj(Rectangle)
    assert len(objs) >= 4
    counts = [obj.get_height() for obj in objs[:4]]
    shots = counts[0] + counts[1]
    for i in range(4):
        assert round(counts[i]/shots, 1) == 0.5

check(visualize_bell_states)
Plot a circuit layout visualization for a transpiled bell circuit using a pass manager with optimization level as 1 for the Fake Athens V2 backend.
You must implement this using a function named `plot_circuit_layout_bell` with no arguments.

Solution:
from matplotlib.figure import Figure
from qiskit.visualization import plot_circuit_layout
from qiskit import QuantumCircuit
from qiskit_ibm_runtime.fake_provider import FakeAthensV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

def plot_circuit_layout_bell():
    backend = FakeAthensV2()
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0,1)
    pass_manager = generate_preset_pass_manager(optimization_level=1, backend=backend)
    brisbane_bell = pass_manager.run(bell)
    return (plot_circuit_layout(brisbane_bell, backend))


Test:
from matplotlib.figure import Figure
from qiskit.visualization import plot_circuit_layout
from qiskit import QuantumCircuit
from qiskit_ibm_runtime.fake_provider import FakeAthensV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def check(candidate):
    result = candidate()
    assert type(result) == Figure

check(plot_circuit_layout_bell)
Plot a city_state for a bell circuit.
You must implement this using a function named `plot_circuit_layout_bell` with no arguments.

Solution:
from qiskit import QuantumCircuit
from matplotlib.figure import Figure
from qiskit.visualization import plot_state_city
from qiskit.quantum_info import Statevector

def plot_circuit_layout_bell():
    bell = QuantumCircuit(2)
    bell.h(0)
    bell.cx(0,1)
    bell_state = Statevector(bell)
    plot_state_city(bell_state)
    return plot_state_city(bell_state)


Test:
from qiskit import QuantumCircuit
from matplotlib.figure import Figure
from qiskit.visualization import plot_state_city
from qiskit.quantum_info import Statevector
def check(candidate):
    result = candidate()
    assert type(result) == Figure
    assert len(result.axes) == 2

check(plot_circuit_layout_bell)
Run a Bell circuit on Qiskit Sampler and run the circuit on the Aer simulator with the seed set as 42. Return the resulting counts dictionary.
You must implement this using a function named `sampler_qiskit` with no arguments.

Solution:
from typing import Dict
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit_ibm_runtime.options import SamplerOptions

def sampler_qiskit():
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.cx(0,1)
    qc.measure_all()

    options = SamplerOptions()
    options.simulator.seed_simulator=42
    sampler = Sampler(mode=AerSimulator(), options=options)
    job = sampler.run([qc])
    result = job.result()[0].data.meas.get_counts()
    return result


Test:
from typing import Dict
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit_ibm_runtime.options import SamplerOptions
def check(candidate):
    result = candidate()
    assert result == {"00": 521, "11": 503}

check(sampler_qiskit)
Run a Bell circuit on Qiskit Estimator and return expectation values for the bases II, XX, YY, ZZ.
You must implement this using a function named `estimator_qiskit` with no arguments.

Solution:
from numpy import float64
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Estimator
from qiskit.quantum_info import SparsePauliOp

def estimator_qiskit():
    observable = SparsePauliOp(["II","XX","YY","ZZ"], coeffs=[1, 1, -1, 1])
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.cx(0,1)

    estimator = Estimator(mode=AerSimulator())
    job = estimator.run([(qc, observable)])
    result = job.result()[0].data.evs.item()
    return result


Test:
from numpy import float64
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Estimator
from qiskit.quantum_info import SparsePauliOp
def check(candidate):
    result = candidate()
    assert result == 4.0

check(estimator_qiskit)
Generate two random quantum circuits, each with 2 qubits and a depth of 2, using seed values of 0 and 1 respectively. Run the circuits using the Sampler on the Aer simulator with the seed set as 42 and return the counts for both circuits.
You must implement this using a function named `run_multiple_sampler` with no arguments.

Solution:
from typing import List
from qiskit.circuit.random import random_circuit
from qiskit_ibm_runtime import Sampler, SamplerOptions
from qiskit_aer import AerSimulator

def run_multiple_sampler():
    circuits = (
        random_circuit(2, 2, seed=0, measure=True).decompose(reps=1),
        random_circuit(2, 2, seed=1, measure=True).decompose(reps=1),
    )
    options = SamplerOptions()
    options.simulator.seed_simulator=42
    sampler = Sampler(mode=AerSimulator(), options=options)
    job = sampler.run(circuits)
    results = job.result()
    statevectors = [result.data.c.get_counts() for result in results]
    return statevectors


Test:
from typing import List
from qiskit.circuit.random import random_circuit
from qiskit_ibm_runtime import Sampler, SamplerOptions
from qiskit_aer import AerSimulator
def check(candidate):
    result = candidate()
    assert isinstance(result, list)
    assert result == [{"01": 1024}, {"00": 552, "01": 472}]

check(run_multiple_sampler)
Generate all four Bell states and execute them on the FakeAlgiers backend using SamplerV2 with batch mode. Each Bell state circuit will be transpiled with an optimization level of 3, with the seed 123 for the transpiler.
Returns a dictionary where the keys are the Bell state names ['phi_plus', 'phi_minus', 'psi_plus', 'psi_minus'] and the values are the corresponding RuntimeJob objects and the batch id.
You must implement this using a function named `run_jobs_on_batch` with no arguments.

Solution:
from typing import Dict, Optional, Tuple
from qiskit_ibm_runtime import Batch, Sampler
from qiskit.primitives.primitive_job import PrimitiveJob
from qiskit_ibm_runtime.fake_provider import FakeAlgiers
from qiskit.transpiler import CouplingMap
from qiskit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

def run_jobs_on_batch():
    def create_bell_circuit(state):
        "Helper function to create bell state"
        qc = QuantumCircuit(2)
        qc.h(0) 
        qc.cx(0, 1)
        if state == "phi_minus":
            qc.z(0)
        elif state == "psi_plus":
            qc.x(1)
        elif state == "psi_minus'":
            qc.x(1)
            qc.z(0)
        qc.measure_all()
        return qc
        
    # Create bell states
    bell_states = ["phi_plus", "phi_minus", "psi_plus", "psi_minus"]
    circuits = [create_bell_circuit(state) for state in bell_states]

    # Setting backend and pass managers
    backend = FakeAlgiers()
    coupling_map = CouplingMap(backend.configuration().coupling_map)
    pm = generate_preset_pass_manager(optimization_level = 3, backend=backend, seed_transpiler=123, coupling_map=coupling_map)

    # Running jobs using batch
    with Batch(backend=backend) as batch:
        jobs = {}
        sampler = Sampler(mode=batch)
        for bell_state, bell_circuit in zip(bell_states, circuits):
            isa_bell_circuit = pm.run(bell_circuit)
            jobs[bell_state] = sampler.run([(isa_bell_circuit)])
        return jobs


Test:
from typing import Dict, Optional, Tuple
from qiskit_ibm_runtime import Batch, Sampler
from qiskit.primitives.primitive_job import PrimitiveJob
from qiskit_ibm_runtime.fake_provider import FakeAlgiers
from qiskit.transpiler import CouplingMap
from qiskit import QuantumCircuit
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def check(candidate):
    from numpy import isclose
    jobs = candidate()
    reference_data = {
        'phi_plus': {'00': 0.10, '11': 0.10},
        'phi_minus': {'00': 0.10, '11': 0.10},
        'psi_plus': {'01': 0.10, '10': 0.10},
        'psi_minus': {'01': 0.1, '10': 0.10}
    }
    assert isinstance(jobs, dict)
    assert set(jobs.keys()) == set(reference_data.keys())
    for state, job in jobs.items():
        assert isinstance(job, PrimitiveJob)
        assert job.job_id() is not None
        counts = job.result()[0].data.meas.get_counts()
        shots = 4096
        normalized_counts = {k: v/shots for k, v in counts.items()}
        for key, value in reference_data[state].items():
            assert isclose(normalized_counts[key], value, atol=1e-01)

check(run_jobs_on_batch)
Run an EfficientSU2 circuit with 5 qubits, 2 repetitions, and pairwise entanglement on the FakeAuckland backend.
The circuit should be transpiled with an optimization level of 1 and a transpiler seed of 789. Use 1*Z_-1 observable to calculate the expectation value.
You must implement this using a function named `run_circuit_with_dd_trex` with no arguments.

Solution:
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler import CouplingMap
import numpy as np
from qiskit_ibm_runtime import QiskitRuntimeService, Estimator, EstimatorOptions
from qiskit.primitives.primitive_job import PrimitiveJob
from qiskit_ibm_runtime.fake_provider import FakeAuckland
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

def run_circuit_with_dd_trex():
    n_qubits = 5
    reps = 2
    circuit = EfficientSU2(n_qubits, entanglement="pairwise", reps=reps)
    observable = SparsePauliOp.from_sparse_list([("Z", [-1], 1.0)], num_qubits=n_qubits)
    

    # Generate random parameters
    rng = np.random.default_rng(1234)
    params = rng.uniform(-np.pi, np.pi, size=circuit.num_parameters)
    backend = FakeAuckland()
    coupling_map = CouplingMap(backend.configuration().coupling_map)
    pm = generate_preset_pass_manager(optimization_level = 1, backend=backend, seed_transpiler=789, coupling_map=coupling_map)
    isa_circuit = pm.run(circuit)
    isa_observable = observable.apply_layout(isa_circuit.layout)

    options = EstimatorOptions()
    options.environment.job_tags = ["run_circ_dd_trex"]
    estimator = Estimator(mode=backend, options=options)
    job = estimator.run([(isa_circuit, isa_observable, params)])
    return job


Test:
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler import CouplingMap
import numpy as np
from qiskit_ibm_runtime import QiskitRuntimeService, Estimator, EstimatorOptions
from qiskit.primitives.primitive_job import PrimitiveJob
from qiskit_ibm_runtime.fake_provider import FakeAuckland
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
def check(candidate):
    from numpy import isclose
    job = candidate()
    assert isinstance(job, PrimitiveJob)
    assert job.job_id() is not None
    result = job.result()
    assert isclose(result[0].data.evs.item(), 0.33, atol=0.06)

check(run_circuit_with_dd_trex)
Write a function to design a Bernstein-Vazirani oracle from a bitstring and return it.
You must implement this using a function named `bv_function` with the following arguments: s.

Solution:
from qiskit import QuantumCircuit

def bv_function(s):
    n = len(s)
    qc = QuantumCircuit(n + 1)
    for index, bit in enumerate(reversed(s)):
        if bit == "1":
            qc.cx(index, n)
    return qc


Test:
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit.quantum_info.operators import Operator
    s = "1111"
    result = candidate(s)
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 5
    solution = QuantumCircuit(5)
    for i in range(4):
        solution.cx(i, 4)
    assert Operator(result).equiv(Operator(solution))

check(bv_function)
Illustrate a Bernstein-Vazirani algorithm routine on Qiskit and run it using Qiskit Sampler with Aer simulator as backend for a string of 0s and 1s. Return the bit strings of the result and the result itself.
You must implement this using a function named `bv_algorithm` with the following arguments: s.

Solution:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.primitives.containers.primitive_result import PrimitiveResult

def bv_algorithm(s):
    qc = QuantumCircuit(len(s) + 1)
    for index, bit in enumerate(reversed(s)):
        if bit == "1":
            qc.cx(index, len(s))
    qc.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result= sampler.run([qc], shots=1).result()
    bitstrings = result[0].data.meas.get_bitstrings()
    return [bitstrings, result]


Test:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.primitives.containers.primitive_result import PrimitiveResult
def check(candidate):
    s = "1111"
    result = candidate(s)
    assert (type(result[0]) == list)
    assert (len(result[0]) == result[1][0].data.meas.num_shots)
    assert (type(result[1]) == PrimitiveResult)

check(bv_algorithm)
Build a 2-qubit Quantum Circuit composed by H gate in Quantum register 0, Controlled-RZ gate in quantum register 0 1 with given input theta value, H gate in quantum register 1 and Controlled-RY gate in quantum register 1 0 with given input theta value.
You must implement this using a function named `create_quantum_circuit_based_h0_crz01_h1_cry10` with the following arguments: theta.

Solution:
from qiskit import QuantumCircuit

def create_quantum_circuit_based_h0_crz01_h1_cry10(theta):
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.crz(theta,0,1)
    qc.h(1)
    qc.cry(theta,1,0)
    return qc


Test:
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit import QuantumRegister
    from qiskit.circuit import CircuitInstruction
    from math import pi
    from qiskit.circuit.library import HGate, CRZGate, CRYGate
    qr = QuantumRegister(2, name="q")
    theta = pi/2
    data = candidate(theta).data
    assert data[0]==CircuitInstruction(HGate(), [qr[0]], [])
    assert data[1]==CircuitInstruction(CRZGate(theta), [qr[0], qr[1]], [])
    assert data[2]==CircuitInstruction(HGate(), [qr[1]], [])
    assert data[3]==CircuitInstruction(CRYGate(theta), [qr[1], qr[0]], [])

check(create_quantum_circuit_based_h0_crz01_h1_cry10)
Initialize a uniform superposition on n qubits and return statevector.
You must implement this using a function named `create_uniform_superposition` with the following arguments: n.

Solution:
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

def create_uniform_superposition(n):
    qc = QuantumCircuit(n)
    qc.h(range(n))
    return Statevector(qc)


Test:
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
def check(candidate):
    from qiskit.quantum_info import state_fidelity
    from math import sqrt
    assert round(state_fidelity(candidate(1), [1/sqrt(2)]*2),3)==1
    assert round(state_fidelity(candidate(2), [0.5]*4),3)==1
    assert round(state_fidelity(candidate(3), [1/sqrt(8)]*8),3)==1

check(create_uniform_superposition)
Initialize a non-trivial 3-qubit state for a given desired vector state and return counts after running it using Qiskit Sampler with the Aer simulator as backend and ser=t seed as 42.
You must implement this using a function named `init_random_3qubit` with the following arguments: desired_vector.

Solution:
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit_ibm_runtime.options import SamplerOptions

def init_random_3qubit(desired_vector):
    qc = QuantumCircuit(3)
    qc.initialize(desired_vector, range(3))
    qc.measure_all()
    backend = AerSimulator()
    options = SamplerOptions()
    options.simulator.seed_simulator=42
    sampler = Sampler(mode=backend,options=options)
    result = sampler.run([qc]).result()
    return result[0].data.meas.get_counts()


Test:
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit_ibm_runtime.options import SamplerOptions
def check(candidate):
    from math import sqrt
    from qiskit.quantum_info import state_fidelity
    desired_vector = [0.25j, 1 /sqrt(8)+0j, 0.25+0.25j, 0, 0,1 / sqrt(8) * (1+2j), 0.25+0j, 0]
    result = candidate(desired_vector)
    assert isinstance(result, dict)
    assert result == {"101": 665, "010": 118, "000": 49, "110": 51, "001": 141}

check(init_random_3qubit)