Coder Social home page Coder Social logo

Comments (2)

jakelishman avatar jakelishman commented on June 10, 2024 1

I think there's probably two parts to the solution here:

  • PauliEvolutionGate absolutely should not be producing by default labels that use that many characters. It's not helpful to anybody, and I imagine it's slow to make as well - I agree we should definitely change that to something more sensible, arguably avoiding eagerly serialising the inner SparsePauliOp into a less efficient representation when the gate is created, even if we do partially truncate it - it seems very wasteful and prone to this sort of explosion. I don't use the gate, though, so I don't know what might be more useful.
  • QPY should have an escape mechanism to avoid hard crashing - maybe we just emit a warning on too-long labels and truncate them at the maximum length. We could consider introducing a new QPY format version to support arbitrary-length labels in some form or another too, if it's necessary.

from qiskit.

Lancelot03 avatar Lancelot03 commented on June 10, 2024

hi, @garrison as by your suggestion we can implement the truncate function like this

def serialize(self):
        label = self._get_full_label()
        truncated_label = self._truncate_label(label)
            return truncated_label
    
def _truncate_label(self, label, max_length=65536):
        if len(label) <= max_length:
            return label
        else:
            index = max_length - 1
            while index >= 0 and label[index] != '+':
                index -= 1
            if index < 0:
                raise ValueError("Cannot truncate label without breaking terms")
            return label[:index] + ' {...}'

we can do some modification in the code according to the types of input.

from qiskit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.