arasyi/quantum-api-drift huggingface dataset:
Task: Write the function that converts the matrix [[0, 0, 0, 1],[0, 0, 1, 0],[1, 0, 0, 0],[0, 1, 0, 0]] into a unitary gate and apply it to a Quantum Circuit. Then return the circuit.
You must implement this using a function named `create_unitary_from_matrix` with no arguments.
Function to implement: create_unitary_from_matrix
Tests:
from qiskit import QuantumCircuit
result = create_unitary_from_matrix()
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 2
assert len(result.data) > 0
Task: Generate a 1 qubit QuantumCircuit with a parametrized Rx gate with parameter "theta".
You must implement this using a function named `create_parametrized_gate` with no arguments.
Function to implement: create_parametrized_gate
Tests:
circuit = create_parametrized_gate()
assert circuit.num_qubits == 1
assert circuit.data[0].operation.name == "rx"
assert circuit.data[0].operation.params[0].name == "theta"
Task: Return a 1-qubit QuantumCircuit with a parametrized Rx gate and parameter "theta". If value is not None, return the circuit with value assigned to theta.
You must implement this using a function named `rx_gate` with the following arguments: value.
Function to implement: rx_gate
Tests:
circuit = rx_gate()
assert circuit.num_qubits == 1
assert circuit.data[0].operation.name == "rx"
assigned = rx_gate(value=1.0)
assert assigned.num_qubits == 1
assert assigned.num_parameters == 0
Task: Create a Qiskit circuit with the following unitary [[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]], consisting of only single-qubit gates and CX gates, then transpile the circuit using pass manager with optimization level as 1.
You must implement this using a function named `create_operator` with no arguments.
Function to implement: create_operator
Tests:
from qiskit import QuantumCircuit
result = create_operator()
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 2
for inst in result.data:
    if inst.operation.num_qubits > 1:
        assert inst.operation.name in ["cx", "barrier"]
Task: 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.
Function to implement: create_quantum_circuit_based_h0_crz01_h1_cry10
Tests:
from math import pi
from qiskit import QuantumCircuit
result = create_quantum_circuit_based_h0_crz01_h1_cry10(pi / 2)
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 2
assert len(result.data) >= 4
Task: 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.
Function to implement: tensor_circuits
Tests:
from qiskit import QuantumCircuit
result = tensor_circuits()
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 3
assert len(result.data) > 0
Task: Define a phi plus bell state using Qiskit, transpile the circuit using pass manager with optimization level as 1, run it using Qiskit Sampler with the Aer simulator as backend and return the counts dictionary.
You must implement this using a function named `run_bell_state_simulator` with no arguments.
Function to implement: run_bell_state_simulator
Tests:
result = run_bell_state_simulator()
assert isinstance(result, dict)
assert len(result) > 0
assert set(result.keys()).issubset({"00", "11"})
Task: Run a phi plus Bell circuit using Qiskit Sampler with the Aer simulator as backend for 100 shots and return measurement results for each shots. To do so, transpile the circuit using a pass manager with optimization level as 1.
You must implement this using a function named `bell_each_shot` with no arguments.
Function to implement: bell_each_shot
Tests:
result = bell_each_shot()
assert isinstance(result, list)
assert len(result) > 0
assert all(isinstance(x, str) for x in result)
Task: 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.
Function to implement: sampler_qiskit
Tests:
result = sampler_qiskit()
assert isinstance(result, dict)
assert len(result) > 0
assert set(result.keys()).issubset({"00", "11"})
Task: 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.
Function to implement: run_multiple_sampler
Tests:
result = run_multiple_sampler()
assert isinstance(result, list)
assert len(result) == 2
for counts in result:
    assert isinstance(counts, dict)
    assert len(counts) > 0
Task: 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.
Function to implement: random_number_generator_unsigned_8bit
Tests:
result = random_number_generator_unsigned_8bit(10)
assert isinstance(result, list)
assert len(result) == 10
for value in result:
    assert isinstance(value, int)
    assert 0 <= value < 256
Task: Create a constant oracle for use in a Deutsch-Jozsa experiment. The oracle takes two input bits (qubits 0 and 1) and writes to one output bit (qubit 2).
You must implement this using a function named `dj_constant_oracle` with no arguments.
Function to implement: dj_constant_oracle
Tests:
from qiskit import QuantumCircuit
result = dj_constant_oracle()
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 3
Task: 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.
Function to implement: dj_algorithm
Tests:
from qiskit import QuantumCircuit
balanced = QuantumCircuit(5)
balanced.cx(3, 4)
constant = QuantumCircuit(9)
constant.x(8)
result_balanced = dj_algorithm(balanced)
result_constant = dj_algorithm(constant)
assert isinstance(result_balanced, bool)
assert isinstance(result_constant, bool)
Task: 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.
Function to implement: bv_function
Tests:
from qiskit import QuantumCircuit
result = bv_function("1111")
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 5
assert result.count_ops().get("cx", 0) > 0
Task: 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.
Function to implement: bv_algorithm
Tests:
result = bv_algorithm("1111")
assert isinstance(result, (list, tuple))
assert len(result) == 2
assert isinstance(result[0], list)
assert result[1] is not None
Task: 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.
Function to implement: send_bits
Tests:
from qiskit import QuantumCircuit
result_1 = send_bits("10")
assert isinstance(result_1, QuantumCircuit)
assert result_1.num_qubits == 2
result_2 = send_bits("01")
assert isinstance(result_2, QuantumCircuit)
assert result_2.num_qubits == 2
Task: 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.
Function to implement: bb84_senders_circuit
Tests:
from numpy.random import randint, seed
from qiskit import QuantumCircuit
seed(12345)
qubits = 5
state = randint(2, size=qubits)
basis = randint(2, size=qubits)
result = bb84_senders_circuit(state, basis)
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == qubits
Task: 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.
Function to implement: bb84_circuit_generate_key
Tests:
from qiskit import QuantumCircuit
basis = [1, 0, 0, 1, 1]
circuit = QuantumCircuit(5)
circuit.x([3, 4])
circuit.h([0, 3, 4])
result = bb84_circuit_generate_key(basis, circuit)
assert isinstance(result, str)
assert set(result).issubset({"0", "1"})
Task: Write a function that takes the bitstring 's' as the input and builds a Quantum Circuit such that the output when xor-ed with the input 's' is same as the 's'. When building the quantum circuit make sure the classical registers is named 'c'.
You must implement this using a function named `simons_algorithm` with the following arguments: s.
Function to implement: simons_algorithm
Tests:
from qiskit import QuantumCircuit
result = simons_algorithm("1010")
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 8
assert result.num_clbits >= 4
Task: 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.
Function to implement: bell_dag
Tests:
from qiskit.dagcircuit import DAGCircuit
result = bell_dag()
assert isinstance(result, DAGCircuit)
assert result.num_qubits() == 3
ops = dict(result.count_ops())
assert "h" in ops
assert "cx" in ops
Task: 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.
Function to implement: apply_op_back
Tests:
from qiskit.dagcircuit import DAGCircuit
result = apply_op_back()
assert isinstance(result, DAGCircuit)
assert result.num_qubits() == 3
assert result.depth() >= 2
Task: 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.
Function to implement: remove_gate_in_position
Tests:
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.h(1)
qc.h(0)
result = remove_gate_in_position(qc, 0)
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 2
assert len(result.data) == 3
Task: Split `circuit` at each barrier operation. Do not include barriers in the output circuits.
You must implement this using a function named `split_circuit_at_barriers` with the following arguments: circuit.
Function to implement: split_circuit_at_barriers
Tests:
from qiskit import QuantumCircuit
qc = QuantumCircuit(3)
qc.x(0)
qc.barrier()
qc.cx(0, 1)
qc.h([0, 1])
qc.z(1)
qc.barrier()
qc.barrier()
qc.tdg(0)
circuits = split_circuit_at_barriers(qc)
assert isinstance(circuits, list)
assert len(circuits) == 4
for circuit in circuits:
    assert isinstance(circuit, QuantumCircuit)
    assert all(inst.operation.name != "barrier" for inst in circuit.data)
Task: For a given Quantum Circuit remove all the barriers from it and return.
You must implement this using a function named `remove_barrier` with the following arguments: circuit.
Function to implement: remove_barrier
Tests:
from qiskit import QuantumCircuit
circuit = QuantumCircuit(1)
circuit.h(0)
circuit.barrier()
circuit.x(0)
candidate_circuit = remove_barrier(circuit)
assert isinstance(candidate_circuit, QuantumCircuit)
for inst in candidate_circuit.data:
    assert inst.operation.name != "barrier"
Task: Unroll circuit for the gateset: CX, ID, RZ, SX, X, U.
You must implement this using a function named `unroll_circuit` with the following arguments: circuit.
Function to implement: unroll_circuit
Tests:
from qiskit import QuantumCircuit
import numpy as np
trial_circuit = QuantumCircuit(2)
trial_circuit.h(0)
trial_circuit.u(0.3, 0.1, 0.1, 1)
trial_circuit.cp(np.pi / 4, 0, 1)
trial_circuit.h(0)
output = unroll_circuit(trial_circuit)
assert isinstance(output, QuantumCircuit)
for inst in output.data:
    assert inst.operation.name in ["cx", "id", "rz", "sx", "x", "u"]
Task: 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.
Function to implement: passmanager_Lookahead
Tests:
from qiskit import QuantumCircuit
from qiskit.transpiler import CouplingMap
coupling = CouplingMap([[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]])
result = passmanager_Lookahead(coupling)
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 7
Task: Return a transpiler pass that replaces all non-controlled Z-gates with H-X-H-gate sequences.
You must implement this using a function named `create_hxh_pass` with no arguments.
Function to implement: create_hxh_pass
Tests:
from qiskit.transpiler.basepasses import TransformationPass
hxh_pass = create_hxh_pass()
if isinstance(hxh_pass, type):
    assert issubclass(hxh_pass, TransformationPass)
else:
    assert isinstance(hxh_pass, TransformationPass)
Task: Create a 5-qubit quantum circuit with a chain of CX gates and apply Qiskit's CollectLinearFunctions transpiler pass. Return two circuits:
1. One with no block width restriction.
2. One with a max_block_width of 3.
Use PassManager to apply the pass and return both circuits.
You must implement this using a function named `collect_linear_blocks_with_and_without_limit` with no arguments.
Function to implement: collect_linear_blocks_with_and_without_limit
Tests:
from qiskit import QuantumCircuit
full, limited = collect_linear_blocks_with_and_without_limit()
assert isinstance(full, QuantumCircuit)
assert isinstance(limited, QuantumCircuit)
assert full.num_qubits == 5
assert limited.num_qubits == 5
Task: Create a pass manager to decompose the single qubit gates into gates of the dense subset ['t', 'tdg', 'h'] in the given circuit.
You must implement this using a function named `sol_kit_decomp` with the following arguments: circuit.
Function to implement: sol_kit_decomp
Tests:
from qiskit import QuantumCircuit
import numpy as np
circ = QuantumCircuit(3)
circ.h(0)
circ.rx(np.pi / 7, 1)
circ.ry(np.pi / 5, 2)
circ.cx(0, 1)
circ.rz(np.pi / 3, 1)
circ.s(2)
circ.t(0)
circ_can = sol_kit_decomp(circ)
assert isinstance(circ_can, QuantumCircuit)
assert circ_can.num_qubits == circ.num_qubits
Task: Remove barriers from the given quantum circuit and calculate the depth before and after removal.
Return a PropertySet with 'depth_before', 'depth_after', and 'width' properties.
The function should only remove barriers and not perform any other optimizations.
You must implement this using a function named `calculate_depth_after_barrier_removal` with the following arguments: qc.
Function to implement: calculate_depth_after_barrier_removal
Tests:
from qiskit import QuantumCircuit
qc = QuantumCircuit(3)
qc.h(0)
qc.barrier()
qc.cx(0, 1)
qc.barrier()
qc.cx(1, 2)
qc.measure_all()
property_set = calculate_depth_after_barrier_removal(qc)
assert "depth_before" in property_set
assert "depth_after" in property_set
Task: Create a CouplingMap with a specific coupling list, then modify it by adding an edge and a physical qubit.
The initial coupling list is [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]].
Add an edge (5, 6), and add a physical qubit "7".
You must implement this using a function named `create_and_modify_coupling_map` with no arguments.
Function to implement: create_and_modify_coupling_map
Tests:
from qiskit.transpiler import CouplingMap
cmap = create_and_modify_coupling_map()
assert isinstance(cmap, CouplingMap)
assert len(cmap.get_edges()) > 0
assert len(cmap.physical_qubits) >= 7
Task: Create a Target object for a 2-qubit system and add UGate and CXGate instructions with specific properties.
- Add UGate for both qubits (0 and 1) with parameters 'theta', 'phi', and 'lambda'.
- Add CXGate for qubit pairs (0,1) and (1,0).
- All instructions should have nonzero 'duration' and 'error' properties set.
You must implement this using a function named `create_target` with no arguments.
Function to implement: create_target
Tests:
from qiskit.transpiler import Target
target = create_target()
assert isinstance(target, Target)
assert len(target.instructions) > 0
Task: Generate a QASM 2 string representing a Phi plus Bell state quantum circuit. Then, convert this QASM 2 string into a Quantum Circuit object and return the resulting circuit.
You must implement this using a function named `convert_qasm_string_to_quantum_circuit` with no arguments.
Function to implement: convert_qasm_string_to_quantum_circuit
Tests:
from qiskit import QuantumCircuit
data = convert_qasm_string_to_quantum_circuit()
assert isinstance(data, QuantumCircuit)
assert data.num_qubits == 2
Task: Create a file containing the binary serialization of a Phi plus Bell state quantum circuit and write it as 'bell.qpy' in binary mode.
You must implement this using a function named `create_binary_serialization` with no arguments.
Function to implement: create_binary_serialization
Tests:
import os
from qiskit import qpy
create_binary_serialization()
assert os.path.exists("bell.qpy")
with open("bell.qpy", "rb") as fd:
    data = qpy.load(fd)[0]
assert data.num_qubits == 2
Task: Given a QuantumCircuit, convert it into qasm2 string and return it.
You must implement this using a function named `convert_quantum_circuit_to_qasm_string` with the following arguments: circuit.
Function to implement: convert_quantum_circuit_to_qasm_string
Tests:
from qiskit import QuantumCircuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qasm_str = convert_quantum_circuit_to_qasm_string(qc)
assert isinstance(qasm_str, str)
assert len(qasm_str) > 0
assert "OPENQASM" in qasm_str
Task: Given a QuantumCircuit, convert it into a gate equivalent to the action of the input circuit and return it.
You must implement this using a function named `circ_to_gate` with the following arguments: circ.
Function to implement: circ_to_gate
Tests:
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.gate import Gate
q = QuantumRegister(3, "q")
circ = QuantumCircuit(q)
circ.h(q[0])
circ.cx(q[0], q[1])
custom_gate = circ_to_gate(circ)
assert isinstance(custom_gate, Gate)
assert custom_gate.num_qubits == 3
Task: Get unitary matrix for a phi plus bell circuit and return it.
You must implement this using a function named `get_unitary` with no arguments.
Function to implement: get_unitary
Tests:
import numpy as np
result = get_unitary()
assert hasattr(result, "shape")
assert tuple(result.shape) == (4, 4)
Task: Compose YX 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.
Function to implement: compose_op
Tests:
from qiskit.quantum_info.operators import Operator
result = compose_op()
assert isinstance(result, Operator)
assert result.num_qubits == 3
Task: 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.
Function to implement: combine_op
Tests:
from qiskit.quantum_info.operators import Operator
result = combine_op()
assert isinstance(result, Operator)
assert result.num_qubits == 2
Task: Construct a Phi plus Bell state quantum circuit, compute its Density Matrix and Concurrence, and return these results in a tuple in the same order.
You must implement this using a function named `calculate_bell_state_properties` with no arguments.
Function to implement: calculate_bell_state_properties
Tests:
from qiskit.quantum_info import DensityMatrix
result = calculate_bell_state_properties()
assert isinstance(result, tuple)
assert len(result) == 2
rho, conc = result
assert isinstance(rho, DensityMatrix)
assert isinstance(conc, (int, float, complex))
Task: Construct a Phi plus Bell state quantum circuit, compute its stabilizer state, and return both the stabilizer state and a dictionary of the stabilizer state measurement probabilities.
You must implement this using a function named `calculate_stabilizer_state_info` with no arguments.
Function to implement: calculate_stabilizer_state_info
Tests:
from qiskit.quantum_info import StabilizerState
stab, probabilities_dict = calculate_stabilizer_state_info()
assert isinstance(stab, StabilizerState)
assert isinstance(probabilities_dict, dict)
assert len(probabilities_dict) > 0
Task: Initialize a CNOTDihedral element from a QuantumCircuit consist of 2-qubits with cx gate on qubit 0 and 1 and t gate on qubit 0 and return.
You must implement this using a function named `initialize_cnot_dihedral` with no arguments.
Function to implement: initialize_cnot_dihedral
Tests:
from qiskit.quantum_info import CNOTDihedral
result = initialize_cnot_dihedral()
assert isinstance(result, CNOTDihedral)
assert result.num_qubits == 2
Task: Create two Quantum Circuits of 2 qubits. First quantum circuit should have a cx gate on qubits 0 and 1 and a T gate on qubit 0. The second one is the same but with an additional X gate on qubit 1. Convert the two quantum circuits into CNOTDihedral elements and return the composed circuit.
You must implement this using a function named `compose_cnot_dihedral` with no arguments.
Function to implement: compose_cnot_dihedral
Tests:
from qiskit.quantum_info import CNOTDihedral
result = compose_cnot_dihedral()
assert isinstance(result, CNOTDihedral)
assert result.num_qubits == 2
Task: Design a Quantum Fourier Transform circuit for n qubits using basic Quantum gates.
You must implement this using a function named `QFT` with the following arguments: n.
Function to implement: QFT
Tests:
from qiskit import QuantumCircuit
result = QFT(3)
assert isinstance(result, QuantumCircuit)
assert result.num_qubits == 3
for gate in result.data:
    op = gate.operation
    assert op.num_qubits <= 2 or op.name == "barrier"
Task: Return an inverse quantum Fourier transform circuit without the swap gates.
You must implement this using a function named `qft_no_swaps` with the following arguments: num_qubits.
Function to implement: qft_no_swaps
Tests:
from qiskit import QuantumCircuit
for num_qubits in [1, 3, 8]:
    response = qft_no_swaps(num_qubits)
    assert isinstance(response, QuantumCircuit)
    assert response.num_qubits == num_qubits
    assert response.count_ops().get("swap", 0) == 0
Task: Create a 2-qubit quantum circuit where you define a custom 1-qubit unitary gate (e.g., U3) and apply it as a controlled gate with qubit 0 as control and qubit 1 as target. Return the final circuit.
You must implement this using a function named `controlled_custom_unitary_circuit` with no arguments.
Function to implement: controlled_custom_unitary_circuit
Tests:
from qiskit import QuantumCircuit
qc = controlled_custom_unitary_circuit()
assert isinstance(qc, QuantumCircuit)
assert qc.num_qubits == 2
assert len(qc.data) > 0
Task: Construct a quantum circuit with a three-qubit controlled-Hadamard gate, using qubit 0 and qubit 1 as the control bits and qubit 2 as the target bit. Return the circuit.
You must implement this using a function named `create_controlled_hgate` with no arguments.
Function to implement: create_controlled_hgate
Tests:
from qiskit import QuantumCircuit
qc = create_controlled_hgate()
assert isinstance(qc, QuantumCircuit)
assert qc.num_qubits == 3
assert len(qc.data) > 0