Qiskit/qiskit_humaneval_hard huggingface dataset:
Compose XZ with a 3-qubit identity operator using the Operator and the Pauli 'YX' class in Qiskit. Return the operator instance.
You must implement this using a function named `compose_op` with no arguments.

Solution:
from qiskit.quantum_info.operators import Operator, Pauli
import numpy as np

def compose_op():
    op = Operator(np.eye(2 ** 3))
    YX = Operator(Pauli('YX'))
    op.compose(YX, qargs=[0, 2], front=True)
    return op


Test:
from qiskit.quantum_info.operators import Operator, Pauli
import numpy as np
def check(candidate):
    result = candidate()
    op = Operator(np.eye(2 ** 3))
    YX = Operator(Pauli('YX'))
    op.compose(YX, qargs=[0, 2], front=True)
    assert(result == op)

check(compose_op)
Combine the following three operators XX YY ZZ as: 0.5 * (XX + YY - 3 * ZZ).
You must implement this using a function named `combine_op` with no arguments.

Solution:
from qiskit.quantum_info.operators import Operator, Pauli

def combine_op():
    XX = Operator(Pauli('XX'))
    YY = Operator(Pauli('YY'))
    ZZ = Operator(Pauli('ZZ'))

    op = 0.5 * (XX + YY - 3 * ZZ)
    return op


Test:
from qiskit.quantum_info.operators import Operator, Pauli
def check(candidate):
    result = candidate()
    XX = Operator(Pauli('XX'))
    YY = Operator(Pauli('YY'))
    ZZ = Operator(Pauli('ZZ'))

    op = 0.5 * (XX + YY - 3 * ZZ)
    assert (result == op)

check(combine_op)
Instantiate a preset_passmanager using Qiskit using the least busy device available and optimzation level 3. Return the resulting passmanager instance.
You must implement this using a function named `generate_pass_manager_obj` with no arguments.

Solution:
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit import QuantumCircuit

def generate_pass_manager_obj():
    provider = QiskitRuntimeService()
    backend = provider.least_busy()
    pass_manager = generate_preset_pass_manager(optimization_level=3, backend=backend)
    return pass_manager


Test:
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit.transpiler.passmanager import StagedPassManager
    result = candidate()
    assert(type(result) == StagedPassManager)

check(generate_pass_manager_obj)
Write an example using Qiskit that performs tensor operation on a 1-qubit quantum circuit with an X gate and a 2-qubit quantum circuit with a CRY gate, where the CRY gate has an angle of 0.2 radians and is controlled by qubit 0.
You must implement this using a function named `tensor_circuits` with no arguments.

Solution:
from qiskit import QuantumCircuit

def tensor_circuits():
    top = QuantumCircuit(1)
    top.x(0)
    bottom = QuantumCircuit(2)
    bottom.cry(0.2, 0, 1)
    tensored = bottom.tensor(top)
    return tensored


Test:
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit.quantum_info import Statevector
    result = candidate()
    top = QuantumCircuit(1)
    top.x(0);
    bottom = QuantumCircuit(2)
    bottom.cry(0.2, 0, 1)
    tensored = bottom.tensor(top)
    assert Statevector.from_instruction(result).equiv(Statevector.from_instruction(tensored))

check(tensor_circuits)
Generate a random clifford circuit using the input n_qubit as number of qubits.
You must implement this using a function named `get_random_clifford` with the following arguments: n_qubits.

Solution:
from qiskit.quantum_info.random import random_clifford

def get_random_clifford(n_qubits):
    return random_clifford(num_qubits=n_qubits)


Test:
from qiskit.quantum_info.random import random_clifford
def check(candidate):
    from qiskit.quantum_info import Clifford
    result = candidate(3)
    assert result.num_qubits == 3
    assert isinstance(result, Clifford)

check(get_random_clifford)
Generate a random linear function circuit using the input parameters n_qubits and seed, and the random_invertible_binary_matrix method.
You must implement this using a function named `get_random_linear_function` with the following arguments: n_qubits, seed.

Solution:
from qiskit.circuit.library import LinearFunction
from qiskit.synthesis.linear.linear_matrix_utils import random_invertible_binary_matrix

def get_random_linear_function(n_qubits, seed):
    return LinearFunction(random_invertible_binary_matrix(num_qubits=n_qubits, seed=seed))


Test:
from qiskit.circuit.library import LinearFunction
from qiskit.synthesis.linear.linear_matrix_utils import random_invertible_binary_matrix
def check(candidate):
    result = candidate(3,3)
    assert result.num_qubits == 3
    assert isinstance(result, LinearFunction)

check(get_random_linear_function)
Design a Quantum Circuit that simulates random coin flips for the given samples using Qiskit Sampler with the Aer simulator as backend and outputs the count of heads and tails in a dictionary. The heads should be stored in the dict as 'Heads' and tails as 'Tails'. For example
random_coin_flip(10) == {'Heads' : 5, 'Tails : 5}
random_coin_flip(20) == {'Heads' : 9, 'Tails : 11}.
You must implement this using a function named `random_coin_flip` with the following arguments: samples.

Solution:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler

def random_coin_flip(samples):
    circuit = QuantumCircuit(1,1)
    circuit.h(0)
    circuit.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit], shots=samples).result()
    counts = result[0].data.meas.get_counts()
    return {'Heads' : counts['0'], 'Tails': counts['1']}


Test:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
def check(candidate):
    samples = 2000
    result = candidate(samples)

    assert result.keys() == {'Heads', 'Tails'}
    assert round(result['Heads']/samples, 1) == 0.5
    assert round(result['Tails']/samples, 1) == 0.5

check(random_coin_flip)
Write a function that generates n number of random 8-bit unsigned integers using a Quantum Circuit and outputs a list of integers.
You must implement this using a function named `random_number_generator_unsigned_8bit` with the following arguments: n.

Solution:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler

def random_number_generator_unsigned_8bit(n):
    circuit = QuantumCircuit(8)
    circuit.h(range(8))
    circuit.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit], shots=n).result()
    samples = result[0].data.meas.get_bitstrings()
    return [int(sample, 2) for sample in samples]


Test:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
def check(candidate):
    result = candidate(10)
    assert isinstance(result, list)
    assert len(result) == 10
    for i in range(10):
        assert result[i] >= 0 and result[i] < 256

check(random_number_generator_unsigned_8bit)
Return a simple Elitzur Vaidman bomb tester circuit.
You must implement this using a function named `simple_elitzur_vaidman` with no arguments.

Solution:
from qiskit import QuantumCircuit

def simple_elitzur_vaidman():
    circuit = QuantumCircuit(2)
    circuit.h(0)
    circuit.cx(0,1)
    circuit.h(0)
    return circuit


Test:
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit.quantum_info import Statevector
    result = candidate()
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 2
    circuit = QuantumCircuit(2)
    circuit.h(0)
    circuit.cx(0,1)
    circuit.h(0)
    assert Statevector.from_instruction(result).equiv(Statevector.from_instruction(circuit))

check(simple_elitzur_vaidman)
Remove the gate in the input position for the given Quantum Circuit.
You must implement this using a function named `remove_gate_in_position` with the following arguments: circuit, position.

Solution:
from qiskit import QuantumCircuit

def remove_gate_in_position(circuit, position):
    del circuit.data[position]
    return circuit


Test:
from qiskit import QuantumCircuit
def check(candidate):
    qc = QuantumCircuit(2)
    qc.h(0)
    qc.cx(0, 1)
    qc.h(1)
    qc.h(0)
    expected_qc = QuantumCircuit(2)
    expected_qc.cx(0, 1)
    expected_qc.h(1)
    expected_qc.h(0)
    assert candidate(qc, 0)==expected_qc

check(remove_gate_in_position)
Write a function to build a quantum teleportation circuit that takes a list of instructions as an argument to transfer the data from the sender to the receiver while taking advantage of dynamic circuits.
You must implement this using a function named `quantum_teleportation_circuit` with the following arguments: data.

Solution:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.circuit import Instruction

def quantum_teleportation_circuit(data):
    sender = QuantumRegister(1, "sender")
    receiver = QuantumRegister(1, "receiver")
    ancillary = QuantumRegister(1, "ancillary")
    c_sender = ClassicalRegister(1, "c_sender")
    c_receiver = ClassicalRegister(1, "c_receiver")
    c_ancillary = ClassicalRegister(1, "c_ancillary")
    circuit = QuantumCircuit(sender, ancillary, receiver, c_sender, c_ancillary, c_receiver)
    for gate in data:
        circuit.append(gate, [0])
    circuit.barrier()
    circuit.h(ancillary)
    circuit.cx(ancillary, receiver)
    circuit.barrier()
    circuit.cx(sender, ancillary)
    circuit.h(sender)
    circuit.measure(sender, c_sender)
    circuit.measure(ancillary, c_ancillary)
    circuit.barrier()
    with circuit.if_test((c_ancillary, 1)):
        circuit.x(receiver)
    with circuit.if_test((c_sender, 1)):
        circuit.z(receiver)
    circuit.barrier()
    circuit.measure(receiver, c_receiver)
    return circuit


Test:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.circuit import Instruction
def check(candidate):
    from qiskit.circuit.library import XGate, HGate
    from qiskit_aer import AerSimulator
    from qiskit_ibm_runtime import Sampler
    from qiskit.result import marginal_distribution
    result_x = candidate([XGate()])
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    assert isinstance(result_x, QuantumCircuit)
    assert result_x.num_qubits == 3
    assert result_x.count_ops()['x'] == 1 and result_x.count_ops()['if_else'] == 2
    assert  marginal_distribution(sampler.run([result_x]).result()[0].data.c_receiver.get_counts()) == {'1': 1024}
    result_h = candidate([HGate()])
    assert result_h.count_ops()['h'] == 3 and result_h.count_ops()['if_else'] == 2
    assert round(marginal_distribution(sampler.run([result_h]).result()[0].data.c_receiver.get_counts())['0']/1024, 1) == 0.5

check(quantum_teleportation_circuit)
Provide a quantum circuit that enables the transmission of two classical bits from the sender to the receiver through a single qubit of quantum communication, given that the sender and receiver have access to entangled qubits.
You must implement this using a function named `send_bits` with the following arguments: bitstring.

Solution:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit

def send_bits(bitstring):
    sender = QuantumRegister(1, "sender")
    receiver = QuantumRegister(1, "receiver")
    measure = ClassicalRegister(2, "measure")
    circuit = QuantumCircuit(sender, receiver, measure)
    # Prepare ebit used for superdense coding
    circuit.h(sender)
    circuit.cx(sender, receiver)
    circuit.barrier()
    # sender's operations
    if bitstring[1] == "1":
        circuit.z(sender)
    if bitstring[0] == "1":
        circuit.x(sender)
    circuit.barrier()
    # receiver's actions
    circuit.cx(sender, receiver)
    circuit.h(sender)
    circuit.measure(sender, measure[0])
    circuit.measure(receiver, measure[1])
    return circuit


Test:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
def check(candidate):
    from qiskit_aer import AerSimulator
    from qiskit_ibm_runtime import Sampler
    result_1 = candidate("10")
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    assert isinstance(result_1, QuantumCircuit)
    assert result_1.num_qubits == 2
    assert result_1.count_ops()["x"] == 1
    assert sampler.run([result_1]).result()[0].data.measure.get_counts() == {"10": 1024}
    result_2 = candidate("01")
    assert result_2.depth() == 6
    assert result_2.count_ops()["z"] == 1
    assert sampler.run([result_2]).result()[0].data.measure.get_counts() == {"01": 1024}

check(send_bits)
Given two 8-bit integers a and b design a Quantum Circuit that acts as a classical XOR gate. Simulate the circuit using Qiskit Sampler with the Aer simulator as backend and return the counts of the result.
You must implement this using a function named `xor_gate` with the following arguments: a, b.

Solution:
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.circuit.library import XOR

def xor_gate(a, b):
    circuit = XOR(8, a).compose(XOR(8, b))
    circuit.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit.decompose()]).result()
    return result[0].data.meas.get_counts()


Test:
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from qiskit.circuit.library import XOR
def check(candidate):
    assert candidate(10, 20) == {"00011110": 1024}
    assert candidate(61, 9) == {"00110100": 1024}
    assert candidate(47, 8) == {"00100111": 1024}

check(xor_gate)
Given two 3-bit integers a and b, design a quantum circuit that acts as a classical AND gate. Simulate the circuit on using Qiskit Sampler with the Aer simulator as backend and return the counts of the result.
You must implement this using a function named `and_gate` with the following arguments: a, b.

Solution:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler

def and_gate(a, b):
    qr_a = QuantumRegister(3, "qr_a")
    qr_b = QuantumRegister(3, "qr_b")
    ancillary = QuantumRegister(3, "ancillary")
    measure = ClassicalRegister(3, "measure")
    circuit = QuantumCircuit(qr_a, qr_b, ancillary, measure)
    a = format(a, '03b')
    b = format(b, '03b')
    for i in range(3):
        if a[2-i] == '1':
            circuit.x(qr_a[i])
        if b[2-i] == '1':
            circuit.x(qr_b[i])
    for i in range(3):
        circuit.ccx(qr_a[i], qr_b[i], ancillary[i])
    circuit.measure(ancillary, measure)
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit]).result()
    return result[0].data.measure.get_counts()


Test:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
def check(candidate):
    assert candidate(1, 2) == {'000': 1024}
    assert candidate(6, 7) == {'110': 1024}
    assert candidate(3, 5) == {'001': 1024}

check(and_gate)
Given two 3-bit integers a and b, design a quantum circuit that acts as a classical OR gate. Simulate the circuit using Qiskit Sampler with the Aer simulator as backend and return the counts of the result.
You must implement this using a function named `or_gate` with the following arguments: a, b.

Solution:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler

def or_gate(a, b):
    qr_a = QuantumRegister(3, "qr_a")
    qr_b = QuantumRegister(3, "qr_b")
    ancillary = QuantumRegister(3, "ancillary")
    measure = ClassicalRegister(3, "measure")
    circuit = QuantumCircuit(qr_a, qr_b, ancillary, measure)
    a = format(a, '03b')
    b = format(b, '03b')
    for i in range(3):
        if a[2-i] == '0':
            circuit.x(qr_a[i])
        if b[2-i] == '0':
            circuit.x(qr_b[i])
    for i in range(3):
        circuit.ccx(qr_a[i], qr_b[i], ancillary[i])
    circuit.x(ancillary)
    circuit.measure(ancillary, measure)
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit]).result()
    return result[0].data.measure.get_counts()


Test:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
def check(candidate):
    assert candidate(1, 2) == {"011": 1024}
    assert candidate(6, 7) == {"111": 1024}
    assert candidate(0, 5) == {"101": 1024}

check(or_gate)
Given two 8-bit integers, design a quantum circuit that acts as a classical NOT gate. Simulate the circuit Qiskit Sampler with the Aer simulator as backend and return the counts of the result.
You must implement this using a function named `not_gate` with the following arguments: a.

Solution:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler

def not_gate(a):
    circuit = QuantumCircuit(8)
    a = format(a, "08b")
    for i in range(8):
        if a[7-i] == "0":
            circuit.x(i)
    circuit.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit]).result()
    return result[0].data.meas.get_counts()


Test:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
def check(candidate):
    assert candidate(0) == {"11111111": 1024}
    assert candidate(238) == {"00010001": 1024}
    assert candidate(59) == {"11000100": 1024}

check(not_gate)
Design a SWAP gate using only CX gates.
You must implement this using a function named `create_swap_gate` with no arguments.

Solution:
from qiskit import QuantumCircuit

def create_swap_gate():
    circuit = QuantumCircuit(2)
    circuit.cx(0,1)
    circuit.cx(1,0)
    circuit.cx(0,1)
    return circuit


Test:
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit.circuit.library import SwapGate
    from qiskit.quantum_info.operators import Operator
    result = candidate()
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 2
    assert dict(result.count_ops()) == {'cx': 3}
    assert Operator(result) == Operator(SwapGate())

check(create_swap_gate)
Design a CH gate using CX and RY gates.
You must implement this using a function named `create_ch_gate` with no arguments.

Solution:
from qiskit import QuantumCircuit
from numpy import pi

def create_ch_gate():
    circuit = QuantumCircuit(2)
    circuit.ry(pi/4, 1)
    circuit.cx(0,1)
    circuit.ry(-pi/4, 1)
    return circuit


Test:
from qiskit import QuantumCircuit
from numpy import pi
def check(candidate):
    from qiskit.circuit.library import CHGate
    from qiskit.quantum_info.operators import Operator
    result = candidate()
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 2
    assert dict(result.count_ops()) == {'ry': 2, 'cx': 1}
    assert Operator(result) == Operator(CHGate())

check(create_ch_gate)
Design a CZ gate using only H and CNOT gates and return the quantum circuit.
You must implement this using a function named `create_cz_gate` with no arguments.

Solution:
from qiskit import QuantumCircuit

def create_cz_gate():
    circuit = QuantumCircuit(2)
    circuit.h(1)
    circuit.cx(0,1)
    circuit.h(1)
    return circuit


Test:
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit.circuit.library import CZGate
    from qiskit.quantum_info.operators import Operator
    result = candidate()
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 2
    assert dict(result.count_ops()) == {'h': 2, 'cx': 1}
    assert Operator(result) == Operator(CZGate())

check(create_cz_gate)
Design a CY gate using only one CX gate and any other single qubit gates.
You must implement this using a function named `create_cy_gate` with no arguments.

Solution:
from qiskit import QuantumCircuit

def create_cy_gate():
    circuit = QuantumCircuit(2)
    circuit.sdg(1)
    circuit.cx(0,1)
    circuit.s(1)
    return circuit


Test:
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit.circuit.library import CYGate
    from qiskit.quantum_info.operators import Operator
    result = candidate()
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == 2
    assert 'cx' in result.count_ops()
    for gate in result.data:
        op = gate.operation
        assert op.num_qubits == 1 or op.name == 'cx' or op.name == 'barrier'
    assert Operator(result) == Operator(CYGate())

check(create_cy_gate)
Build a Quantum Circuit by first creating one Quantum Register and one Classical Register and then perform measurement on it.
You must implement this using a function named `create_quantum_circuit_with_one_qubit_and_measure` with no arguments.

Solution:
from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister

def create_quantum_circuit_with_one_qubit_and_measure():
    q = QuantumRegister(1, 'q')
    c = ClassicalRegister(1, 'c')
    qc = QuantumCircuit(q, c)
    qc.measure(q, c)
    return qc


Test:
from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister
def check(candidate):
    result = candidate()
    assert result.depth() == 1
    assert result.width() == 2
    assert dict(result.count_ops()) == {'measure': 1}

check(create_quantum_circuit_with_one_qubit_and_measure)
Construct a BB84 protocol circuit for the sender, inputting both the states and the measured bases.
You must implement this using a function named `bb84_senders_circuit` with the following arguments: state, basis.

Solution:
from qiskit import QuantumCircuit

def bb84_senders_circuit(state, basis):
    num_qubits = len(state)
    circuit = QuantumCircuit(num_qubits)
    for i in range(len(basis)):
        if state[i] == 1:
            circuit.x(i)
        if basis[i] == 1:
            circuit.h(i)
    return circuit


Test:
from qiskit import QuantumCircuit
def check(candidate):
    from qiskit.quantum_info import Statevector
    from numpy.random import randint, seed
    seed(12345)
    qubits = 5
    state = randint(2, size=qubits)
    basis = randint(2, size=qubits)
    result = candidate(state, basis)
    assert isinstance(result, QuantumCircuit)
    assert result.num_qubits == qubits
    assert result.count_ops()['h'] == sum(basis)
    assert result.count_ops()['x'] == sum(state)
    solution = QuantumCircuit(5)
    solution.x([1,2,3])
    solution.h([0,3])
    assert Statevector.from_instruction(result).equiv(Statevector.from_instruction(solution))

check(bb84_senders_circuit)
Write a function to generate the key from the circuit and the sender's basis generated by the sender using BB84 protocol.
You must implement this using a function named `bb84_circuit_generate_key` with the following arguments: senders_basis, circuit.

Solution:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from numpy.random import randint

def bb84_circuit_generate_key(senders_basis, circuit):
    n = len(senders_basis)
    receivers_basis = randint(2, size=n)
    for i in range(n):
        if receivers_basis[i]:
            circuit.h(i)
    circuit.measure_all()
    backend = AerSimulator()
    sampler = Sampler(mode=backend)
    result = sampler.run([circuit.reverse_bits()], shots=1).result()
    count= result[0].data.meas.get_counts()
    key = next(iter(count))
    encryption_key = ''
    for i in range(n):
        if senders_basis[i] == receivers_basis[i]:
             encryption_key += str(key[i])
    return encryption_key


Test:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import Sampler
from numpy.random import randint
def check(candidate):
    from numpy.random import seed
    seed(12345)
    basis = [1, 0, 0, 1, 1]
    circuit = QuantumCircuit(5)
    circuit.x([3, 4])
    circuit.h([0, 3, 4])
    result = candidate(basis, circuit)
    assert result == "1"

check(bb84_circuit_generate_key)