Qulacs

Qulacs is a very fast simulator across the board for large, noisy or parametric quantum circuits. It can be executed on both CPUs and GPUs, and can be optimized for faster execution. However, as of now, we only provide Qulacs support for CPU execution. Installation of Qulacs for different devices, as well as various tutorials and API documents, can be found via Github repository.

Quantum Circuit Learning (QCL) is a hybrid algorithm that leverages quantum computers to enhance machine learning capabilities [1]. It’s designed to run on Noisy Intermediate-Scale Quantum (NISQ) Computers, which are medium-scale quantum devices that don’t have error correction capabilities. This algorithm combines quantum and classical computing to achieve efficient machine learning results.

Getting Started

Below is a base example for creating and running the Qulacs (CPU & GPU) simulator:

# Import necessary libraries from Qulacs, you have one dependencies
from qulacs import QuantumCircuit, QuantumState
from qulacs.gate import X, H, CNOT, SWAP

# Initialize quantum state and circuit with 4 qubits
nqubits = 4
st = QuantumState(nqubits)          # Create a quantum state with 4 qubits
circuit = QuantumCircuit(nqubits)   # Create a quantum circuit for 4 qubits

# Add gates to the circuit
circuit.add_gate(X(0))              # Apply Pauli-X gate (NOT) on qubit 0
circuit.add_gate(H(2))              # Apply Hadamard gate on qubit 2 (superposition)
circuit.add_gate(SWAP(0, 1))        # Swap the states of qubits 0 and 1

# Define control and target qubits for CNOT gate
control, target = 3, 2
circuit.add_gate(CNOT(control, target))  # Apply CNOT gate with qubit 3 as control and 2 as target

# Add a random unitary gate on a subset of qubits
list_qubits = [1, 2, 3]
circuit.add_random_unitary_gate(list_qubits)  # Apply a random unitary gate on qubits 1, 2, and 3

# Update the quantum state using the circuit
circuit.update_quantum_state(st)    # Apply all gates to update the quantum state

# Calculate the probability of measuring qubit 1 in the zero state
prob_zero = st.get_zero_probability(1)  # Get probability of qubit 1 being in state |0>

# Calculate the marginal probability distribution for the specified qubits
prob_marginal = st.get_marginal_probability([1, 2, 2, 0])  # Get marginal probability for qubits 1, 2, and 0

# Draw the circuit diagram (requires 'matplotlib' library)
circuit.draw(output='mpl')          # Visualize the quantum circuit

Code Insights

  • Import the necessary dependencies.
  • Be aware of the environment. Pay attention to the environment you’re using, and switch between GPU and CPU if needed.
  • Define a quantum state and build the quantum circuit.
    • Adjust the quantum circuit gates that want to be added into the circuit.
    • For random entangling of arbitrary many chosen qubits, add; add_random_unitary_gate
  • update_quantum_state is to simulate the evolution of a quantum state under the operations defined in the quantum circuit.
  • get_zero_probability is to get the probability that the specified qubit will be measured as 0.
  • get_marginal_probability is to get the 0th qubit is 1 and the 3rd qubit is 0. The qubits and the state of the qubits may change with respect to the problem.

Follow up on the GWDG Updates:

  • Qulacs
    • The version of CPU supported Qulacs provided by GWDG: 0.6.10

Key Features

Qulacs is a quantum simulator optimized for high performance that can be used on classical as well as quantum computers. Renowned for its quickness and adaptability, Qulacs enables the simulation of extensive quantum circuits, making it a favored option for researchers and industry experts alike. Its ability to efficiently utilize memory and computing power allows for quick simulation of quantum gates and algorithms, even on devices with restricted resources.

  • Tailored for speed: Qulacs is created to enhance speed on traditional devices, making it one of the speediest quantum simulators around. Efficient simulation of large-scale quantum circuits is made possible by its optimized and parallelized functions.

  • Flexibility in Gate Operations: Qulacs allows users to try out advanced quantum algorithms by offering a range of quantum gates, both standard and custom.

  • Hybrid Classical-Quantum Simulations: Qulacs enables hybrid quantum-classical algorithms like the Variational Quantum Eigensolver (VQE) and Quantum Approximate Optimization Algorithm (QAOA), important for near-term quantum computing applications.

  • GPU Acceleration: Utilizing the power of GPUs, Qulacs speeds up simulation performance, allowing for the running of more intricate circuits in a shorter period of time.

Supplementary Modules

The usage of Qulacs can be seen rather easier since it has one core library. To see the various functions from Qulacs, visit the Qulacs tutorials.

Command
Description
QuantumState(nQubits).get_vectorReturns all the element as an array.
QuantumState(nQubits).get_amplitudeGet a single element.
QuantumState(nQubits).allocate_bufferAllocate a state vector of the same size as the quantum state you already have and without copying the state.
QuantumState(nQubits).set_Haar_random_state()Generate a random Haar-distributed quantum state.
QuantumState(nQubits).set_zero_state()Initialize a quantum state.
QuantumState(nQubits).set_computational_basis(0b101)Initialize the specified value to the calculation base in binary notation.
QuantumState(nQubits).permutate_qubit()Swap indices of a qubit.
QuantumState(nQubits).drop_qubit()Get a projection onto a specified qubit.
QuantumState(nQubits).partial_trace()Obtain the partial trace of a given qubit of a given quantum state as a density matrix.
state = QuantumStateGpu(n)Calculate using GPU.
value = inner_product(state_bra, state_ket)Calculate inner product.
tensor_product_state = tensor_product(state_ket1, state_ket2)Calculate tensor product.

References

[1] K. Mitarai, M. Negoro, M. Kitagawa, and K. Fujii, “Quantum circuit learning”, Phys. Rev. A 98, 032309 (2018), arXiv:https://arxiv.org/abs/1803.00745