code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def parseString(self, string):
"""Parse a document from a string, returning the document node."""
parser = self.getParser()
try:
parser.Parse(string, True)
self._setup_subset(string)
except ParseEscape:
pass
doc = self.document
self.res... | Parse a document from a string, returning the document node. | parseString | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def _setup_subset(self, buffer):
"""Load the internal subset if there might be one."""
if self.document.doctype:
extractor = InternalSubsetExtractor()
extractor.parseString(buffer)
subset = extractor.getSubset()
self.document.doctype.internalSubset = subse... | Load the internal subset if there might be one. | _setup_subset | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def parseString(self, string):
"""Parse a document fragment from a string, returning the
fragment node."""
self._source = string
parser = self.getParser()
doctype = self.originalDocument.doctype
ident = ""
if doctype:
subset = doctype.internalSubset or... | Parse a document fragment from a string, returning the
fragment node. | parseString | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def _getDeclarations(self):
"""Re-create the internal subset from the DocumentType node.
This is only needed if we don't already have the
internalSubset as a string.
"""
doctype = self.context.ownerDocument.doctype
s = ""
if doctype:
for i in range(do... | Re-create the internal subset from the DocumentType node.
This is only needed if we don't already have the
internalSubset as a string.
| _getDeclarations | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def install(self, parser):
"""Insert the namespace-handlers onto the parser."""
ExpatBuilder.install(self, parser)
if self._options.namespace_declarations:
parser.StartNamespaceDeclHandler = (
self.start_namespace_decl_handler) | Insert the namespace-handlers onto the parser. | install | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def _getNSattrs(self):
"""Return string of namespace attributes from this element and
ancestors."""
# XXX This needs to be re-written to walk the ancestors of the
# context to build up the namespace information from
# declarations, elements, and attributes found in context.
... | Return string of namespace attributes from this element and
ancestors. | _getNSattrs | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def parse(file, namespaces=True):
"""Parse a document, returning the resulting Document node.
'file' may be either a file name or an open file object.
"""
if namespaces:
builder = ExpatBuilderNS()
else:
builder = ExpatBuilder()
if isinstance(file, StringTypes):
fp = ope... | Parse a document, returning the resulting Document node.
'file' may be either a file name or an open file object.
| parse | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def parseString(string, namespaces=True):
"""Parse a document from a string, returning the resulting
Document node.
"""
if namespaces:
builder = ExpatBuilderNS()
else:
builder = ExpatBuilder()
return builder.parseString(string) | Parse a document from a string, returning the resulting
Document node.
| parseString | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def parseFragment(file, context, namespaces=True):
"""Parse a fragment of a document, given the context from which it
was originally extracted. context should be the parent of the
node(s) which are in the fragment.
'file' may be either a file name or an open file object.
"""
if namespaces:
... | Parse a fragment of a document, given the context from which it
was originally extracted. context should be the parent of the
node(s) which are in the fragment.
'file' may be either a file name or an open file object.
| parseFragment | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def parseFragmentString(string, context, namespaces=True):
"""Parse a fragment of a document from a string, given the context
from which it was originally extracted. context should be the
parent of the node(s) which are in the fragment.
"""
if namespaces:
builder = FragmentBuilderNS(context... | Parse a fragment of a document from a string, given the context
from which it was originally extracted. context should be the
parent of the node(s) which are in the fragment.
| parseFragmentString | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def makeBuilder(options):
"""Create a builder based on an Options object."""
if options.namespaces:
return ExpatBuilderNS(options)
else:
return ExpatBuilder(options) | Create a builder based on an Options object. | makeBuilder | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/expatbuilder.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/expatbuilder.py | MIT |
def _clone_node(node, deep, newOwnerDocument):
"""
Clone a node and give it the new owner document.
Called by Node.cloneNode and Document.importNode
"""
if node.ownerDocument.isSameNode(newOwnerDocument):
operation = xml.dom.UserDataHandler.NODE_CLONED
else:
operation = xml.dom.U... |
Clone a node and give it the new owner document.
Called by Node.cloneNode and Document.importNode
| _clone_node | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/minidom.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/minidom.py | MIT |
def parse(file, parser=None, bufsize=None):
"""Parse a file into a DOM by filename or file object."""
if parser is None and not bufsize:
from xml.dom import expatbuilder
return expatbuilder.parse(file)
else:
from xml.dom import pulldom
return _do_pulldom_parse(pulldom.parse, ... | Parse a file into a DOM by filename or file object. | parse | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/minidom.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/minidom.py | MIT |
def parseString(string, parser=None):
"""Parse a file into a DOM from a string."""
if parser is None:
from xml.dom import expatbuilder
return expatbuilder.parseString(string)
else:
from xml.dom import pulldom
return _do_pulldom_parse(pulldom.parseString, (string,),
... | Parse a file into a DOM from a string. | parseString | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/minidom.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/minidom.py | MIT |
def _slurp(self):
""" Fallback replacement for getEvent() using the
standard SAX2 interface, which means we slurp the
SAX events into memory (no performance gain, but
we are compatible to all SAX parsers).
"""
self.parser.parse(self.stream)
self.getEve... | Fallback replacement for getEvent() using the
standard SAX2 interface, which means we slurp the
SAX events into memory (no performance gain, but
we are compatible to all SAX parsers).
| _slurp | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/dom/pulldom.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/dom/pulldom.py | MIT |
def doctype(self, name, pubid, system):
"""This method of XMLParser is deprecated."""
warnings.warn(
"This method of XMLParser is deprecated. Define doctype() "
"method on the TreeBuilder target.",
DeprecationWarning,
) | This method of XMLParser is deprecated. | doctype | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/etree/ElementTree.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/etree/ElementTree.py | MIT |
def parse(self, source):
"Parse an XML document from a URL or an InputSource."
source = saxutils.prepare_input_source(source)
self._source = source
self.reset()
self._cont_handler.setDocumentLocator(ExpatLocator(self))
xmlreader.IncrementalParser.parse(self, source) | Parse an XML document from a URL or an InputSource. | parse | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/expatreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/expatreader.py | MIT |
def startDocument(self):
"""Receive notification of the beginning of a document.
The SAX parser will invoke this method only once, before any
other methods in this interface or in DTDHandler (except for
setDocumentLocator).""" | Receive notification of the beginning of a document.
The SAX parser will invoke this method only once, before any
other methods in this interface or in DTDHandler (except for
setDocumentLocator). | startDocument | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def endDocument(self):
"""Receive notification of the end of a document.
The SAX parser will invoke this method only once, and it will
be the last method invoked during the parse. The parser shall
not invoke this method until it has either abandoned parsing
(because of an unreco... | Receive notification of the end of a document.
The SAX parser will invoke this method only once, and it will
be the last method invoked during the parse. The parser shall
not invoke this method until it has either abandoned parsing
(because of an unrecoverable error) or reached the end ... | endDocument | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def startPrefixMapping(self, prefix, uri):
"""Begin the scope of a prefix-URI Namespace mapping.
The information from this event is not necessary for normal
Namespace processing: the SAX XML reader will automatically
replace prefixes for element and attribute names when the
http... | Begin the scope of a prefix-URI Namespace mapping.
The information from this event is not necessary for normal
Namespace processing: the SAX XML reader will automatically
replace prefixes for element and attribute names when the
http://xml.org/sax/features/namespaces feature is true (th... | startPrefixMapping | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def endPrefixMapping(self, prefix):
"""End the scope of a prefix-URI mapping.
See startPrefixMapping for details. This event will always
occur after the corresponding endElement event, but the order
of endPrefixMapping events is not otherwise guaranteed.""" | End the scope of a prefix-URI mapping.
See startPrefixMapping for details. This event will always
occur after the corresponding endElement event, but the order
of endPrefixMapping events is not otherwise guaranteed. | endPrefixMapping | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def startElement(self, name, attrs):
"""Signals the start of an element in non-namespace mode.
The name parameter contains the raw XML 1.0 name of the
element type as a string and the attrs parameter holds an
instance of the Attributes class containing the attributes of
the elem... | Signals the start of an element in non-namespace mode.
The name parameter contains the raw XML 1.0 name of the
element type as a string and the attrs parameter holds an
instance of the Attributes class containing the attributes of
the element. | startElement | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def endElement(self, name):
"""Signals the end of an element in non-namespace mode.
The name parameter contains the name of the element type, just
as with the startElement event.""" | Signals the end of an element in non-namespace mode.
The name parameter contains the name of the element type, just
as with the startElement event. | endElement | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def startElementNS(self, name, qname, attrs):
"""Signals the start of an element in namespace mode.
The name parameter contains the name of the element type as a
(uri, localname) tuple, the qname parameter the raw XML 1.0
name used in the source document, and the attrs parameter
... | Signals the start of an element in namespace mode.
The name parameter contains the name of the element type as a
(uri, localname) tuple, the qname parameter the raw XML 1.0
name used in the source document, and the attrs parameter
holds an instance of the Attributes class containing the... | startElementNS | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def endElementNS(self, name, qname):
"""Signals the end of an element in namespace mode.
The name parameter contains the name of the element type, just
as with the startElementNS event.""" | Signals the end of an element in namespace mode.
The name parameter contains the name of the element type, just
as with the startElementNS event. | endElementNS | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def characters(self, content):
"""Receive notification of character data.
The Parser will call this method to report each chunk of
character data. SAX parsers may return all contiguous
character data in a single chunk, or they may split it into
several chunks; however, all of th... | Receive notification of character data.
The Parser will call this method to report each chunk of
character data. SAX parsers may return all contiguous
character data in a single chunk, or they may split it into
several chunks; however, all of the characters in any single
event m... | characters | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def ignorableWhitespace(self, whitespace):
"""Receive notification of ignorable whitespace in element content.
Validating Parsers must use this method to report each chunk
of ignorable whitespace (see the W3C XML 1.0 recommendation,
section 2.10): non-validating parsers may also use thi... | Receive notification of ignorable whitespace in element content.
Validating Parsers must use this method to report each chunk
of ignorable whitespace (see the W3C XML 1.0 recommendation,
section 2.10): non-validating parsers may also use this method
if they are capable of parsing and us... | ignorableWhitespace | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def processingInstruction(self, target, data):
"""Receive notification of a processing instruction.
The Parser will invoke this method once for each processing
instruction found: note that processing instructions may occur
before or after the main document element.
A SAX parser... | Receive notification of a processing instruction.
The Parser will invoke this method once for each processing
instruction found: note that processing instructions may occur
before or after the main document element.
A SAX parser should never report an XML declaration (XML 1.0,
... | processingInstruction | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def skippedEntity(self, name):
"""Receive notification of a skipped entity.
The Parser will invoke this method once for each entity
skipped. Non-validating processors may skip entities if they
have not seen the declarations (because, for example, the
entity was declared in an ex... | Receive notification of a skipped entity.
The Parser will invoke this method once for each entity
skipped. Non-validating processors may skip entities if they
have not seen the declarations (because, for example, the
entity was declared in an external DTD subset). All processors
... | skippedEntity | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/handler.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/handler.py | MIT |
def __dict_replace(s, d):
"""Replace substrings of a string using a dictionary."""
for key, value in d.items():
s = s.replace(key, value)
return s | Replace substrings of a string using a dictionary. | __dict_replace | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/saxutils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/saxutils.py | MIT |
def escape(data, entities={}):
"""Escape &, <, and > in a string of data.
You can escape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
# must do ampersand f... | Escape &, <, and > in a string of data.
You can escape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
| escape | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/saxutils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/saxutils.py | MIT |
def unescape(data, entities={}):
"""Unescape &, <, and > in a string of data.
You can unescape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
data =... | Unescape &, <, and > in a string of data.
You can unescape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
| unescape | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/saxutils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/saxutils.py | MIT |
def quoteattr(data, entities={}):
"""Escape and quote an attribute value.
Escape &, <, and > in a string of data, then quote it for use as
an attribute value. The \" character will be escaped as well, if
necessary.
You can escape other strings of data by passing a dictionary as
the optional e... | Escape and quote an attribute value.
Escape &, <, and > in a string of data, then quote it for use as
an attribute value. The " character will be escaped as well, if
necessary.
You can escape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values mu... | quoteattr | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/saxutils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/saxutils.py | MIT |
def _qname(self, name):
"""Builds a qualified name from a (ns_url, localname) pair"""
if name[0]:
# Per http://www.w3.org/XML/1998/namespace, The 'xml' prefix is
# bound by definition to http://www.w3.org/XML/1998/namespace. It
# does not need to be declared and will... | Builds a qualified name from a (ns_url, localname) pair | _qname | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/saxutils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/saxutils.py | MIT |
def prepare_input_source(source, base = ""):
"""This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading."""
if type(source) in _StringTypes:
source = xmlreader.InputSource(source)
elif hasattr(source, "read"):
f = sou... | This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading. | prepare_input_source | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/saxutils.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/saxutils.py | MIT |
def parse(self, source):
"Parse an XML document from a system identifier or an InputSource."
raise NotImplementedError("This method must be implemented!") | Parse an XML document from a system identifier or an InputSource. | parse | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def setContentHandler(self, handler):
"Registers a new object to receive document content events."
self._cont_handler = handler | Registers a new object to receive document content events. | setContentHandler | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def setDTDHandler(self, handler):
"Register an object to receive basic DTD-related events."
self._dtd_handler = handler | Register an object to receive basic DTD-related events. | setDTDHandler | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def setEntityResolver(self, resolver):
"Register an object to resolve external entities."
self._ent_handler = resolver | Register an object to resolve external entities. | setEntityResolver | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def setErrorHandler(self, handler):
"Register an object to receive error-message events."
self._err_handler = handler | Register an object to receive error-message events. | setErrorHandler | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def getFeature(self, name):
"Looks up and returns the state of a SAX2 feature."
raise SAXNotRecognizedException("Feature '%s' not recognized" % name) | Looks up and returns the state of a SAX2 feature. | getFeature | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def getProperty(self, name):
"Looks up and returns the value of a SAX2 property."
raise SAXNotRecognizedException("Property '%s' not recognized" % name) | Looks up and returns the value of a SAX2 property. | getProperty | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def setPublicId(self, public_id):
"Sets the public identifier of this InputSource."
self.__public_id = public_id | Sets the public identifier of this InputSource. | setPublicId | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def setSystemId(self, system_id):
"Sets the system identifier of this InputSource."
self.__system_id = system_id | Sets the system identifier of this InputSource. | setSystemId | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def __init__(self, attrs, qnames):
"""NS-aware implementation.
attrs should be of the form {(ns_uri, lname): value, ...}.
qnames of the form {(ns_uri, lname): qname, ...}."""
self._attrs = attrs
self._qnames = qnames | NS-aware implementation.
attrs should be of the form {(ns_uri, lname): value, ...}.
qnames of the form {(ns_uri, lname): qname, ...}. | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/xmlreader.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/xmlreader.py | MIT |
def __init__(self, msg, exception=None):
"""Creates an exception. The message is required, but the exception
is optional."""
self._msg = msg
self._exception = exception
Exception.__init__(self, msg) | Creates an exception. The message is required, but the exception
is optional. | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/_exceptions.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/_exceptions.py | MIT |
def __init__(self, msg, exception, locator):
"Creates the exception. The exception parameter is allowed to be None."
SAXException.__init__(self, msg, exception)
self._locator = locator
# We need to cache this stuff at construction time.
# If this exception is raised, the objects... | Creates the exception. The exception parameter is allowed to be None. | __init__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/_exceptions.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/_exceptions.py | MIT |
def __str__(self):
"Create a string representation of the exception."
sysid = self.getSystemId()
if sysid is None:
sysid = "<unknown>"
linenum = self.getLineNumber()
if linenum is None:
linenum = "?"
colnum = self.getColumnNumber()
if colnu... | Create a string representation of the exception. | __str__ | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/_exceptions.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/_exceptions.py | MIT |
def make_parser(parser_list = []):
"""Creates and returns a SAX parser.
Creates the first parser it is able to instantiate of the ones
given in the list created by doing parser_list +
default_parser_list. The lists must contain the names of Python
modules containing both a SAX parser and a create_... | Creates and returns a SAX parser.
Creates the first parser it is able to instantiate of the ones
given in the list created by doing parser_list +
default_parser_list. The lists must contain the names of Python
modules containing both a SAX parser and a create_parser function. | make_parser | python | mchristopher/PokemonGo-DesktopMap | app/pywin/Lib/xml/sax/__init__.py | https://github.com/mchristopher/PokemonGo-DesktopMap/blob/master/app/pywin/Lib/xml/sax/__init__.py | MIT |
def _find_toml_section_end(lines, start):
"""Find the index of the start of the next section."""
return (
next(filter(itemgetter(1), enumerate(line.startswith('[') for line in lines[start + 1 :])))[0]
+ start
+ 1
) | Find the index of the start of the next section. | _find_toml_section_end | python | ProjectQ-Framework/ProjectQ | setup.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/setup.py | Apache-2.0 |
def _parse_list(lines):
"""Parse a TOML list into a Python list."""
# NB: This function expects the TOML list to be formatted like so (ignoring leading and trailing spaces):
# name = [
# '...',
# ]
# Any other format is not sup... | Parse a TOML list into a Python list. | _parse_list | python | ProjectQ-Framework/ProjectQ | setup.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/setup.py | Apache-2.0 |
def parse_toml(filename):
"""Very simple parser routine for pyproject.toml."""
result = {'project': {'optional-dependencies': {}}}
with open(filename) as toml_file:
lines = [line.strip() for line in toml_file.readlines()]
lines = [line for line in lines if... | Very simple parser routine for pyproject.toml. | parse_toml | python | ProjectQ-Framework/ProjectQ | setup.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/setup.py | Apache-2.0 |
def compiler_test(
compiler,
flagname=None,
link_executable=False,
link_shared_lib=False,
include='',
body='',
compile_postargs=None,
link_postargs=None,
): # pylint: disable=too-many-arguments,too-many-branches
"""Return a boolean indicating whether a flag name is supported on the ... | Return a boolean indicating whether a flag name is supported on the specified compiler. | compiler_test | python | ProjectQ-Framework/ProjectQ | setup.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/setup.py | Apache-2.0 |
def has_ext_modules(self):
"""Return whether this distribution has some external modules."""
# We want to always claim that we have ext_modules. This will be fine
# if we don't actually have them (such as on PyPy) because nothing
# will get built, however we don't want to provide an over... | Return whether this distribution has some external modules. | has_ext_modules | python | ProjectQ-Framework/ProjectQ | setup.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/setup.py | Apache-2.0 |
def recursive_getattr(obj, attr, *args):
"""Recursively get the attributes of a Python object."""
def _getattr(obj, attr):
return getattr(obj, attr, *args)
return functools.reduce(_getattr, [obj] + attr.split('.')) | Recursively get the attributes of a Python object. | recursive_getattr | python | ProjectQ-Framework/ProjectQ | docs/conf.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/docs/conf.py | Apache-2.0 |
def linkcode_resolve(domain, info):
"""Change URLs in documentation on the fly."""
# Copyright 2018 ProjectQ (www.projectq.ch), all rights reserved.
on_rtd = os.environ.get('READTHEDOCS') == 'True'
github_url = "https://github.com/ProjectQ-Framework/ProjectQ/tree/"
github_tag = 'v' + version
if ... | Change URLs in documentation on the fly. | linkcode_resolve | python | ProjectQ-Framework/ProjectQ | docs/conf.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/docs/conf.py | Apache-2.0 |
def __init__( # pylint: disable=too-many-arguments
self,
pkg_name,
desc='',
module_special_members='__init__',
submodule_special_members='',
submodules_desc='',
helper_submodules=None,
):
"""
Initialize a PackageDescription object.
Ar... |
Initialize a PackageDescription object.
Args:
name (str): Name of ProjectQ module
desc (str): (optional) Description of module
module_special_members (str): (optional) Special members to include in the documentation of the module
submodule_special_member... | __init__ | python | ProjectQ-Framework/ProjectQ | docs/package_description.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/docs/package_description.py | Apache-2.0 |
def run_entangle(eng, num_qubits=3):
"""
Run an entangling operation on the provided compiler engine.
Args:
eng (MainEngine): Main compiler engine to use.
num_qubits (int): Number of qubits to entangle.
Returns:
measurement (list<int>): List of measurement outcomes.
"""
... |
Run an entangling operation on the provided compiler engine.
Args:
eng (MainEngine): Main compiler engine to use.
num_qubits (int): Number of qubits to entangle.
Returns:
measurement (list<int>): List of measurement outcomes.
| run_entangle | python | ProjectQ-Framework/ProjectQ | examples/aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/aqt.py | Apache-2.0 |
def zoo_profile():
"""Generate and display the zoo of quantum gates."""
# create a main compiler engine with a drawing backend
drawing_engine = CircuitDrawer()
locations = {0: 1, 1: 2, 2: 0, 3: 3}
drawing_engine.set_qubit_locations(locations)
main_eng = MainEngine(drawing_engine)
qureg = mai... | Generate and display the zoo of quantum gates. | zoo_profile | python | ProjectQ-Framework/ProjectQ | examples/gate_zoo.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/gate_zoo.py | Apache-2.0 |
def openfile(filename):
"""
Open a file.
Args:
filename (str): the target file.
Return:
bool: succeed if True.
"""
platform = sys.platform
if platform == "linux" or platform == "linux2":
os.system('xdg-open %s' % filename)
elif platform == "darwin":
os.s... |
Open a file.
Args:
filename (str): the target file.
Return:
bool: succeed if True.
| openfile | python | ProjectQ-Framework/ProjectQ | examples/gate_zoo.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/gate_zoo.py | Apache-2.0 |
def run_grover(eng, n, oracle):
"""
Run Grover's algorithm on n qubit using the provided quantum oracle.
Args:
eng (MainEngine): Main compiler engine to run Grover on.
n (int): Number of bits in the solution.
oracle (function): Function accepting the engine, an n-qubit register,
... |
Run Grover's algorithm on n qubit using the provided quantum oracle.
Args:
eng (MainEngine): Main compiler engine to run Grover on.
n (int): Number of bits in the solution.
oracle (function): Function accepting the engine, an n-qubit register,
and an output qubit which is f... | run_grover | python | ProjectQ-Framework/ProjectQ | examples/grover.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/grover.py | Apache-2.0 |
def alternating_bits_oracle(eng, qubits, output):
"""
Alternating bit oracle.
Mark the solution string 1,0,1,0,...,0,1 by flipping the output qubit, conditioned on qubits being equal to the
alternating bit-string.
Args:
eng (MainEngine): Main compiler engine the algorithm is being run on.
... |
Alternating bit oracle.
Mark the solution string 1,0,1,0,...,0,1 by flipping the output qubit, conditioned on qubits being equal to the
alternating bit-string.
Args:
eng (MainEngine): Main compiler engine the algorithm is being run on.
qubits (Qureg): n-qubit quantum register Grover s... | alternating_bits_oracle | python | ProjectQ-Framework/ProjectQ | examples/grover.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/grover.py | Apache-2.0 |
def run_entangle(eng, num_qubits=3):
"""
Run an entangling operation on the provided compiler engine.
Args:
eng (MainEngine): Main compiler engine to use.
num_qubits (int): Number of qubits to entangle.
Returns:
measurement (list<int>): List of measurement outcomes.
"""
... |
Run an entangling operation on the provided compiler engine.
Args:
eng (MainEngine): Main compiler engine to use.
num_qubits (int): Number of qubits to entangle.
Returns:
measurement (list<int>): List of measurement outcomes.
| run_entangle | python | ProjectQ-Framework/ProjectQ | examples/ibm.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/ibm.py | Apache-2.0 |
def run_entangle(eng, num_qubits=3):
"""
Run an entangling operation on the provided compiler engine.
Args:
eng (MainEngine): Main compiler engine to use.
num_qubits (int): Number of qubits to entangle.
Returns:
measurement (list<int>): List of measurement outcomes.
"""
... |
Run an entangling operation on the provided compiler engine.
Args:
eng (MainEngine): Main compiler engine to use.
num_qubits (int): Number of qubits to entangle.
Returns:
measurement (list<int>): List of measurement outcomes.
| run_entangle | python | ProjectQ-Framework/ProjectQ | examples/ionq.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/ionq.py | Apache-2.0 |
def run_shor(eng, N, a, verbose=False):
"""
Run the quantum subroutine of Shor's algorithm for factoring.
Args:
eng (MainEngine): Main compiler engine to use.
N (int): Number to factor.
a (int): Relative prime to use as a base for a^x mod N.
verbose (bool): If True, display ... |
Run the quantum subroutine of Shor's algorithm for factoring.
Args:
eng (MainEngine): Main compiler engine to use.
N (int): Number to factor.
a (int): Relative prime to use as a base for a^x mod N.
verbose (bool): If True, display intermediate measurement results.
Returns:... | run_shor | python | ProjectQ-Framework/ProjectQ | examples/shor.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/shor.py | Apache-2.0 |
def create_bell_pair(eng):
r"""
Create a Bell pair state with two qubits.
Returns a Bell-pair (two qubits in state :math:`|A\rangle \otimes |B \rangle = \frac 1{\sqrt 2} \left(
|0\rangle\otimes|0\rangle + |1\rangle \otimes|1\rangle \right)`).
Args:
eng (MainEngine): MainEngine from which t... |
Create a Bell pair state with two qubits.
Returns a Bell-pair (two qubits in state :math:`|A\rangle \otimes |B \rangle = \frac 1{\sqrt 2} \left(
|0\rangle\otimes|0\rangle + |1\rangle \otimes|1\rangle \right)`).
Args:
eng (MainEngine): MainEngine from which to allocate the qubits.
Returns... | create_bell_pair | python | ProjectQ-Framework/ProjectQ | examples/teleport.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/teleport.py | Apache-2.0 |
def run_teleport(eng, state_creation_function, verbose=False):
"""
Run quantum teleportation on the provided main compiler engine.
Creates a state from |0> using the state_creation_function, teleports this state to Bob who then tries to
uncompute his qubit using the inverse of the state_creation_functi... |
Run quantum teleportation on the provided main compiler engine.
Creates a state from |0> using the state_creation_function, teleports this state to Bob who then tries to
uncompute his qubit using the inverse of the state_creation_function. If successful, deleting the qubit won't
raise an error in the ... | run_teleport | python | ProjectQ-Framework/ProjectQ | examples/teleport.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/teleport.py | Apache-2.0 |
def run_circuit(eng, n_qubits, circuit_num, gate_after_measure=False):
"""Run a quantum circuit demonstrating the capabilities of the UnitarySimulator."""
qureg = eng.allocate_qureg(n_qubits)
if circuit_num == 1:
All(X) | qureg
elif circuit_num == 2:
X | qureg[0]
with Control(en... | Run a quantum circuit demonstrating the capabilities of the UnitarySimulator. | run_circuit | python | ProjectQ-Framework/ProjectQ | examples/unitary_simulator.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/unitary_simulator.py | Apache-2.0 |
def main():
"""Definition of the main function of this example."""
# Create a MainEngine with a unitary simulator backend
eng = MainEngine(backend=UnitarySimulator())
n_qubits = 3
# Run out quantum circuit
# 1 - circuit applying X on all qubits
# 2 - circuit applying an X gate followed... | Definition of the main function of this example. | main | python | ProjectQ-Framework/ProjectQ | examples/unitary_simulator.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/examples/unitary_simulator.py | Apache-2.0 |
def __init__(self, accept_input=True, default_measure=False, in_place=False):
"""
Initialize a CommandPrinter.
Args:
accept_input (bool): If accept_input is true, the printer queries the user to input measurement results if
the CommandPrinter is the last engine. Othe... |
Initialize a CommandPrinter.
Args:
accept_input (bool): If accept_input is true, the printer queries the user to input measurement results if
the CommandPrinter is the last engine. Otherwise, all measurements yield default_measure.
default_measure (bool): Defaul... | __init__ | python | ProjectQ-Framework/ProjectQ | projectq/backends/_printer.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_printer.py | Apache-2.0 |
def is_available(self, cmd):
"""
Test whether a Command is supported by a compiler engine.
Specialized implementation of is_available: Returns True if the CommandPrinter is the last engine (since it
can print any command).
Args:
cmd (Command): Command of which to ch... |
Test whether a Command is supported by a compiler engine.
Specialized implementation of is_available: Returns True if the CommandPrinter is the last engine (since it
can print any command).
Args:
cmd (Command): Command of which to check availability (all Commands can be pr... | is_available | python | ProjectQ-Framework/ProjectQ | projectq/backends/_printer.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_printer.py | Apache-2.0 |
def _print_cmd(self, cmd):
"""
Print a command.
Print a command or, if the command is a measurement instruction and the CommandPrinter is the last engine in
the engine pipeline: Query the user for the measurement result (if accept_input = True) / Set the result to 0
(if it's Fal... |
Print a command.
Print a command or, if the command is a measurement instruction and the CommandPrinter is the last engine in
the engine pipeline: Query the user for the measurement result (if accept_input = True) / Set the result to 0
(if it's False).
Args:
cmd (C... | _print_cmd | python | ProjectQ-Framework/ProjectQ | projectq/backends/_printer.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_printer.py | Apache-2.0 |
def receive(self, command_list):
"""
Receive a list of commands.
Receive a list of commands from the previous engine, print the
commands, and then send them on to the next engine.
Args:
command_list (list<Command>): List of Commands to print (and
pot... |
Receive a list of commands.
Receive a list of commands from the previous engine, print the
commands, and then send them on to the next engine.
Args:
command_list (list<Command>): List of Commands to print (and
potentially send on to the next engine).
... | receive | python | ProjectQ-Framework/ProjectQ | projectq/backends/_printer.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_printer.py | Apache-2.0 |
def __init__(self):
"""
Initialize a resource counter engine.
Sets all statistics to zero.
"""
super().__init__()
self.gate_counts = {}
self.gate_class_counts = {}
self._active_qubits = 0
self.max_width = 0
# key: qubit id, depth of this q... |
Initialize a resource counter engine.
Sets all statistics to zero.
| __init__ | python | ProjectQ-Framework/ProjectQ | projectq/backends/_resource.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_resource.py | Apache-2.0 |
def is_available(self, cmd):
"""
Test whether a Command is supported by a compiler engine.
Specialized implementation of is_available: Returns True if the ResourceCounter is the last engine (since it
can count any command).
Args:
cmd (Command): Command for which to ... |
Test whether a Command is supported by a compiler engine.
Specialized implementation of is_available: Returns True if the ResourceCounter is the last engine (since it
can count any command).
Args:
cmd (Command): Command for which to check availability (all Commands can be ... | is_available | python | ProjectQ-Framework/ProjectQ | projectq/backends/_resource.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_resource.py | Apache-2.0 |
def depth_of_dag(self):
"""Return the depth of the DAG."""
if self._depth_of_qubit:
current_max = max(self._depth_of_qubit.values())
return max(current_max, self._previous_max_depth)
return self._previous_max_depth | Return the depth of the DAG. | depth_of_dag | python | ProjectQ-Framework/ProjectQ | projectq/backends/_resource.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_resource.py | Apache-2.0 |
def __str__(self):
"""
Return the string representation of this ResourceCounter.
Returns:
A summary (string) of resources used, including gates, number of calls, and max. number of qubits that
were active at the same time.
"""
if len(self.gate_counts)... |
Return the string representation of this ResourceCounter.
Returns:
A summary (string) of resources used, including gates, number of calls, and max. number of qubits that
were active at the same time.
| __str__ | python | ProjectQ-Framework/ProjectQ | projectq/backends/_resource.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_resource.py | Apache-2.0 |
def receive(self, command_list):
"""
Receive a list of commands.
Receive a list of commands from the previous engine, increases the counters of the received commands, and then
send them on to the next engine.
Args:
command_list (list<Command>): List of commands to r... |
Receive a list of commands.
Receive a list of commands from the previous engine, increases the counters of the received commands, and then
send them on to the next engine.
Args:
command_list (list<Command>): List of commands to receive (and count).
| receive | python | ProjectQ-Framework/ProjectQ | projectq/backends/_resource.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_resource.py | Apache-2.0 |
def _qidmask(target_ids, control_ids, n_qubits):
"""
Calculate index masks.
Args:
target_ids (list): list of target qubit indices
control_ids (list): list of control qubit indices
control_state (list): list of states for the control qubits (0 or 1)
n_qubits (int): number of ... |
Calculate index masks.
Args:
target_ids (list): list of target qubit indices
control_ids (list): list of control qubit indices
control_state (list): list of states for the control qubits (0 or 1)
n_qubits (int): number of qubits
| _qidmask | python | ProjectQ-Framework/ProjectQ | projectq/backends/_unitary.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_unitary.py | Apache-2.0 |
def is_available(self, cmd):
"""
Test whether a Command is supported by a compiler engine.
Specialized implementation of is_available: The unitary simulator can deal with all arbitrarily-controlled gates
which provide a gate-matrix (via gate.matrix).
Args:
cmd (Comm... |
Test whether a Command is supported by a compiler engine.
Specialized implementation of is_available: The unitary simulator can deal with all arbitrarily-controlled gates
which provide a gate-matrix (via gate.matrix).
Args:
cmd (Command): Command for which to check availab... | is_available | python | ProjectQ-Framework/ProjectQ | projectq/backends/_unitary.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_unitary.py | Apache-2.0 |
def receive(self, command_list):
"""
Receive a list of commands.
Receive a list of commands from the previous engine and handle them:
* update the unitary of the quantum circuit
* update the internal quantum state if a measurement or a qubit deallocation occurs
... |
Receive a list of commands.
Receive a list of commands from the previous engine and handle them:
* update the unitary of the quantum circuit
* update the internal quantum state if a measurement or a qubit deallocation occurs
prior to sending them on to the next engine.... | receive | python | ProjectQ-Framework/ProjectQ | projectq/backends/_unitary.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_unitary.py | Apache-2.0 |
def _handle(self, cmd):
"""
Handle all commands.
Args:
cmd (Command): Command to handle.
Raises:
RuntimeError: If a measurement is performed before flush gate.
"""
if isinstance(cmd.gate, AllocateQubitGate):
self._qubit_map[cmd.qubits... |
Handle all commands.
Args:
cmd (Command): Command to handle.
Raises:
RuntimeError: If a measurement is performed before flush gate.
| _handle | python | ProjectQ-Framework/ProjectQ | projectq/backends/_unitary.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_unitary.py | Apache-2.0 |
def measure_qubits(self, ids):
"""
Measure the qubits with IDs ids and return a list of measurement outcomes (True/False).
Args:
ids (list<int>): List of qubit IDs to measure.
Returns:
List of measurement results (containing either True or False).
"""
... |
Measure the qubits with IDs ids and return a list of measurement outcomes (True/False).
Args:
ids (list<int>): List of qubit IDs to measure.
Returns:
List of measurement results (containing either True or False).
| measure_qubits | python | ProjectQ-Framework/ProjectQ | projectq/backends/_unitary.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_unitary.py | Apache-2.0 |
def __init__(
self,
use_hardware=False,
num_runs=100,
verbose=False,
token='',
device='simulator',
num_retries=3000,
interval=1,
retrieve_execution=None,
): # pylint: disable=too-many-arguments
"""
Initialize the Backend object... |
Initialize the Backend object.
Args:
use_hardware (bool): If True, the code is run on the AQT quantum chip (instead of using the AQT simulator)
num_runs (int): Number of runs to collect statistics. (default is 100, max is usually around 200)
verbose (bool): If True... | __init__ | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py | Apache-2.0 |
def is_available(self, cmd):
"""
Return true if the command can be executed.
The AQT ion trap can only do Rx,Ry and Rxx.
Args:
cmd (Command): Command for which to check availability
"""
if get_control_count(cmd) == 0:
if isinstance(cmd.gate, (Rx,... |
Return true if the command can be executed.
The AQT ion trap can only do Rx,Ry and Rxx.
Args:
cmd (Command): Command for which to check availability
| is_available | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py | Apache-2.0 |
def _reset(self):
"""Reset all temporary variables (after flush gate)."""
self._clear = True
self._measured_ids = [] | Reset all temporary variables (after flush gate). | _reset | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py | Apache-2.0 |
def _store(self, cmd):
"""
Temporarily store the command cmd.
Translates the command and stores it in a local variable (self._cmds).
Args:
cmd: Command to store
"""
if self._clear:
self._probabilities = {}
self._clear = False
... |
Temporarily store the command cmd.
Translates the command and stores it in a local variable (self._cmds).
Args:
cmd: Command to store
| _store | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py | Apache-2.0 |
def _logical_to_physical(self, qb_id):
"""
Return the physical location of the qubit with the given logical id.
If no mapper is present then simply returns the qubit ID.
Args:
qb_id (int): ID of the logical qubit whose position should be returned.
"""
try:
... |
Return the physical location of the qubit with the given logical id.
If no mapper is present then simply returns the qubit ID.
Args:
qb_id (int): ID of the logical qubit whose position should be returned.
| _logical_to_physical | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py | Apache-2.0 |
def get_probabilities(self, qureg):
"""
Return the probability of the outcome `bit_string` when measuring the quantum register `qureg`.
Return the list of basis states with corresponding probabilities. If input qureg is a subset of the register
used for the experiment, then returns the... |
Return the probability of the outcome `bit_string` when measuring the quantum register `qureg`.
Return the list of basis states with corresponding probabilities. If input qureg is a subset of the register
used for the experiment, then returns the projected probabilities over the other states.... | get_probabilities | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py | Apache-2.0 |
def _run(self):
"""
Run the circuit.
Send the circuit via the AQT API using the provided user token / ask for the user token.
"""
# finally: measurements
# NOTE AQT DOESN'T SEEM TO HAVE MEASUREMENT INSTRUCTIONS (no
# intermediate measurements are allowed, so impl... |
Run the circuit.
Send the circuit via the AQT API using the provided user token / ask for the user token.
| _run | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py | Apache-2.0 |
def receive(self, command_list):
"""
Receive a list of commands.
Receive a command list and, for each command, stores it until completion. Upon flush, send the data to the
AQT API.
Args:
command_list: List of commands to execute
"""
for cmd in comman... |
Receive a list of commands.
Receive a command list and, for each command, stores it until completion. Upon flush, send the data to the
AQT API.
Args:
command_list: List of commands to execute
| receive | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt.py | Apache-2.0 |
def __init__(self):
"""Initialize an AQT session with AQT's APIs."""
super().__init__()
self.backends = {}
self.timeout = 5.0
self.token = None | Initialize an AQT session with AQT's APIs. | __init__ | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt_http_client.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py | Apache-2.0 |
def update_devices_list(self, verbose=False):
"""
Update the internal device list.
Returns:
(list): list of available devices
Note:
Up to my knowledge there is no proper API call for online devices, so we just assume that the list from
AQT portal alw... |
Update the internal device list.
Returns:
(list): list of available devices
Note:
Up to my knowledge there is no proper API call for online devices, so we just assume that the list from
AQT portal always up to date
| update_devices_list | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt_http_client.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py | Apache-2.0 |
def can_run_experiment(self, info, device):
"""
Check if the device is big enough to run the code.
Args:
info (dict): dictionary sent by the backend containing the code to
run
device (str): name of the aqt device to use
Returns:
(bool)... |
Check if the device is big enough to run the code.
Args:
info (dict): dictionary sent by the backend containing the code to
run
device (str): name of the aqt device to use
Returns:
(bool): True if device is big enough, False otherwise
... | can_run_experiment | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt_http_client.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py | Apache-2.0 |
def authenticate(self, token=None):
"""
Authenticate with the AQT Web API.
Args:
token (str): AQT user API token.
"""
if token is None:
token = getpass.getpass(prompt='AQT token > ')
self.headers.update({'Ocp-Apim-Subscription-Key': token, 'SDK': ... |
Authenticate with the AQT Web API.
Args:
token (str): AQT user API token.
| authenticate | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt_http_client.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py | Apache-2.0 |
def get_result( # pylint: disable=too-many-arguments
self, device, execution_id, num_retries=3000, interval=1, verbose=False
):
"""Get the result of an execution."""
if verbose:
print(f"Waiting for results. [Job ID: {execution_id}]")
original_sigint_handler = signal.get... | Get the result of an execution. | get_result | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt_http_client.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py | Apache-2.0 |
def show_devices(verbose=False):
"""
Access the list of available devices and their properties (ex: for setup configuration).
Args:
verbose (bool): If True, additional information is printed
Returns:
(list) list of available devices and their properties
"""
aqt_session = AQT()
... |
Access the list of available devices and their properties (ex: for setup configuration).
Args:
verbose (bool): If True, additional information is printed
Returns:
(list) list of available devices and their properties
| show_devices | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt_http_client.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py | Apache-2.0 |
def retrieve(device, token, jobid, num_retries=3000, interval=1, verbose=False): # pylint: disable=too-many-arguments
"""
Retrieve a previously run job by its ID.
Args:
device (str): Device on which the code was run / is running.
token (str): AQT user API token.
jobid (str): Id of ... |
Retrieve a previously run job by its ID.
Args:
device (str): Device on which the code was run / is running.
token (str): AQT user API token.
jobid (str): Id of the job to retrieve
Returns:
(list) samples form the AQT server
| retrieve | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt_http_client.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py | Apache-2.0 |
def send(
info,
device='aqt_simulator',
token=None,
num_retries=100,
interval=1,
verbose=False,
): # pylint: disable=too-many-arguments
"""
Send circuit through the AQT API and runs the quantum circuit.
Args:
info(dict): Contains representation of the circuit to run.
... |
Send circuit through the AQT API and runs the quantum circuit.
Args:
info(dict): Contains representation of the circuit to run.
device (str): name of the aqt device. Simulator chosen by default
token (str): AQT user API token.
verbose (bool): If True, additional information is ... | send | python | ProjectQ-Framework/ProjectQ | projectq/backends/_aqt/_aqt_http_client.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_aqt/_aqt_http_client.py | Apache-2.0 |
def __init__(
self,
use_hardware=False,
num_runs=1000,
verbose=False,
credentials=None,
s3_folder=None,
device='Aspen-8',
num_retries=30,
interval=1,
retrieve_execution=None,
): # pylint: disable=too-many-arguments
"""
... |
Initialize the Backend object.
Args:
use_hardware (bool): If True, the code is run on one of the AWS Braket backends, by default on the Rigetti
Aspen-8 chip (instead of using the AWS Braket SV1 Simulator)
num_runs (int): Number of runs to collect statistics. (d... | __init__ | python | ProjectQ-Framework/ProjectQ | projectq/backends/_awsbraket/_awsbraket.py | https://github.com/ProjectQ-Framework/ProjectQ/blob/master/projectq/backends/_awsbraket/_awsbraket.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.