cuquantum.CircuitToEinsum

class cuquantum.CircuitToEinsum(circuit, dtype='complex128', backend='cupy')

Create a converter object that can generate Einstein summation expressions and tensor operands for a given circuit.

The supported circuit types include cirq.Circuit and qiskit.QuantumCircuit. The input circuit must be fully parameterized and can not contain operations that are not well-defined in tensor network simulation, for instance, resetting the quantum state or performing any intermediate measurement.

Parameters
  • circuit – A fully parameterized cirq.Circuit or qiskit.QuantumCircuit object.

  • dtype – The datatype for the output tensor operands. If not specified, double complex is used.

  • backend – The backend for the output tensor operands. If not specified, cupy is used.

Notes

  • For qiskit.QuantumCircuit, composite gates will be decomposed into either Qiskit standard gates or customized unitary gates.

Examples

Examples using Qiskit:

>>> import qiskit.circuit.random
>>> from cuquantum import contract, CircuitToEinsum

Generate a random quantum circuit:

>>> qc = qiskit.circuit.random.random_circuit(num_qubits=8, depth=7)

Create a CircuitToEinsum object:

>>> converter = CircuitToEinsum(qc, backend='cupy')

Find the Einstein summation expression and tensor operands for the state vector:

>>> expression, operands = converter.state_vector()

Contract the equation above to compute the state vector:

>>> sv = contract(expression, *operands)
>>> print(sv.shape)
(2, 2, 2, 2, 2, 2, 2, 2)

Find the Einstein summation expression and tensor operands for computing the probability amplitude of bitstring 00000000:

>>> expression, operands = converter.amplitude('00000000')

Contract the equation above to compute the amplitude:

>>> amplitude = contract(expression, *operands)

Find the Einstein summation expression and tensor operands for computing reduced density matrix on the first two qubits with the condition that the last qubit is fixed at state 1:

>>> where = qc.qubits[:2]
>>> fixed = {qc.qubits[-1]: '1'}
>>> expression, operands = converter.reduced_density_matrix(where, fixed=fixed)

Contract the equation above to compute the reduced density matrix:

>>> rdm = contract(expression, *operands)
>>> print(rdm.shape)
(2, 2, 2, 2)

Methods

__init__(circuit, dtype='complex128', backend='cupy')
amplitude(bitstring)

Generate the Einstein summation expression and tensor operands to compute the probability amplitude of a bitstring for the input circuit.

Parameters

bitstring – A sequence of 0/1 specifying the desired measured state. The order of the bitstring is expected to be consistent with CircuitToEinsum.qubits. For cirq.Circuit, this order corresponds to all qubits in the circuit sorted in ascending order. For qiskit.QuantumCircuit, this order is the same as qiskit.QuantumCircuit.qubits.

Returns

The Einstein summation expression and a list of tensor operands

reduced_density_matrix(where, fixed=None, lightcone=True)

Generate the Einstein summation expression and tensor operands to compute the reduced density matrix for the input circuit.

Unitary reverse lightcone cancellation refers to removing the identity formed by a unitary gate (from the ket state) and its inverse (from the bra state) when there exists no additional operators in-between. One can take advantage of this technique to reduce the effective network size by only including the causal gates (gates residing in the lightcone).

Parameters
  • where – A sequence of qubits specifying where the density matrix are reduced onto.

  • fixed – Optional, a dictionary that maps certain qubits to the corresponding fixed states 0 or 1.

  • lightcone – Whether to apply the unitary reverse lightcone cancellation technique to reduce the number of tensors in density matrix computation.

Returns

The Einstein summation expression and a list of tensor operands. The mode labels for output of the expression has the same order as the where argument. For example, if where = (\(a, b\)), the mode labels for the reduced density matrix would be (\(a, b, a^{\prime}, b^{\prime}\))

state_vector(fixed=None)

Generate the Einstein summation expression and tensor operands to compute the statevector for the input circuit.

Parameters

fixed – Optional, a dictionary that maps certain qubits to the corresponding fixed states 0 or 1.

Returns

The Einstein summation expression and a list of tensor operands. The order of the output mode labels is consistent with CircuitToEinsum.qubits. For cirq.Circuit, this order corresponds to all qubits in the circuit sorted in ascending order. For qiskit.QuantumCircuit, this order is the same as qiskit.QuantumCircuit.qubits.

Attributes

qubits

A sequence of all qubits in the circuit.