Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style warning cleanup #826

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions benchmarking/quil-rewiring/0019q-0000024-anthony.quil
Original file line number Diff line number Diff line change
Expand Up @@ -70,73 +70,73 @@ DEFGATE foo11:
-0.050174486902593782-0.11288632606699173i, -0.023857573808631804+0.03121846306974415i, 0.99153928915857925+0.00084410838218316206i, 0.0033477097430969992+0.0057741113689640947i
-0.14239100921332956-0.034981767365271921i, -0.13522832255359934-0.41610569735083602i, -0.0032552718128886658+0.0058267253281272411i, 0.86947316011387743-0.17618825777471114i

DEFGATE foo0:
DEFGATE bar0:
0.86700715251227878+0.010147781213455363i, -0.3654643630125104-0.084698132785995736i, 0.1584221303508366-0.28496855448433311i, -0.024561091572465093-0.023446749250193914i
0.099800369620845708-0.095024894170119084i, 0.75851391789077305+0.013775194974669547i, 0.35434415665853275-0.49900425139913868i, 0.16373723163001502+0.06404787886086942i
-0.29890302131318097-0.37354161847068795i, -0.32254524961945391-0.3857219933829435i, 0.71786655226531748+0.0099231766833925775i, -0.010694235415613242-0.052550222843061475i
-0.0012259317951535459+0.018108449737048091i, -0.090995809562085805+0.15043860691517461i, 0.017046662949014253+0.058385634219982566i, 0.78973196267775581-0.58427949258474698i

DEFGATE foo1:
DEFGATE bar1:
0.88834823297484011-0.0011277593550825429i, 0.0094099721441700222+0.39835178307220048i, 0.12855160442725719-0.14960915308528336i, 0.01868873784594869-0.11316259040322728i
-0.016474428845686669+0.38195646929142008i, 0.76214365336445944-0.0011126655476778149i, 0.10944106445424681+0.048657810402398249i, -0.4993829359436015-0.096153089178707532i
-0.13621468082000029-0.1834426201955873i, -0.040432233953783599-0.0099811896257192816i, 0.97253599613900876-0.0011378280379065586i, 0.014987799970066095+0.0027899013180065191i
0.016784577274091519+0.11039310522206632i, 0.49932361778674494-0.096460655142998147i, 0.029799915627809665+0.0055734908347795176i, 0.85321967156007084+1.7501864432547269e-05i

DEFGATE foo2:
DEFGATE bar2:
0.74544408555152364-0.47884168948402739i, 0.099252957243133488+0.13837051815288612i, -0.20880903539020312-0.37739235372797714i, 0.0+0.0i
0.074696045199053901+0.22789134504481059i, 0.948687011620994+0.022992976197000459i, -0.10624403321669371+0.17510716181347352i, 0.0+0.0i
-0.3926349479307088-0.057858318996258429i, 0.23241407396774721-0.12825921188570058i, 0.26851948130440834-0.83661267832525832i, 0.0+0.0i
0.0+0.0i, 0.0+0.0i, 0.0+0.0i, 1.0+0.0i

DEFGATE foo3:
DEFGATE bar3:
0.73542668757842666+0.4676810552756222i, -0.30744057961497684+0.30131726252704982i, 0.14296546538082971-0.10197082815898108i, 0.15552394375805748+0.0092381748127213226i
0.1962995467196878+0.38311654969269227i, 0.42360727747207849-0.18410463662194362i, -0.57897055534074615-0.048480716018802758i, -0.36430747970459065-0.3620405101783899i
0.1202556898033158+0.12796774264209856i, 0.54515791574010719-0.20089830930888897i, 0.76701214129269857+0.019914664825719894i, -0.17170986365602336-0.11583197353686467i
0.15256625172561705+0.03156865201945537i, 0.30057061712358668-0.41647397865999475i, -0.15870476817619489+0.13309440231788597i, 0.8119917639905686+0.098497411673606122i

DEFGATE foo4:
DEFGATE bar4:
0.86827397985190569-0.0066692684325322443i, 0.052660996715569217+0.094104201953826072i, 0.38495001949463198-0.27034025043018201i, -0.043112331682506888+0.10629202094037796i
-0.008423186871706-0.042242238910771675i, 0.30517136446282694+0.05660391125189207i, 0.25843852600491868+0.044758010215022334i, 0.5323661010420816-0.74135258951248229i
-0.3536617202049826-0.30431702560847557i, -0.15438979368007225+0.47525913440307899i, 0.68850857693631984+0.053281948158788284i, -0.22310996417872933+0.07711030884400509i
-0.15225990286612961+0.057722764236446927i, -0.54902832988365469-0.58386479077048836i, 0.34760998530540321-0.3349927639336871i, 0.30907220561753862+0.050757477228038125i

DEFGATE foo5:
DEFGATE bar5:
0.5288984239763227-0.70757479868835804i, 0.39465637072578896-0.24235275732253403i, 0.00059250545674494753+0.046958531747421317i, 0.031712535844705916-0.043643003378705886i
-0.25625730608837149+0.38577286453639681i, 0.68950077681815547-0.47906788850644755i, 0.017047698798767247+0.18569041006153361i, 0.12495934066357503-0.17380373353475062i
-0.045030747144807828-0.01332991290932654i, 0.14927682906012396+0.11174963413321992i, 0.89843825793765619-0.39414745825031317i, 0.021608922366167009+0.0035390836662454756i
0.053798714187464798-0.0040118605896723343i, -0.2007686123128628-0.074259941554389891i, 0.014600761749307195-0.016318345362311904i, 0.97507038198206974+0.0050307314584900099i

DEFGATE foo6:
DEFGATE bar6:
0.87282390890812944+0.0022919510253473041i, 0.0074181608587802778+0.012709826006544311i, -0.15307490938686891-0.42695733088490928i, 0.17803030872318226+0.02318018781097303i
0.0098982242827216748-0.010890084650373881i, 0.98739671616802605-0.0013090499825309857i, -0.002167348074470624-0.00090458210891704359i, -0.10836185824824292+0.11437497327483075i
0.10383744321356862-0.44152267854214799i, 0.0022468092541351424-0.00068375042465582039i, 0.88411352132470278-0.10350080605473289i, 0.013903269997535642-0.04132260511632075i
-0.17631566360001039-0.033836351758301977i, 0.068176744518980523+0.14204174858619631i, 0.0082573898505992997+0.04280974331947076i, 0.92261712309884303+0.29970109574196857i

DEFGATE foo7:
DEFGATE bar7:
0.76564898360792855-0.025120868825249408i, 0.0066196317105252549+0.094667674529143736i, -0.28731900259399989+0.16598759910310559i, 0.40420426595632375+0.36146868024762074i
0.023260615204884937-0.087360220674517i, 0.94704211691236073+0.0061074899782108984i, 0.069667066295061933-0.017721688581388572i, -0.2049786727455831+0.21844278045161714i
0.22930835726904497+0.31444411709698061i, 0.059348725905573121+0.028501988649786789i, 0.81457407273806659-0.22132679311745795i, 0.34581874119691081-0.11000394899415995i
-0.4543743554994325+0.21694292117455222i, 0.20650951634298162+0.21699613884067623i, -0.34120530888567918-0.23620079843118333i, 0.69567892647223584-0.023773108250506575i

DEFGATE foo8:
DEFGATE bar8:
0.66868736757636538-0.4000589172186807i, -0.17366162813885316-0.43207254889412577i, -0.023345397784291018+0.04440073624410712i, 0.30712065768465008+0.28129252967067292i
0.27342613976073038-0.2616135048600356i, 0.48404873596517001+0.71478974017121244i, -0.032653456452737692-0.18309692100546121i, 0.24052710911008104+0.13829297816607247i
-0.0092177452239405114-0.043044928902039231i, 0.16491483672971291-0.085987367248934091i, 0.98119828839457746-0.0059978756449850738i, 0.023068257170100723-0.012378869869553518i
-0.15070041656698974+0.47429752169217826i, -0.051848998140146312-0.025462730659927744i, 0.0057885943941238102+0.008559955462682331i, 0.86523273169844339+0.016128094663142179i

DEFGATE foo9:
DEFGATE bar9:
0.80749710503025529+0.041704569701353361i, 0.16389430481913481-0.33530866034059603i, 0.17536466605063927-0.10440248249068819i, 0.37670836920182932+0.15282039623772967i
-0.29596833732916999+0.00095282162721917196i, 0.51648589926512511-0.67596889920677028i, -0.28049206871236754-0.30266015284456088i, -0.13116711508746698-0.035020248203437777i
-0.27127340350001511+0.13619632012658653i, -0.10686387860888398-0.32626971842109054i, 0.82964296498415058+0.046733162640375699i, 0.073655901823302644-0.30671298556812737i
-0.34301164031810571+0.2209418638626732i, -0.071015747977129562+0.11874370780494643i, -0.16649581134664554-0.2643030340087888i, 0.84655139382621913+0.012577417215381539i

DEFGATE foo10:
DEFGATE bar10:
0.97292360620756269+1.7052188373638552e-05i, 0.024181888741885649+0.036187608830357973i, -0.22428178538708324+0.034179634123577787i, 0.0072642714832323102-0.0014188487900124501i
0.029931126397357295-0.031598013364282238i, 0.77716564552258416+0.21954348107870247i, 0.21628587786351702-0.28318319004935627i, 0.24257139750390072-0.400133389737234i
0.22438910188879546+0.033467859190259776i, -0.13740116698353616-0.32877533271412629i, 0.90158194003172654-0.0060337913430830474i, -0.093094163645736736+0.002051519143374154i
-0.0070265159571978059-0.0023261224332064958i, -0.13372770236889248-0.44840217895182166i, -0.091418854460148427-0.017700991070814173i, 0.87876136295393659-0.010263513139697974i

DEFGATE foo11:
DEFGATE bar11:
0.78398124874275521+0.012221070205692984i, -0.078314642714775132+0.28795516546387767i, -0.23343288941335277+0.48780842445263894i, -0.019783779828728726-0.057734874302812648i
0.13347232076189033+0.080672312153741862i, 0.82458528525893804+0.0099243255661326142i, -0.29983172081280179-0.23186561401004208i, -0.36438642563633566+0.13856241115415366i
0.30972330021098687+0.51361287895419649i, 0.16256185978249518-0.21018373377800315i, 0.74744452768619374+0.0098409695188711802i, 0.00760796234528828+0.1041233880443511i
Expand All @@ -154,16 +154,16 @@ foo8 5 2
foo9 10 17
foo10 6 5
foo11 16 6
foo0 10 7
foo1 5 0
foo2 7 2
foo3 11 1
foo4 11 18
foo5 16 10
foo6 7 1
foo7 16 1
foo8 2 17
foo9 12 5
foo10 2 16
foo11 2 5
bar0 10 7
bar1 5 0
bar2 7 2
bar3 11 1
bar4 11 18
bar5 16 10
bar6 7 1
bar7 16 1
bar8 2 17
bar9 12 5
bar10 2 16
bar11 2 5

9 changes: 0 additions & 9 deletions benchmarking/rewiring-analysis.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,6 @@
:a*-sum (:partial :a* :a* 1d0 :sum)
))

(defvar *cost-fn-weight-style-assn*
(make-assignments
((*random-state* (seed-random-state))
(quil::*compressor-passes* 1))
(quil::*cost-fn-weight-style*)
:duration (:duration)
:fidelity (:fidelity)
))

(defvar *addresser-style-assn*
(make-assignments
((*random-state* (seed-random-state))
Expand Down
2 changes: 1 addition & 1 deletion cl-quil.asd
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@
(:file "types")
(:file "frontend-utilities")
(:file "queue")
(:file "magicl-constructors")
(:file "classical-memory")
(:file "ast")
(:file "magicl-constructors")
(:file "define-pragma")
(:file "pragmas")
(:file "parser")
Expand Down
4 changes: 1 addition & 3 deletions src/addresser/addresser-common.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,10 @@ If DRY-RUN, this returns T as soon as it finds an instruction it can handle."
values triple (initial-rewiring chip-schedule final-rewiring).

Optional arguments:
+ INITIAL-REWIRING launches with the addresser with a nontrivial qubit
permutation.
+ USE-FREE-SWAPS treats the initial rewiring as virtual (able to be changed).
If INITIAL-REWIRING is not provided this option has no effect.
")
(:method (state instrs &key (initial-rewiring nil) (use-free-swaps nil))
(:method (state instrs &key (use-free-swaps nil))
(format-noise "DO-GREEDY-ADDRESSING: entrance.")
(with-slots (chip-spec lschedule working-l2p chip-sched initial-l2p) state
(let ((*addresser-use-free-swaps* (or use-free-swaps initial-l2p)))
Expand Down
7 changes: 5 additions & 2 deletions src/ast.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,14 @@ The keys are typically INSTRUCTION instances and associated values are STRINGs."
(integer-vec
(map 'vector
(lambda (token)
(declare
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just move this whole rewiring section to be defined after token is?

;; quiet an SBCL warning about use before definition of inline struct accessors for `token'
(notinline token-type token-payload))
(cond
((equalp (token-payload token) "nil")
nil)
((eql (token-type token) :integer)
((eql (token-type token)
:integer)
(token-payload token))
(t
(error "Malformed rewiring string: unexpected token ~A." token))))
Expand Down Expand Up @@ -860,7 +864,6 @@ Each addressing mode will be a vector of symbols:
:for typed-name := (make-typed-name name type-tuple)
:do (assert (and (= num-args (length type-tuple))
(every #'valid-type-symbol-p type-tuple)))
:collect typed-name :into typed-names
:append (list
;; Leaf class.
`(defclass ,typed-name (,name)
Expand Down
99 changes: 46 additions & 53 deletions src/chip/chip-specification.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -39,50 +39,6 @@ LOOKUP-CACHE is a hash table mapping lists of qubit indices to hardware objects.
(print-unreadable-object (cs stream :type t :identity nil)
(format stream "of ~{~D~^:~} objects" (map 'list #'length (chip-specification-objects cs)))))

(defun debug-print-link (stream link &optional colon-p at-sign-p)
"Print out the two qubits constituting a link."
(declare (ignore colon-p at-sign-p))
(let* ((cxns (hardware-object-cxns link))
(qubit0 (vnth 0 (vnth 0 cxns)))
(qubit1 (vnth 1 (vnth 0 cxns))))
(format stream "~a -- ~a" qubit0 qubit1)))

(defun debug-print-chip-spec (cs &optional (stream *standard-output*))
"Print out a simple, human-readable representation of a chip specification consisting of the number of qubits, the number of links, and a list of the links."
(format stream "~a qubits, ~a links~%links:~%~{~/cl-quil::debug-print-link/~%~}~%"
(chip-spec-n-qubits cs)
(chip-spec-n-links cs)
(coerce (chip-spec-links cs) 'list)))

(defstruct permutation-record
"Houses information about a permutation gate, for ease of lookup by the greedy scheduler.

OPERATOR is a string that names the permutation gate.

ARGUMENTS is a list of positions into the hardware object's cxns list's 0th level, naming the argument order for the gate application.

PERMUTATION is a list of positions into the hardware object's cxns list's 0th level, indicating the permutation that this gate application has on the qubit data.

DURATION is the time duration in nanoseconds of this gate application."
(operator "SWAP")
(arguments (list 0 1))
(permutation (list 1 0))
(duration 600))

(defstruct (gate-record (:copier nil))
"Houses information about a hardware instantiation of a gate.

FIDELITY stores the measured gate fidelity.

DURATION stores the measured gate duration (in nanoseconds)."
(fidelity +near-perfect-fidelity+ :type (or null real))
(duration 1/100 :type (or null real)))

(defun copy-gate-record (record &key fidelity duration)
(make-gate-record :fidelity (or fidelity (gate-record-fidelity record))
:duration (or duration (gate-record-duration record))))


;;; The HARDWARE object structure stores a lot of information. It
;;; serves many purposes, principally to solve some of the following
;;; problems:
Expand Down Expand Up @@ -118,15 +74,9 @@ DURATION stores the measured gate duration (in nanoseconds)."
;;; our order. maybe there is a more intelligent data structure to use. something
;;; to think about in the future.
;;;
;;; We NOTINLINE here because a previous file "compilation-methods.lisp" uses this
;;; structure, but the dependency is circular, so moving this doesn't make much sense.
(declaim (notinline hardware-object-order
hardware-object-native-instruction-p
hardware-object-compilation-methods
hardware-object-permutation-gates
hardware-object-rewriting-rules
hardware-object-cxns
hardware-object-misc-data))
;;; Note that a previous file "compilation-methods.lisp" uses this structure, but the dependency is circular,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reverse it? Can we

(declaim inline)
(defstruct)
(declaim notinline)

and just inline whenever we feel we need to?

Adding bulky notinline decls everywhere just to quiet SBCL is sort of a code smell to me; I'd rather condense it all, and use inline to drive performance, not notinline to hush warnings.

;;; so moving this doesn't make much sense. To get SBCL to be quiet about it, each usage of one of the struct
;;; accessors defined here is explicitly declared NOTINLINE at the callsite.
(defstruct hardware-object
"Houses information about a particular hardware object on a QPU.

Expand All @@ -152,6 +102,49 @@ MISC-DATA is a hash-table of miscellaneous data associated to this hardware obje
(make-adjustable-vector))))
(misc-data (make-hash-table :test #'equal) :type hash-table))

(defun debug-print-link (stream link &optional colon-p at-sign-p)
"Print out the two qubits constituting a link."
(declare (ignore colon-p at-sign-p))
(let* ((cxns (hardware-object-cxns link))
(qubit0 (vnth 0 (vnth 0 cxns)))
(qubit1 (vnth 1 (vnth 0 cxns))))
(format stream "~a -- ~a" qubit0 qubit1)))

(defun debug-print-chip-spec (cs &optional (stream *standard-output*))
"Print out a simple, human-readable representation of a chip specification consisting of the number of qubits, the number of links, and a list of the links."
(format stream "~a qubits, ~a links~%links:~%~{~/cl-quil::debug-print-link/~%~}~%"
(chip-spec-n-qubits cs)
(chip-spec-n-links cs)
(coerce (chip-spec-links cs) 'list)))

(defstruct permutation-record
"Houses information about a permutation gate, for ease of lookup by the greedy scheduler.

OPERATOR is a string that names the permutation gate.

ARGUMENTS is a list of positions into the hardware object's cxns list's 0th level, naming the argument order for the gate application.

PERMUTATION is a list of positions into the hardware object's cxns list's 0th level, indicating the permutation that this gate application has on the qubit data.

DURATION is the time duration in nanoseconds of this gate application."
(operator "SWAP")
(arguments (list 0 1))
(permutation (list 1 0))
(duration 600))

(defstruct (gate-record (:copier nil))
"Houses information about a hardware instantiation of a gate.

FIDELITY stores the measured gate fidelity.

DURATION stores the measured gate duration (in nanoseconds)."
(fidelity +near-perfect-fidelity+ :type (or null real))
(duration 1/100 :type (or null real)))

(defun copy-gate-record (record &key fidelity duration)
(make-gate-record :fidelity (or fidelity (gate-record-fidelity record))
:duration (or duration (gate-record-duration record))))

(defun hardware-object-native-instruction-p (obj instr)
"Emits the physical duration in nanoseconds if this instruction translates to a physical pulse (i.e., if it is a native gate, \"instruction native\"), and emits NIL if this instruction does not admit direct translation to a physical pulse.

Expand Down
20 changes: 16 additions & 4 deletions src/cl-quil.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,23 @@
(defun warn-on-ambiguous-gate-or-circuit-definition (condition)
"Handler which prints a warning in the presence of a CONDITION indicating an ambiguous gate or circuit declaration."
(check-type condition ambiguous-definition-condition)
(let ((instr (ambiguous-definition-instruction condition)))
(with-accessors ((instr ambiguous-definition-instruction)
(file ambiguous-definition-file)
(conflicts ambiguous-definition-conflicts))
condition
(typecase instr
(gate-definition (alexandria:simple-style-warning "Gate ~A has multiple definitions, this leads to ambiguous behavior." (gate-definition-name instr)))
(circuit-definition (alexandria:simple-style-warning "Circuit ~A has multiple definitions, this leads to ambiguous behavior." (circuit-definition-name instr)))
(t (alexandria:simple-style-warning "Object ~A (of type ~A) represents a duplicate definition." instr (type-of instr))))
(gate-definition (alexandria:simple-style-warning "Gate ~A has multiple definitions, this leads to ambiguous behavior. Definition in ~a conflicts with ~a"
(gate-definition-name instr)
file
conflicts))
(circuit-definition (alexandria:simple-style-warning "Circuit ~A has multiple definitions, this leads to ambiguous behavior. Definition in ~a conflicts with ~a"
(circuit-definition-name instr)
file
conflicts))
(t (alexandria:simple-style-warning "Object ~A (of type ~A) represents a duplicate definition. Definition in ~a conflicts with ~a"
instr (type-of instr)
file
conflicts)))
(continue)))

(defgeneric definition-signature (instr)
Expand Down
Loading