grmlarose / mpsim Goto Github PK
View Code? Open in Web Editor NEWPackage for using Matrix Product States (MPS) to simulate quantum circuits.
Package for using Matrix Product States (MPS) to simulate quantum circuits.
Currently only tests for qubit gates.
Could add as an argument to MPS.__init__
or as a new method, e.g.,
class MPS:
...
@staticmethod
def from_wavefunction(wavefunction: np.ndarray, qudit_dimension: int = 2) -> `MPS`:
"""Returns an MPS representation of the input wavefunction.
Args:
wavefunction: Initial wavefunction to write in MPS form.
qudit_dimension: Dimension of qudits. (Default value is 2 for qubits.)
"""
# Reshape the wavefunction to be a tensor with n = log_(qudit_dimension) (len(wavefunction))
# Apply SVD to split all edges
# Put into a list of nodes and return the MPS
Initial signature:
class MPS:
...
def amplitude(bitstring: str) -> np.complex64:
"""Returns the amplitude of the MPS specified by the bitstring."""
Current support only includes qubits. Generalization to d-level systems will involve, minimally:
MPS.__init__
.Tensor contraction + SVD should be largely the same, if not identical.
Move MPSOperation
to core.py
and re-implement MPSOperation.from_gate_operation
in mpsim_cirq
.
Ref. https://arxiv.org/abs/1201.3974 may have the algorithm(s).
Gates can be kept as long as they can be generalized to larger dimensions, but gates requiring qubits should obviously be removed as these don't generalize to all MPS and will fail unless the qudit dimension is two.
Gates that can be generalized:
For non-unitary operations, SVD is required after the gate to orthonormalize the index.
Probably the best option is to add a method which orthonormalizes the index, then call this after the single-qudit gate contraction of the gate is non-unitary.
E.g., |0><0|
and |1><1|
.
An MPO on n qudits is just an MPS on 2n qudits. While this is the most straightforward generalization, it may not be the easiest in the long term. Considerations to evaluate this include
Having a license would help make the software more broadly useful and clarify when people can contribute / use this code.
For example, tensorflow
is not supported because, e.g., mpsim.gates.is_unitary
assumes the node
object has a .conj()
method in the final line
return np.allclose(
gate.conj().T @ gate, np.identity(gate.shape[0]), atol=1e-5
)
which is unique to the numpy
backend. (This also explicitly uses numpy in other locations.)
To add support for different backends:
Potential signature.
class MPS:
...
def expectation_of(operator: tn.Node, tensor_indices: Sequence[int]) -> np.real:
"""Returns the expectation value of the operator acting on the tensor indices."""
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.